forums

TNT Basic Forums > Programming Q&A
Sprites behind maps? sprite layers?
< Last Thread     Next Thread >
Author
Thread        Post A Reply

07-19-2003 01:25

Posted by:
JAS

Click Here to Email JAS   Find more posts by JAS

Hello,

I'm curious if there is a way to have sprites behind layers?

Also, how can you manipulate which sprite is over which (ie to make animated tiles show up under the player)?

07-19-2003 03:59

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Here's a thread that pertains to that

http://www.tntbasic.com/community/forums/showthread.php?threadid=669

07-19-2003 10:17

Posted by:
JAS

Click Here to Email JAS   Find more posts by JAS

So, the only way to have a sprite behind a map is to make the map out of sprites?

That still leaves the second question - of which sprite is over which open though... I'll have to experiment.

07-20-2003 05:43

Posted by:
CubeFusion

Location:
California, USA

Find more posts by CubeFusion

Set Sprite Priority spriteID,priority

Replace "spriteID" with (Insert drum roll here), the ID of the Sprite! You then replace "priority" with a number. Sprites with higher numbers appear on top of other Sprites.

07-21-2003 00:12

Posted by:
JAS

Click Here to Email JAS   Find more posts by JAS

I found that out yesterday! :)

But does that include the map? If i put a low enough number will it (the sprite) appear behind the map?

Thanks!

07-21-2003 01:21

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Only if the map is made of sprites. Sprites appear on top of everything except other sprites.

07-21-2003 05:15

Posted by:
JAS

Click Here to Email JAS   Find more posts by JAS

Drat! I'm gonna test out sprite based maps and see how they work out framerate-wise...

Thanks!

07-21-2003 23:50

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully



If it's too slow to draw all the tiles your hero can go behind as sprites, you could try just drawing the tiles as sprites that your hero is currently standing behind. As your hero has presumably a maximum fixed size, he will at most be standing on (as an example) 6 tiles. So you only actually need to pickout and draw 6 tiles as sprites around where your hero is to make him go behind them. You can turn these sprites off and reposition them every frame depending on where your hero is. You could do this for all your characters on the map that need to walk behind things.

Here's a quick code example, I've not tried this so there might be errors in it but it might give you some ideas:

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'NOTE:
' see thread http://www.tntbasic.com/community/forums/showthread.php?threadid=669 for info on using sprite priorities to control which sprites are drawn over which. This also presents a simple way of doing this that simply draws all the tiles that the hero can walk behind as sprites all the time. this is a bit slower but if it's fast enough then i'd use it as it's much easier!


' init code
global int kFirstTileSprite=1000 ' out of the way
global int gTileSprites=kFirstTileSprite
MakeTileSpriteBankUsingTilePictureAndCopyImagesCommand()

' game loop
while not gGameOver

' move hero
sprite kHeroSprite, herox, heroy, heroimage
set sprite priority kHeroSprite, heroy

' draw all the tiles the hero is over as sprites - you will probably need to tweak this for your game
MakeSpriteTile(heroxtile,heroytile,heroztile)
MakeSpriteTile(heroxtile+1,heroytile,heroztile)
MakeSpriteTile(heroxtile-1,heroytile,heroztile)
MakeSpriteTile(heroxtile,heroytile+1,heroztile)
MakeSpriteTile(heroxtile+1,heroytile+1,heroztile)
MakeSpriteTile(heroxtile-1,heroytile+1,heroztile)

draw frame
ClearSpriteTiles() ' get rid of the sprites so they can be replaced next frame at the heros new location
wend

' pulls a tile out of the map and makes a sprite out of it and places it on the screen
procedure MakeSpriteTile(int tilex, int tiley, int tilez)
int tile = map tile (tilex,tiley,tilez)

if tile = kATileThatShouldBeInFrontOfTheHero or tile = kAnotherTileThatShouldBeInFrontOfTheHero
' assume that you've created a bank with all your tiles in it - you can use the 'copy image' command to do this from your tile graphics when your game is loading

set image bank gTileSprites,kTileSpriteBank
sprite gTileSprites, tilex * map tile width, tiley * map tile height, tile
set sprite priority gTileSprites, tiley*map tile height
' draw tiles in front on main character
gTileSprites=gTileSprite+1
end if
end proc

' call after draw frame to clear all the tile sprites so then can be repositioned next frame
procedure ClearSpriteTiles()
int i
for i=kFirstTileSprite to gTileSprites
sprite off i
next i
gTileSprites=kFirstTileSprite
end proc


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

If anyone wants to make a working example out of this I'd be more than happy to discuss it. If there's a better way that someones come up with then we can discuss that too!

We really should add commands to TNT Basic to do all this automatically, I'll add it to the todo list.

Cheers,

Mark

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.