Sign in to follow this  
coderx04

Template Image

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this