Drawing other shapes


(Willard Torres) #1

This might seem like an odd question, but is there a way to draw shapes other than rectangles, circles and ellipses in Flashpunk? (eg. polygons and the like), similar to OpenGL drawing?

Thanks in advance.


(Bora Kasap) #2

not possible in flashpunk but i’m sure you can find a class or create a class to do this, because flashpunk using pixeldraw to draw lines or shapes… so you can write or import a new class to draw everything…

And a note, i heard people not using draw functions for ingame objects, that is not suggested, but i don’t know why…


(rostok) #3

it is possible. you could just create some DisplayObjects in your entities and overload render() method to draw them on FP.buffer which is just a BitmapData. but i’m not sure that efficiency of this will be sufficient/


(Jacob Albano) #4

Here’s one possible approach:

  • Create a Sprite.
  • Do your polygon drawing and such on the sprite.
  • Draw the sprite to a BitmapData.
  • Create a new Image with the data as a source.
  • Set the image as your entity’s graphic.

If you’re going to be updating the graphic often, this approach is probably too expensive, but it should work fine in cases where the graphic is only updated every now and then.


(Willard Torres) #5

Thanks, Jacob. I was just reading about using AS3’s drawing utilities, and I think they would do the job well. Maybe I’ll even write helper classes to facilitate something along the lines of drawPolygon(points:Array).