Witam wczoraj zacząłem bawić się Paserem, zrobiłem startowy projekt z kursu Getting Started with Phaser.
I po tym kursie nasuwa mi się pytanie mianowicie.
game.input.keyboard.isDown(Phaser.KeyCode.LEFT
Jeżeli chodzi o tą linijkę oznacza to użyj obiektu game z obiektu game wybieramy obiekt input z obiektu input wybieramy obiekt keyboard i na rzecz obiektu keyboard wywołujemy metodę isDown ?
Czy w tym przypadku chodzi o zagnieżdżone obiekty ?
A tu cały kod.
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update});
function preload() {
game.load.image('bot', 'assets/star.png');
}
var s;
function create() {
game.physics.startSystem(Phaser.Physics.ARCADE);
s = game.add.sprite(game.world.centerX, game.world.centerY, 'bot');
s.anchor.setTo(0.5, 0.5);
s.scale.setTo(2, 2);
s.animations.add('run');
s.animations.play('run', 10, true);
game.physics.arcade.enable(s);
s.body.gravity.y=5;
}
function update() {
if (game.input.keyboard.isDown(Phaser.KeyCode.LEFT))
{
s.x -= 4;
}
else if (game.input.keyboard.isDown(Phaser.KeyCode.RIGHT))
{
s.x += 4;
}
if (game.input.keyboard.isDown(Phaser.KeyCode.UP))
{
s.y -= 4;
}
else if (game.input.keyboard.isDown(Phaser.KeyCode.DOWN))
{
s.y += 4;
}
}