Sign in to follow this  
BrentBarrett

Difficult Level Editor feature

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this