October 18, 2017, 05:58:54 AM

Author Topic: Blitting  (Read 1005 times)

Lazarus404

  • Newbie
  • *
  • Posts: 3
    • View Profile
Blitting
« on: October 14, 2015, 07:42:40 AM »
Hi again,

So, my aim is to implement a blitted engine for a Pseudo 3D game.  I couldn't use OpenFL, because drawn polygons and bitmap data cannot be drawn to the same DisplayObject (they're incompatible).  If I drew an image from a sprite sheet, all was good. However, drawing with polys on top of that cause the sprite sheet to display in full, which screwed everything up.

I'm hoping HaxePunk can help here. Essentially, I have an image which will be my game area.  I now need to be able to blit other images to it.  Image is great because it has draw_polygon support, but I can't see how I can draw another image to it.  Is this possible?  If not, how do I do this?

Thanks,
Lee

voec

  • Newbie
  • *
  • Posts: 36
  • Hello :(
    • View Profile
    • 384400 kilometers
Re: Blitting
« Reply #1 on: October 14, 2015, 04:33:12 PM »
I'm not sure if HaxePunk can also help you much with this, since it is based on OpenFl. So everything that OpenFl can/cannot HaxePunk can/can't do either.

From what I understand reading this and your previous topic maybe BitmapData() maybe be able to help you out?

You can create your game area Image like this:

Code: [Select]
var bd:BitmapData = new BitmapData(game_width, game_height);

addGraphic(new Image(bd));

And then you can use the BitmapData setPixels() and copyPixels() function to draw images, like this for example:

Code: [Select]
bd.copyPixels("graphics/image_to_draw.png", new Rectangle(0,0,image_width,image_height),new Point(x_position, y_position))
And you can use matrixes to do rotation and scaling etc.

It is sort of like a custom made buffer.
However this is really, really slow if you want to draw a lot of stuff and I'm not quite sure why you don't just add new Images on different layers? You can use some of them for drawing polygons and some just for normal images.