Hi
I am trying to get an object to move freely without gravity lika a spaceship in space.
I am just starting out som I know very little about Phaser. I have just messed a little with the first tutorial code.
Can anyone tell me how I can get my object to move freely on the screen?
This is my code:
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 300 },
debug: false
}
},
scene: {
preload: preload,
create: create,
update: update
}
};
var player;
var cursors;
var game = new Phaser.Game(config);
function preload (){
this.load.image('sky', 'assets/sky.png');
this.load.image('star', 'assets/star.png');
}
function create (){
this.add.image(400, 300, 'sky');
player = this.physics.add.sprite(400, 300, 'star');
player.setCollideWorldBounds(true);
cursors = this.input.keyboard.createCursorKeys();
}
function update (){
if (cursors.left.isDown){
player.setVelocityX(-160);
}
else if (cursors.right.isDown){
player.setVelocityX(160);
}
else if (cursors.up.isDown){
player.setVelocityY(-160);
}
else if (cursors.down.isDown){
player.setVelocityY(160);
}
else{
player.setVelocityX(0);
}
}