0
我有一個背景和汽車精靈的遊戲。加快精靈點擊相位器
汽車現在從右向左駕駛。我試圖做到這一點,以便當玩家點擊汽車時,汽車加速並繼續加速。
我迄今爲止代碼:
var game = new Phaser.Game(800, 500, Phaser.AUTO, '', { preload: preload, create: create, update: update });
var text;
var counter = 0;
function preload() {
game.load.image('background', 'images/backgrounds/bg_g1a.png');
game.load.image('car', 'images/items/car.png');
}
function create() {
// enable the Arcade Physics system
game.physics.startSystem(Phaser.Physics.ARCADE);
// Game background
game.add.sprite(0, 0, 'background');
//add car
var sprite = game.add.sprite(700, 300, 'car');
game.physics.arcade.enable(sprite);
// add movement from right to left
var demoTween = game.add.tween(sprite).to({x:-200,y:300},2000);
// start again when out of the game
demoTween.onComplete.add(function(){
sprite.x = 700; sprite.y = 300;
demoTween.start();
});
demoTween.start();
//enable input on car
sprite.inputEnabled = true;
//counter
text = game.add.text(250, 16, '', { fill: '#ffffff' });
//start listener function on input
sprite.events.onInputDown.add(listener, this);
}
function update() {
}
// car has been clicked
function listener (sprite) {
counter++;
text.text = "You clicked " + counter + " times!";
sprite.body.acceleration = -2000;
}
我已經在最後一行嘗試:
sprite.body.acceleration = -2000;
我從速度嘗試了不同的方法來改變補間的數據,但他們沒有工作。計數器很重要,但汽車像以前一樣繼續前進。 我在做什麼錯?