Phaser官方网站, 本文主要基于2.4.2版本, 官方有详细的API,例子不是很充足,但是提供了很多例子, 可以通过学习例子+查阅API进行学习
var sprite = game.add.sprite(0, 0, 'sprite');
sprite.anchor.set(0.5, 0.5);
上面的代码设置元素中心坐标为0,0.anchor默认值为(0, 0)也就是说把元素的左上角放到指定坐标.
var text = game.add.text(8, 8, 'fixed');
text.fixedToCamera = true;
fireButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
fireButton.onDown.add(fire, game);
function fire() {
console.log('fire');
}
var flame = game.add.sprite(0, 0, 'flame');
flame.alpha = 1;
flame.visible = true;
game.add.tween(flame).to({
alpha: 0
}, 100, 'Linear', true);
var bullet = game.add.sprite(0, 0, 'bullet');
game.camera.follow(bullet);
var targets = game.add.group(game.world. 'target', false, true, Phaser.PhysicsARCADE);
targets.create(300, 390, 'target');
targets.create(500, 390, 'target');
targets.setAll('body.allowGravity', false);
game.load.baseURL = 'http://qiudeqing.com/';
game.load.corssOrigin = 'anonymous';
var bullet = game.add.sprite(0, 0, 'bullet');
bullet.exists = false;
bullet.exists = false
同时会影响bullet.visible
bullet.reset(x, y);
This moves the Game Object to the given x/y world coordinates and sets fresh
, exists
, visible
and renderable
to true.