What does this mean for me? You will always be able to play your favorite games on Kongregate. However, certain site features may suddenly stop working and leave you with a severely degraded experience.
What should I do? We strongly urge all our users to upgrade to modern browsers for a better experience and improved security.
We suggest you install the latest version of one of these browsers:
Kongregate is a community-driven browser games portal with an open platform for all web games.
Get your games in front of thousands of users while monetizing through ads and virtual goods.
Learn more »
I’m a begginer dev and I’m working on my first game :) and I was wondering about the efficiency of my blit class.
The way I see it I can do it in 2 ways:
1-Each displayed object contains a bitmapdata instance of the blitted image.
2-Each displayed object contains an array which holds the frames of the blitted image.
I was wondering about the efficiency and pros and cons of each method (in trems of CPU, RAM, render speed, ect…),and I would like to hear from you
BTW I’m working with Flash CS6 using AS3.
Thank you very much!
Blitting (if done right) allows for alot better performance than normal use of the display list. It is more difficult to do, and (maybe?) uses more RAM, depending on your method, but drastically cuts down the time spent rendering graphics.
[Here is an Adobe tutorial on ways to blit](http://www.adobe.com/devnet/flash/articles/blitting_mc.html) if that’s what you’re looking for.
Thanks for the answer, but I already know how to blit (actually, I already used this very tutorial),now I’m trying to optimize my game.
Let’s take this tutorial as example, there they create a bitmapData object for the blockFace, and directly blit from that image to the stage.
This can be done in another way – create an array, store all the frames of the blockFace in the array, and blit from the array to the stage (only use the actual image to insert the frames into the array, say while the game is loading, but not blit from the image).
I guess what I’m trying to ask is – Which is “cheaper” (memory\CUP-wise) bitmapData object or an array..? and does it depend on the size and frames of the blitted object.
This is the way I do it.
public class blitting_example
private var rect:Rectangle = new Rectangle(0, 0, 10, 10);
public var point:Point = new Point;
public var vect:Vector.<Number> = new Vector.<Number>;
public var input:BitmapData;
public var output:BitmapData;
public var frame:int;
public function blit():void
rect.x = vect[frame * 2];
rect.y = vect[(frame * 2) + 1];
output.copyPixels(input, rect, point);
I’ve found this method to be very fast. I had about ~~40,000~~ 25,000 objects blitting at once and I still maintained an FPS above 24.
Are you talking about animating your blitted images? If so, you can do even better than an array by having a spritesheet of your frames as a single huge bitmapdata, and then only drawing the relevant part to the screen.
> *Originally posted by **[Drakim](/forums/4/topics/333858?page=1#posts-6995140):***
> Are you talking about animating your blitted images? If so, you can do even better than an array by having a spritesheet of your frames as a single huge bitmapdata, and then only drawing the relevant part to the screen.
That’s exactly what the above code does, it just uses the vector to store the xy positions of each frame in the bitmapData.
Something I just figured out: make your background images into bitmaps. I seems to really help performance (as opposed to things drawn in Flash).
But something along the lines of, “When should/shouldn’t I blit” would be helpful.
Thanks for the answers guys.
I actually coded a little stress test and ran it myself, and monitored FPS, RAM and CPU usage, and figured that there isn’t much of a difference when using/not using array (without array resulted in 1-2 FPS better), so I’l answer to myself – it doesnt matter :P
Guess it makes sence, cause the toal size of the bitmap is the same, it doesn’t matter if it’s sliced to single frames and put into an array.