PocketMatrix forums

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

Easy Sprite Question

Hi,

As will be obvious from my pathetic question I am fairly new to Easy CE (and C++ for that matter). All I want to do is assign a tga file to a sprite. Is this possible or do I have to use a bitmap? The following shows the code I have been playing around with:

Code:
void main()
{

unsigned short* buffer = (unsigned short*)getbuffer();

loadtga(L"\\My Documents\\Pocket Invaders\\Invaders_Title.tga", 240, 320, buffer);
PIXEL* buttonbuffer = new PIXEL[135 * 35];
loadtga(L"\\My Documents\\Pocket Invaders\\Button_Start.tga", 135, 35, buttonbuffer);
ASprite buttonsprite( 135, 35, 35, buttonbuffer );
ASprite::settarget( buffer );
buttonsprite.setpos( 50, 100 );
buttonsprite.draw();

while (clicked()) { update(); };

while (!clicked()) { update(); };

}


Any help would be muchly appreciated.

Cheers,

DS
This is indeed the way to do it (I looked over the code and I assume this is working). In EasyCE 2.0, you'll have to pass a surface instead of a pixel array, but you will still have to create the surface and load the image before you use it for a sprite. It might be a good idea to make a constructor for the sprite class that accepts a filename instead of a surface. I'll give it some thought.
Thanks for the quick reply.

This code almost works. The background tga file loads fine, the problem is the sprite - it looks almost smeared across the screen. I thought the problem may be that I was using a tga rather than a bitmap (as called for in the documentation). I might try that - is there a load bitmap function? I couldn't see one in the header file.
EasyCE only loads .tga's at the moment.
D'oh!!!

Sorry - stupid mistake. I put the height in the pitch field not the width.