Nafi Posted February 19, 2015 Share Posted February 19, 2015 Hello,I am trying to moving graphics object left or right by Arcade physics system. But its now working. please see blow code and kindly inform me whats wrong. function create() { var rect; var cursors; game.physics.startSystem(Phaser.Physics.ARCADE); var graphics = game.add.graphics(0, 0); graphics.lineStyle(2, 0x0000FF, 1); graphics.drawRect(50, 250, 100, 100); cursors = game.input.keyboard.createCursorKeys(); }function update() { if (cursors.right.isDown) graphics.velocity.x = 350; // If the left arrow if pressed, move left else if (cursors.left.isDown) graphics.velocity.x = -350; // If no arrow is pressed, stop moving else graphics.velocity.x = 0;} Link to comment Share on other sites More sharing options...
XekeDeath Posted February 20, 2015 Share Posted February 20, 2015 It looks to me like you are trying to use Physics on an object that doesn't have a physics body.If you want to use physics on an object, then you need to enable the physics body on that object with Phaser.Physics.enable()However, I don't think that will work on a graphics object because the physics system will only enable physics on things that have a body property.Given that graphics objects can be whatever shape you draw, and can change at any time, I don't think they are capable of having a physics body. You might try adding the graphics obeject as a child of a sprite with a physics body, and moving the sprite around instead. Link to comment Share on other sites More sharing options...
Recommended Posts