RPG Sprites Overlapping Check

For questions about using Classic.

Post » Sun Feb 28, 2010 8:23 pm

So I am making this top-down RPG. For a sprite in the game, there are two objects: (1)the image of the sprite, and (2)the invisible collision box.
These applies to all sprites in-game, which includes NPC.

I tried to make it so that when the hero is in front of an npc(since it's top-down, that means he is on a larger Y coordinate), his image is above the image of the npc, and when the hero is behind the npc, his image is then put under the npc sprite.
I made this by checking the Y coordinates however it only applies to a single NPC - what if there are hundreds of npc sprites on the layout? It seems impractical to check each and every one. And also there is a possible case that I will spawn two of the same npc class on a layout.
I don't know how the event will go so it could pick up the correct object and since the sprite is actually two objects in itself(image and collBox), I wonder how to check the Y coord of the box and apply it to the correct positioning to the image he is assosciated with.

Help Please?
B
16
S
10
G
5
Posts: 255
Reputation: 3,934

Post » Sun Feb 28, 2010 8:54 pm

It should pick the correct one automatically and let you placed the player in front or behind it, without worrying about any of the others.
B
3
S
2
G
3
Posts: 628
Reputation: 2,531

Post » Sun Feb 28, 2010 9:59 pm

Yea, I figured it should do that.

So I just used a for loop to check each and every one of the npc sprite. Inside the loop are the conditions(comparing coords) and the events(placing what behind or in front what).

Is it practical to do this?
B
16
S
10
G
5
Posts: 255
Reputation: 3,934

Post » Sun Feb 28, 2010 10:38 pm

Personally I would do the check when a collision occurs between an NPC & the hero, why check if the hero is above an NPC that is on the oposite side of the Layout.

http://dl.dropbox.com/u/1646976/zdepthtest.cap
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Sun Feb 28, 2010 10:53 pm

You could try a 'for each object (ordered)' loop and place all the objects that need sorting into a family
Then use the aforementioned loop to order that family based on their Y co-ordinate in ascending order.
I'm guessing this is the problem you needed help with, I just woke up so I'm all blurry lol

If you're thinking it'll be too much on the processor due to large layouts and many objects, you could try the condition, 'Object is on-screen', that might help lower the amount of objects needing to be sorted, although I've never tried it.
B
3
S
2
G
5
Posts: 351
Reputation: 2,377

Post » Sun Feb 28, 2010 11:29 pm

[quote="Minor":8jmfbhis]Personally I would do the check when a collision occurs between an NPC & the hero, why check if the hero is above an NPC that is on the oposite side of the Layout.[/quote:8jmfbhis]

Don't do that, collision checks are way more CPU intensive than simply checking a value. Use what Arcticus suggested.
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Mon Mar 01, 2010 12:50 am

Yea, I also really can't use collision checking because the sprite image might intersect with npc image even though their bases(collision box) haven't collided which would make it weird when the hero is on a lower Y coord but he appears above the npc..

Thank you for the suggestions, I am now using the for each loop with a family.
B
16
S
10
G
5
Posts: 255
Reputation: 3,934


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 8 guests