Template Image

Started by
8 comments, last by graveyard filla 19 years, 5 months ago
Hi Guyss.. Im Quite new in game programming.. But I have make two games in this year, which is my uni project. But as far As I make a game, I dont use the template image, I just use One image at a time, which is I know, Its not efficient, I have seen several games used this features. Its like having all of the pictures on one file. my question is how to read from image like that? because I just use sprite.loadfrom do we have to encrypt and decrypt that? I will give attachment so you guys understand what I mean.. Thanks for your help.. Free Image Hosting at www.ImageShack.us
Advertisement
Well you'll have to set the texture coords for each sprite. So if you draw your sprite it wont use the entire texture but just a little bit from it. What does 'sprite.loadfrom' do excaclty? what do u use to draw ur sprites?


xIshtarx
Anyone Have a sample code for doing something like this? ..

I use my university Library to actually Draw the sprites and stuff.
if you dicied to use SDL its really easy just put the rect of what section you want to blit in SDL_BlitSurface(bla,HERE,bla..
other wise im not quite sure ill get more spacific if you ARE using SDL otherwise its just spent air
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
The answer depends on if you are using a 2d or 3d API. I think the solutions operate under the same principle but being a novice at 3d I haven't actually tried it yet though from what I have read it is close enough.

I am using SDL for an example because as it's name implies, it is simple. See http://www.libsdl.org for documentation.

First you would load the entire image onto a surface using SDL_LoadBMP(). Once the image is on an SDL surface, you can draw portions of that image onto the screen using SDL_BlitSurface().

The SDL_BlitSurface function like all of the other 2d API's I have used requires a few important parameters:
int SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect);


src - the source surface we loaded our image onto.
srcrect - a rectangular region defining the portion of the source image to draw.
dst - the destination surface to draw to (probably the screen or a backbuffer)
dstrect - a rectangular region defining the portion of the destination surface you wish to draw to.

The source surface is our large image and the top left corner of the image is represented as 0,0 and the bottom right is 480, 256.

To draw only a portion of the larger image, just mosdify the source rectangle to match the coordinates of the portion you wish to draw.

If I have read my OpenGL tutorials correctly, a similar effect can be achieved in 3d APIs by specifying texture coordinates but it seems to be slightly more complicated but I could be wrong :)

Hope it helped.
Evillive2
if you link to the documentation of your school's library, i could see if i could figure it out. that is, if there is documentation.
FTA, my 2D futuristic action MMORPG
Woww.. Thanks a lot guys for all the help ..

Im using OpenGL for now..

About my uni library, It dont have online documentation, And I cant be bother to upload it..

I think its not have a lot of features, Although its really make easier to make simple game..

Can anyone show me example to do this in opengl? ..

Thankss..
please help ...
Since all tiles are on one image, you'll need to read the image to texture and then make a texture array. You'll have to put each tile into the texture array. I would personally recommend not even using one of these tile sheets as they just create more work. Use your favourite paint program and make new images for each tile. It's much easier.
Rob Loach [Website] [Projects] [Contact]
Quote:Original post by Rob Loach
Since all tiles are on one image, you'll need to read the image to texture and then make a texture array. You'll have to put each tile into the texture array. I would personally recommend not even using one of these tile sheets as they just create more work. Use your favourite paint program and make new images for each tile. It's much easier.


it's not really that difficult to slice an image into pieces. also, if your using a 3d API like OpenGL, i strongly recommend to do this. if you keep all your images seperate, you have to switch up the texture with every render... this can really slow down your game.
FTA, my 2D futuristic action MMORPG

This topic is closed to new replies.

Advertisement