reopucino Posted September 15, 2015 Share Posted September 15, 2015 Hello can I'm moving geomentry? I try to use thisfunction update() {floor.x += 2}but that script doesn't work. Link to comment Share on other sites More sharing options...
drhayes Posted September 15, 2015 Share Posted September 15, 2015 Needs more context. What is "floor", where is it instantiated? Does it have physics enabled on it? Is this your state's update method? Link to comment Share on other sites More sharing options...
reopucino Posted September 16, 2015 Author Share Posted September 16, 2015 floor is geometry rectangle.. And doesn't have any physic.. but I had to solved that. i'm using "game.debug.geom(floor, '#0FF000');" on render functionvar floor;function create() {floor= new Phaser.Rectangle(20, 20, 40, 40);game.debug.geom(floor, '#0FF000');}function update() {floor.x += 2} Link to comment Share on other sites More sharing options...
Gregu92 Posted September 16, 2015 Share Posted September 16, 2015 Hello all!Bumping up - have same issue with moving Ellipse. I would like to move ellipse like ballistic object - maybe something like scorch. Is it even possible to move primitives like this? Any physics libs? Link to comment Share on other sites More sharing options...
drhayes Posted September 16, 2015 Share Posted September 16, 2015 I'm still not sure what "not working" means. A rectangle is not a display object so nothing will be drawn while you move it. Is that what you mean? You'll probably be better off using a Sprite with an image of a rectangle instead of using the debug methods to draw the rectangle for you, performance-wise. Gregu92, same thing. An ellipse isn't a display object so you'd need to draw something along the same path as your ellipse... so why not make it a sprite with a physics body anyway? reopucino 1 Link to comment Share on other sites More sharing options...
Gregu92 Posted September 16, 2015 Share Posted September 16, 2015 I've made something like this:var graphics = this.add.graphics(0, 0); graphics.lineStyle(3, 0xFFAAAA); graphics.beginFill(0xFF0000); graphics.drawEllipse(0,0,50,25); graphics.endFill(); sprite = this.add.sprite(100, 200, graphics.generateTexture());Then, I tried to add some 'physics' to this, but the sprite.body is null.The purpose why I need to use primitives is that there will be more than 200 different colors of the ellipses. Moreover colors should be picked randomly.Still looking. I just have started with the Phaser and it seems to be very powerful tool but I need to know it first.EDIT:Code looks like this right now: var graphics = this.add.graphics(0, 0); graphics.lineStyle(3, 0xFFAAAA); graphics.beginFill(0xFF0000); graphics.drawEllipse(0,0,50,25); graphics.endFill(); sprite = this.add.sprite(100, 200, graphics.generateTexture()); sprite.angle = -30; this.physics.arcade.enable(sprite); sprite.body.bounce.y = 0.2; sprite.body.gravity.y = 300; sprite.body.collideWorldBounds = true; sprite.body.velocity.y = -300; sprite.body.velocity.x = 1;console.log(sprite); graphics.destroy();It seems to work - and it has been done with help of http://phaser.io/tutorials/coding-tips-004 . I think it is highly recommended to go through that tutorial. Also in "update" function I have added sprite.x +=10 and it works perfect. My topic is done here. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts