Sprite sheets....

Cirdan

Newcomer
Joined
Sep 18, 2004
Messages
4
I'm making a ORPG and I was wondering, have this big sprite.bmp image, and each sprite is 32x32, how would I clip the image so it would only show the 32x32 image? Thankyou in advanced.

Also, if I created a tile editor, how would I select each tile in a picture box? what would the math formula be to find out what tile the user clicked on? (again, 32x32)
 
Well, if you're using DirectX, you need to use normal Draw function instead of the DrawFast. One of the parameters is a source rectangle that will allow you to specify a particular area of the source surface to blit from.

TileX=MouseX\32
TileY=MouseY\32

The forward slashes perform integer division (returns a whole number). So a mouseclick at X=42, Y=10 will be on the tile at 1,0.
 
Cirdan said:
I'm making a ORPG and I was wondering, have this big sprite.bmp image, and each sprite is 32x32, how would I clip the image so it would only show the 32x32 image? Thankyou in advanced.

Also, if I created a tile editor, how would I select each tile in a picture box? what would the math formula be to find out what tile the user clicked on? (again, 32x32)

Hi cirdan, It would help to know if you're using DirectDraw or Direct3D to process your game's graphics.

Also, it would be wise for you to create the game's editor in first place. Doing this you are not only developing the game but you will also be forced to think of all aspects of the game. It's like pseu-doing the game.

And just to finish: If your skills are not enough to build the game's editor that also means that you are less ready to build the game itself.
 
Last edited:
if I using Direct3D to process the game graphics.
How can i get the 32x32 sprite from the big sprite bmp ?
 
nihuo13 said:
if I using Direct3D to process the game graphics.
How can i get the 32x32 sprite from the big sprite bmp ?

You mean streching the image or simply cutting it off?

Either way, this is one of some ways you can set up the sprites size

(pseucoding)
Code:
Sprite mySprite;
Texture myTexture; //defining a texture
Rectangle recTextureSize = new Rectangle(); //defining a new rectangle 

//Setting up the rectangles size of 32*32 pixels
recTextureSize = new Rectangle(32,32);

//Setting up the texture with some picture
myTexture = TextureLoader.FromFile(image_name); 

//Draw the texture with the correspondent size
mySprite.Draw(myTexture, recTextureSize (...),(...));

Am skiping here some important things like the sprite initialization, sprite.Begin, sprite.End etc. as I think you already know it. However, if not, let me know about it.
 
Last edited:
I have a Texture t1 with colorkey(TextureLoader.FromFile) and another Texture t2(no colorkey)

Surface s1=t1.GetSurfaceLevel(0);
Surface s2=t2.GetSurfaceLevel(0);
Rectangle r=new Rectangle(0,0,s2.Description.Width,s2.Description.Height);
SurfaceLoader.FromSurface(s2,r,s1,Filter.None,0);

sprite.Begin(SpriteFlags.None);
sprite.Draw2D(t2,Rectangle.Empty, Rectangle.Empty,new Point(0,0), Color.White)
sprite.End();
//the t1 colorkey to be replaced with transparent black
// how can I remove the transparent black
//I don't want to separate it from another,like this:

sprite.Begin(SpriteFlags.None);
sprite.Draw2D(t2,Rectangle.Empty, Rectangle.Empty,new Point(0,0), Color.White)
sprite.End();

sprite.Begin(SpriteFlags.AlphaBlend);
sprite.Draw2D(t1,Rectangle.Empty, Rectangle.Empty,new Point(0,0), Color.White)
sprite.End();
 
nihuo13 said:
//the t1 colorkey to be replaced with transparent black
// how can I remove the transparent black
//I don't want to separate it from another,like this:

So, you want to remove the transparency of t1 or you just want to change the colorkey transparency to another one? I'm kinda confused here...
 
Back
Top