Jump to content

Graphic added to sprite not displaying


Hattraz
 Share

Recommended Posts

I'm trying to get a graphic object to display that is being added to a sprite as a child. It won't display when added to the sprite via sprite.addChild. 

 

I can get it to display by either adding it to a group or using sprite.reset (in which case the sprite acts funny using arcade physics engine). 

 

If I specify an image for the sprite, that displays fine. So it's not a case where the sprite itself isn't visible.

 

Graphic Code:

stinger_graphic = game.add.graphics(10, 10);stinger_graphic.beginFill(0xFFFFFF);stinger_graphic.drawRect(0, 0, 10, 10);stinger_graphic.endFill();    

Sprite code:

// stinger_graphic gets passed in as graphicfunction Bullet(x, y, graphic) {    ...    graphic.x = this.x;    graphic.y = this.y;    this.addChild(graphic);    ...}
Link to comment
Share on other sites

Total shot in the dark: maybe it's that game.add.graphics adds it to the World, then you try to add it to your sprite, and it can't be in two groups at once? Maybe use game.make.graphics instead?

 

This is probably not it. I bet there's code somewhere that is smart about removing children DisplayObjects from their parents before adding them somewhere else. Just wondering.

 

Maybe set the x/y of graphic after adding it, in case those get adjusted now that the parent changed?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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