Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / 2D: Spritesheets with more than just one sprite?

Author
Message
StaticSD
14
Years of Service
User Offline
Joined: 17th Jan 2010
Location:
Posted: 17th Jan 2010 21:02
I wrote some code that will turn data from an array into tiles on a map. But I have to load the two different tiles, grass and water, as separate image files. Is there a way to have both tiles on the same image file, and have code that will select a 32x32 rectangle from the loaded image, give that an ID, and draw it on the screen? For example...

dbLoadImage(1, "spritesheet.png");
dbSelectSprite(1, 0, 0, 32, 32, 1); //position on image, and size
dbSprite(1, 100, 100, 1);

Or something similar?

I understand that it is possible to have a spritesheet for, say, the player, and have code that will automatically split that up into its' however-many frames, like the meteors on the 2D Game wizard. But is it possible to have more than one sprite, possibly with separate frames, on the same spritesheet?

neguz
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 17th Jan 2010 22:16
dbSetSpriteTextureCoord
This command will modify the internal UV data of the specified sprite. You can manipulate each vertex of the sprite by specifying a vertex index from 0 to 3. The fU and fV specify a value typically from 0.0 to 1.0.

Syntax
void dbSetSpriteTextureCoord ( int iSprite, int iVertex, float fU, float fV )

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
StaticSD
14
Years of Service
User Offline
Joined: 17th Jan 2010
Location:
Posted: 18th Jan 2010 00:57 Edited at: 18th Jan 2010 07:56
EDIT (9:23pm): Ah, sweet success. Thank you very much! After a few hours of trial and error (sigh -.-) and a couple google searches for examples, I came up with something that works:



Then, to make a map, I make an array of 1's, 2's, 3's, and 4's to represent grass, water, snow, and sand, then forward it to MapInit() and bickety-bam, it works like a charm. As far as I know, though, the tileset image must be square, and then iX, iY, and fOffset must reflect the new dimensions in tiles.

In other words, my current tileset has four tiles, 2x2. So:
int iX = cellValue % 2;
int iY = cellValue / 2;
float fOffset = 1.0f / 2.0f;

If I had 16, or 4x4, it would have to be:
int iX = cellValue % 4;
int iY = cellValue / 4;
float fOffset = 1.0f / 4.0f;

Anyways, it works great. Thanks again!

neguz

Login to post a reply

Server time is: 2024-11-20 05:39:14
Your offset time is: 2024-11-20 05:39:14