PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

frame animation??

is frame animation possible with gapidraw??? is it possible to use a single image with many frames and sprites and just extract the images from that main image file??? i was trying to make my own Sprite class but i am not getting any luck...
Yes, you need to use pSrcRect (Address of a RECT structure that defines the upper-left and lower-right points of the rectangle to blit from on the source surface. If this parameter is NULL, the entire source surface will be used.)

In the blt/bltfast function,

Just define a RECT to be the size and location of the frame on your sprite’s surface, then each animation frame change the RECT to the next frame.

ie somthing like:


Code:

CRect currentFrameRect;

void CSprite::NextAnimationFrame()
{

currentFrameRect.right+=iFrameWidth;
currentFrameRect.left+=iFrameWidth;

}

HRESULT CSprite::Render(CGapiSurface* pBackBuffer)
{

pBackBuffer->BltFast(m_position.x,m_position.y,pSurface>pSurface,currentFrameRect ,NULL,NULL);

return S_OK;
}





That’s a simplified version, you’d need code to wrap the animation and change to specific animation fraims / sets
The .Net wrapper I wrote has some rudimentary support for this. Load a GapiSurface and set the .Frames property. Then when you blit, one of the overloaded Blit methods takes a FrameIndex parameter.

The only catch is that your sprite frames have to be laid out horizontally.
InexorableTash · 19 Feb 2005, 04:30 UTC
Note that storing frames in one large surface can negatively impact performance. Modern processors (like ARM) cache data in blocks - if you read byte 5, bytes 0 ... 255 are probably cached as well.

If you think about this, it means that when you're drawing one frame from a horizontal strip you're probably using only a fraction of each cached block per row of the surface. I.e. if you were using the frame made up of 'x' pixels in this strip:

ooooooooxxxxxxxxoooooooooooooooooooooooooooooooo
ooooooooxxxxxxxxoooooooooooooooooooooooooooooooo
ooooooooxxxxxxxxoooooooooooooooooooooooooooooooo
ooooooooxxxxxxxxoooooooooooooooooooooooooooooooo

... then odds are all of the 'o' pixels will get cached as well. So you might have to hit memory 4 times (once per row) rather than just once if you had a single frame with 'x' in it.

If you stack the frames vertically, on the other hand, you'll will have cache coherency of the data. (I'm kinda sleepy, but I think this holds true even when GapiDraw loads and rotates the images, but someone should confirm.)

You might want to write a routine that slices up your frames into different surfaces on load.
hmmm... thanks for the info... i have been trying very hard to do my sprite class.. i think now i might be able to make it.. i thought combining frames in one file is more efficient than using multiple files for each frame.. because if you combine the frames in a single file you will be saving a lot of header space provided you put the images that have the same color in the same file.. any clariffications about this???
InexorableTash · 19 Feb 2005, 22:41 UTC
Once it's in a CGapiSurface it's uncompressed (unless you're using an RLE variant) as 2 bytes per pixel - the header info is gone, there's no palette, and the per-object overhead is going to be tiny.

What I'd do is have your sprite class load up the image and split it into multiple frames. (And don't forget to release the loaded image since it's redundant.) That'll have to be repeated whenever the surfaces are flushed (e.g. on screen rotation) but that's why you hide it all in a sprite class.

Now bear in mind this is theory. Do whatever works for you in terms of complexity and reducing the risk of bugs in your code. And never fix a performance problem until you have determined that it is a problem; if your game is humming along at 30fps you introduce risk by trying to change some core piece of the algorithm - is that worth it for a few more fps?

(In my case, I've got a 3D engine with sprites rendered into the screen and z-buffer as textured quads, so yes, I do need the extra FPS.)
ok.. thnks for the rep... but iam having some thought right now... and since iam a beginner in GD ima wondering if any of you could help..

1. i have seen a map editor called tile studio and i am wondering if i could use it in conjunction to gd.. is there any tutorial for it???

2. i have also found a sound library called hekkus... i believe it is made for pf but iam wondering if it is compatible with gd... are any sample sourcecode for gapidraw that uses it... by the way can i use it with pocketpc emulator 2003.. i cant find any lib for ppc2003 emu in the lib folder of hekkus...

3. iam also wondering how i could make a side scroller with gapidraw... because i have read that whn i draw an image that will be outside of the screen it will not be drawn... so how can i draw a background that is larger than the current screen if it will not be drawn because it is larger than the screen...

4. i am also thinking of writing a basic sprite class... it consists of these attributes..
- an x,y coordinate member
- a frame width and frame height member
- a function that could make an array of rects
it will look something like this...
public void extractRect(int framesWide, framesHigh, framesWidth, framesheight)

the framesWide and framesHigh argument are the number of frames across and down the image... the framesWidth and frameHeight are the width and height of each frame... for example if i have an image that have 4 frames across and 4 frames down and each frames are 16x16, i would call that function with this arguments:


RECT moveFrame[4][4]; // one state
extractRect(4, 4, 16, 16);

this will be its body...
Code:
public void extractRect(int wide, int high, int width, int height) {
for (int h=0; h<high; h++) {
for (int w=0; w<wide; w++) {
moveFrame[w][h].left = w * width;
moveframe[w][h].right = (w * width) + width;
moveframe[w][h].top = h * height;
moveframe[w][h].top = (h * height) + height;
}
}


then i could put it into an array that contains different states for example that moveFrame is for the moving state and i could put it to another array that holds different states for my sprite class.. i could put an extract an exploding frame and add it to my state array...

i also want to include a function that detects for collision in that sprite class... well maybe you guys could give some insight for this sprite class..

5. i am also wondering what is the best storage for an array of enemies or bullets?? is it alright to use vector to store those... because in vector i could add and remove obejects dynamically... but i have heard that using vectors might use too much processing.. and slow thins down....

well so hope you guys could answer some of my questions....and maybe you could hel me to enhance my sprite class... thanks....