forums

TNT Basic Forums > Programming Q&A
map object Sprite Priority in relation to heroY ordinate
< Last Thread     Next Thread >
Author
Thread        Post A Reply

10-07-2009 00:18

Posted by:
Destro

Location:
LBC (langley British Columbia)

Find more posts by Destro

My spaceship game idea hit a roadblock, so I started making an overhead RPG type game just so I could keep learning and working, since the tutorials on this site apply more to that type of game. I've gotten as far as having a hero, a scrolling map with barrier tiles the hero can't cross, and map objects.
When I did the map objects it occured to me that when the hero passes in front of a tree object he should appear behind it, and when passing behind a tree he should appear in front of it. So I read about sprite priority, and tried to assign it this way:

for n=0 to objNum-1
objType=map object type (n)

if objType=0
sprite n+2,pX[n]-xmap,pY[n]-ymap,10
end if
if objType=1
sprite n+2,pX[n]-xmap,pY[n]-ymap,11
end if
if objType=2
sprite n+2,pX[n]-xmap,pY[n]-ymap,12
end if

tile=map tile (pX[n]/16,pY[n]/16,0)

'Sprite Overlap

if yposp1>pY[n]
set sprite priority 1,5
end if
if yposp1<pY[n]
set sprite priority 1,0
end if
next n

I've got about 15 objects on the map, and one of them works perfectly, but the other objects on the map above it all appear in front of the hero, and the ones below appear behind. I'm not sure why the one object works... unless each object is being assigned a priority greater than the previous object in the for loop, and priority 5 just happens to coincide with the working object being the fifth one to be placed by the for loop? Seems like all SNES rpg's implement this, where on NES the view was absolute top down view and didn't need anything like this.
Any ideas? If you've seen my other posts, you might have noticed that I'm a bonehead.

10-08-2009 16:42

Posted by:
Destro

Location:
LBC (langley British Columbia)

Find more posts by Destro

Here's what I've got now, should mention all sprite offsets are bottom-middle.

collision=sprite col (1,0 to 10000)

if collision > 0 and sprite image (collision)=10 'boulders
if sprite y (collision) > yposp1-ymap
set sprite priority 1,-1
end if
if sprite y (collision) < yposp1-ymap
set sprite priority 1,999
end if

if yposp1-ymap <= sprite y (collision) +6
if up then yposp1=yposp1+6
end if
if yposp1-ymap >= sprite y (collision) -6
if down then yposp1=yposp1-6
end if
end if

Problem is, as it stands it won't let you move away from the sprite once you are touching it. This works great for walking through tall grass or shrubs though, if you omit the last 6 lines.

10-08-2009 23:45

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Welcome to the boards...

Hi Destro, Easiest answer to this is to set the priority of all sprites to be equal to their y coordinate whenever their position is updated. You can do this as your hotspots are bottom-middle (doesn't always work otherwise). I don't know how you are displaying the map object sprites, so if it doesn't work, update the priority whenever you draw them and it should solve the issue...
This works for 99% of situations and is pretty quick.

Any more problems just drop us a line.

Danny (nod the mod)

10-09-2009 07:05

Posted by:
Destro

Location:
LBC (langley British Columbia)

Find more posts by Destro

Hey that's a really smart way to do it! But how would you deal with the sprite collisions, so that the hero cannot pass through the objects vertically, but can still be touching an object and pass through it from side to side (so it looks like walking in front/behind it)?

10-09-2009 08:19

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Don't use collisions...

Just refer to the map tile and don't let them walk on a 'blocked' one...

If you have to use collisions, remember that the parameters passed to 'sprite col()' are sprite ID's, the actual number of the sprite, they have nothing to do with the priority. If you keep all of your 'terrain sprites' (trees, boulders etc.) together you can check for your main character bumping into stuff with a single call. You don't need to check to see if the terrain has collided with the character, as you already know the character has not bumped into the terrain... And as trees are unlikely to walk into each other, or rocks for that matter, there's no need to check for collisions between terrain sprites either...

This game programming lark is a doddle ain't it?

Danny (nod the mod)

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.