Hi there,
Let me start off I'm a real noob at programming, one of my friends got me into this to keep me occupied during sleepless nights :P....
so I started out with the Hello World project,
edited it a bit to draw a sprite, move it around with the keys, and afterwards I decided I wanted to make him jump.
looked for an example using the Arcade physics, edited my code which looks something like this :
window.onload = function() {
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update : update , render: render });
function preload () {
game.load.image('logo', 'assets/man.jpg');
}
var logo;
function create () {
// var logo;
game.stage.backgroundColor = '#2d2d2d';
game.physics.startSystem(Phaser.Physics.ARCADE);
logo = game.add.sprite(game.world.centerX, game.world.centerY, 'logo');
logo.anchor.setTo(0.5, 0.5);
// gravity mods
// set the world (global) gravity
game.physics.arcade.gravity.y = 100;
game.physics.enable( [ logo ], Phaser.Physics.ARCADE);
// i suppose this is to make it bounce against the rendered window its bounds
logo.body.collideWorldBounds = true;
logo.body.bounce.y = 0.8;
}
function update () {
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)){
logo.x -= 4;
}
else if ( game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
logo.x += 4;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP)){
logo.y -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)){
logo.y += 4;
}
}
function render() {
//game.debug.spriteInfo(logo,20,32);
}
};
as you might have noticed, I commented some lines out to see if it would fix something...
whenever I comment the game.physics.startSystem out, the sprite will respond to the keys pressed.
when I remove the comment, phaser just draws a blank screen.
ive been trying to adapt my code to multiple examples as shown on the phaser.io page, but I can't get it working.
a little bit of help ( even with programming syntax !!! ) would be a real neat and wonderful help
thank you guys for reading this if you got this far