Small queststion about graphic= VS addGraphic


(Blake Jones) #1

Hey all. Just started playing with flashpunk today and have two small questions about graphics. I discovered that both

addGraphic(new Image(PLAYER));

and

graphic = new Image(PLAYER);

work equally well when rendering an IMAGE in an entity.

Question 1: is there a reason someone might use one over the other in different circumstances?


Out of curiosity I went and checked out if this worked the same for adding TEXT.

addGraphic(new Text("some string"));

^this works BUT

graphic = new Text("some string");

pulls an undefined graphic property error. (even though graphics.Text was already required for the first one)

Question 2: why does it work for images but not text?


(Zachary Lewis) #2

addGraphic() puts the argument into a Graphiclist (so you can add multiple graphics to an Entity quickly instead of creating a new Graphiclist yourself). Keep in mind that, using addGraphic() means your graphic is actually a Graphiclist.

For question 2, these should both work. Are you trying them back-to-back, or in separate files?


(Blake Jones) #3

Back to back. They both work when you put them inside an entity I just noticed. Before I was trying them in a World.

Appreciate the feedback, I was already scratching my head at why one graphic would replace another one but you answered it with the graphic lists.