Take a look at jacalbano’s answer, he explains it far better than I can. The takeaway is to be very careful when using FP.world!
okay this is really frustrating. If I call addGraphic()
in the update function, then it shows up. If I call it in my constructor, it doesn’t show up. What is going on?
Rather than myEntity having its own graphic, I am trying to make myEntity hold a reference to a helperObject which manages its own state and renders an image relative to myEntity.
the constructor for the helperObject looks sort of like this:
public function helperObject(myEntityReference:Entity, image:Image, xOffset:int, yOffset:int)
{
//store arguments into private variables
subject = myEntityReference;
this.image = image;
this.xOffset = xOffset;
this.yOffset = yOffset;
//calculate where I want the image rendered
x = subject.x + xOffset;
y = subject.y + yOffset;
//add the graphic to the world and store the reference to a private variable
graphic = FP.world.addGraphic(image, subject.layer, x, y)
}
It all compiles, but nothing shows up on screen. Furthermore, the console says there’s only one entity!
There should be 2 entities (myEntity and the graphic entity that was added in the helperObject constructor)