Using animated MovieClips rather than Images


(Zach) #1

I’m pretty new to this forum (and coding in AS3 overall, really), I’ve been using FlashPunk to help me along the way and I was wondering if it’s possible to still use FlashPunk and use MovieClips for entities rather than still images. I didn’t really search for an old thread so I apologize if this is a duplicate thread, I wouldn’t mind using sprites as the art in my game but I’d really prefer if I could use MovieClips for animations and the like. Just wondering if it would still be possible to do so using FlashPunk.

Thanks.


(David Williams) #2

Flashpunk uses bitmap rendering, so to use movieclips, you’d have to use your own method of rendering. Due to the flashpunk screen being 1 big bitmap, you would also not be able to do depth sorting between flashpunk images and your movieclips, for they could only be on top of the bitmap, or underneath it, and it spans the entire screen.


(Zach) #3

Ah, thanks for the reply. Sounds like it would be way too tricky to use MovieClips.


(David Williams) #4

It wouldn’t be too bad, but it would kind of defeat the purpose of using Flashpunk.
For example, you could still use the world’s and entities hierarchy created by FP, but when your entity gets added, add the movie clip, use the entities update to manage the movie clip and it’s coords, and then remove it when the entity gets removed. This way it still works simply enough, but you’re able to use movie clips to display your graphics.


(Ultima2876) #5

Just use the draw function in your entity’s render function:

override public function render():void 
{
  var target: BitmapData = renderTarget ? renderTarget : FP.buffer;
  super.render();

  FP.matrix.identity();
  FP.matrix.translate(_point.x - _camera.x.x, _point.y - _camera.x.y);
  FP.matrix.scale(1, 1); //scale the MovieClip

  //draw the movie clip with smoothing
  target.draw(myMovieClip, FP.matrix, null, null, null, true);
}

Note that if you do this for a lot of sprites it’ll be slow, and it’ll kill performance on mobile. If you’re worried about performance particularly on mobile, you’ll need to render your sprites into a spritesheet and use a spritemap (this can be done at runtime or precomputed and stored in a png; there are tools for doing this).

I disagree that it defeats the point of using FP though; FlashPunk offers a whole lot more than just fast rendering! In fact, FlashPunk’s rendering is probably its biggest weakpoint these days. It’s a well designed and simple library that has functionality for collisions, entity and world management etc.