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.

AppGameKit Classic Chat / Using sprite sheets?

Author
Message
wargasmic
17
Years of Service
User Offline
Joined: 15th Oct 2006
Location: UK
Posted: 16th Jul 2012 05:54
I'm storing my tiles/texture splats for my 2d rts terrain in a sprite sheet for each tile/texture type. What is the process for drawing sections of a sprite sheet? Or do i need to create a separate sprite for each section of the sprite sheet?
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 16th Jul 2012 09:44 Edited at: 16th Jul 2012 09:47
Nah, it's really straightforward. Once you've loaded your sprite sheet, make a sprite to go with it, then set the animation, and with that you set the tile width and height, and number of images. Then you can set the sprite frame, or animate it automatically.



That code creates sprite 2, from image 10, and sets it to use individual sprite sizes of 96x96 - for 100 frames.

Then you can set the sprite frame with SetSpriteFrame(s,f)

Health, Ammo, and bacon and eggs!
wargasmic
17
Years of Service
User Offline
Joined: 15th Oct 2006
Location: UK
Posted: 17th Jul 2012 17:51
Thanks very much Van B.
wargasmic
17
Years of Service
User Offline
Joined: 15th Oct 2006
Location: UK
Posted: 17th Jul 2012 18:30
I'm a bit confused here. I don't see anything when creating an animated sprite and how would I use this to draw my terrain? Wouldn't I still need to create as many sprites as the amount of tiles/splats that I need to draw? Or am I missing something?



So there I create the sprite with the required properties and frames....but lets say in the main loop I set the sprite frame and position for each splat I need to draw, isn't it only going to draw the very last one every time? First things first though, as I said above, I currently don't see anything being drawn.
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 17th Jul 2012 18:47
You need to have either enough sprites to cover the screen and move them around or you can create all the sprites for your level and let AppGameKit handle them. Either way, you need more than 1

Have you synced the screen?

The Zoq2
14
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 17th Jul 2012 19:08
You could try the Draw sprite command, then you would only need one sprite per terrain type...
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 17th Jul 2012 19:24
Draw is slower than rendering multiple sprites. Or at least it is using T1.

Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 17th Jul 2012 19:39
When I did a quick map example, I just cloned a sprite that was set with the image and animation properties - kinda like a brush sprite. Check my tiled map example in this forum to see what I did, but anyway I use a global sprite ID, set it to say, 300, then for each screen map location I clone the brush sprite if it isn't already cloned, and position the sprite to suit.
There is a lot of overkill in that demo, I mean it has a basic 4-bit tile transition, which means some sprites are bigger than their grid size. This gives things like overhanging grass, extra depth for bricks on vertical walls, that sort of thing. The main benefit is that it allows for depth, so a tile might be more like an object, as well as a straightforward chunk of ground. So it's not a typical tile map, but it uses all the same principles. I guess it could be the start of a 2.5D Minecraft clone, where each 'tile' is more like a Minecraft block. Would have to put in a lot of work to optimize enough though, things like AGK's automatic sprite hiding when sprites are in front. Probably better just waiting for some 3D commands and use cubes for anything too complex like that.

Health, Ammo, and bacon and eggs!

Login to post a reply

Server time is: 2024-05-05 13:57:20
Your offset time is: 2024-05-05 13:57:20