0
我開始與移相,我需要做後續的動畫: 一個精靈轎車從屏幕的任何一側出現,所以,在一個特定的點在同一方向另一輛汽車的舉動,另一個與另一,以相同的時間間隔,並且當這些汽車在屏幕外時,它們將被銷燬。如何讓小組中的精靈創建其他對象並銷燬自己?
對於嘗試,我穿上精靈,但是當汽車與他們碰撞時,另一輛汽車開始運動。看代碼:
var x = 800
var y = 600
var game = new Phaser.Game(x, y, Phaser.AUTO, '', { preload: preload, create: create, update: update });
var cars;
var next;
function preload() {
game.load.image('car', 'assets/images/car.png');
game.load.image('next', 'assets/images/square.png');
game.load.image('destroy', 'assets/images/square.png');
}
function create() {
game.physics.startSystem(Phaser.Physics.ARCADE);
game.stage.backgroundColor = "#4488AA";
// call next car
next = game.add.sprite(500, 200, 'next');
game.physics.arcade.enable(next);
// next.body.checkCollision.right = false;
next.body.bounce.set(0);
next.body.immovable = true;
// destroy last car
destroy = game.add.sprite(0, 550, 'destroy');
game.physics.arcade.enable(destroy);
destroy.body.immovable = true;
cars = game.add.physicsGroup();
createCar(null, null);
}
function update() {
game.physics.arcade.collide(next, cars, createCar, processHandler, this);
}
function processHandler (pointer, car) {
return true;
}
function createCar(pointer, car) {
console.log('call next');
car = cars.create(x, 0,'car');
car.body.velocity.setTo(-150, 100);
}
可是不行的,因爲,與collision
,車子開出了他的去路,並沒有她,他不叫collision
或overlap
回調。看:
我如何做這項工作?