Jump to content

problems running ARCADE physics with phaser


noobnr39
 Share

Recommended Posts

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 :)

 
Link to comment
Share on other sites

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 :huh: but don't give up, we'll solve this!

Link to comment
Share on other sites

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 !!!!

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...