noobnr39 Posted May 30, 2016 Share Posted May 30, 2016 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 Quote Link to comment Share on other sites More sharing options...
Umz Posted May 31, 2016 Share Posted May 31, 2016 Alright, it's probably an issue somewhere with one of the physics objects. Not certain exactly. But if you press F12 in the browser and read the console log it should tell you what went wrong with the code the post the error, or you may be able to solve it. Debugging is the Number 1 most valuable skill in programming haha. Can't see exactly what went wrong with the code but don't give up, we'll solve this! Quote Link to comment Share on other sites More sharing options...
noobnr39 Posted May 31, 2016 Author Share Posted May 31, 2016 that's the weird thing, it doesn't show me any errors at all sometimes it gives me the mainstate error, but not everytime ... there is basically 1 sprite used in the code, maybe someone can launch it and see if it happens to them too and thanks I know i'll solve it !!!! Quote Link to comment Share on other sites More sharing options...
noobnr39 Posted May 31, 2016 Author Share Posted May 31, 2016 > game.physics.startSystem(Phaser.Physics.ARCADE); this line seems to be the troublesome one. if I comment it, the sprite shows up, if I add it to the code, the sprite disappears Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.