RPG Sprites Overlapping Check

This forum is currently in read-only mode.
From the Asset Store
Dirt Bike game sprites - including environment, human rider and more!
  • 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?

  • 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.

  • 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?

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

    Don't do that, collision checks are way more CPU intensive than simply checking a value. Use what Arcticus suggested.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)