Difficult Level Editor feature

Started by
5 comments, last by dhanji 19 years, 7 months ago
I'm working on a level editor for my game. I've got a window where the user can plot sprites when in "Draw" mode. When the user is in "Select" mode, the user can click on a sprite that has already been placed to move it. At least that's what I'd like to have happen. I can't figure out how to know which sprite was selected when the mouse is clicked. Part of the problem is I can't just check the coords of the point where I clicked against the coords of sprites because of the z-layer. If I have one sprite halfway over another, then when I click on the sprite beneath it I'm still technically clicking within the bounds of the top sprite. So, the question is, how do I find out which sprite I'm clicking?
Advertisement
Quote:Original post by BrentBarrett
If I have one sprite halfway over another, then when I click on the sprite beneath it I'm still technically clicking within the bounds of the top sprite.
That doesn't make sense. Always select whichever sprite is topmost.
Ha, sorry, I guess I wasn't clear.

Okay, let's say I have SpriteA and SpriteB:

  SpriteA____________|          ||    0     ||   /|\    ||   / \    ||          |------------  SpriteB____________|          ||          ||   __|>   ||  /  \    ||          |------------

SpriteA contains the image of a man. The area around the man represents the transparent area of the sprite.
SpriteB contains the image of a dog. The area around the dog also represent transparency.
Now, let's say those two sprites had been plotted like this:
_________________|    |      |   ||    |    o |   ||   _|_|>/|\|   ||  / | \ / \|   ||    |      |   |-----------------

They both have the same z-order, one was just plotted over the other. If I click on the dog or the man, they are both technically with the sprite boundaries of the other. So how would I then differentiate between who was really clicked?
I'm thinking I'm going to have to get the front buffer, lock the area around where the user clicked, find the color of the pixel clicked, then compare the color to that pixel position on both of the sprites. I'd really prefer not to do that, and I'm not even sure I could, so does anyone have any ideas?
Use a heuristic, like always picking whichever one is further to the left. If it's not what the user wanted, he'll move his pointer to the right and select again.
Use the [code] tag to maintain whitespace in ASCII art.
The way many similar products will do it is a bit more complicated. Try creating a list of all the sprites that the user clicked on at that Z-Depth and then each click rotate through that list. For instance the first click would select the man, the second the dog, the third the man again, and so on and so forth. In this way it will be possible to select a sprite even if the two sprites are exactly overlapping, which would be common if you were trying to do superimposition.
Quote:For instance the first click would select the man, the second the dog, the third the man again, and so on and so forth.


this doesnt seem like a very intuitive way to me. I would recommend using Layers instead, and u can gray everything thats not on the current layer and even though it's still on top (u see the correct zorder) ur clicks will still net u the right sprite ur looking for.

Have a small layers palette on the corner or something. Two sprites on the same layer shouldnt overlap each other. Atleast for most 2D game purposes this can be done easily. BTW, can u give us a hint as to what kind of game this is? Why would you need so many sprites behind each other?
________________
"I'm starting to think that maybe it's wrong to put someone who thinks they're a Vietnamese prostitute on a bull"       -- Stan from South Park
Lab74 Entertainment | Project Razor Online: the Future of Racing (flashsite preview)

This topic is closed to new replies.

Advertisement