Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

can moving geom?


reopucino
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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

 Share

  • Recently Browsing   0 members

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