Sign in to follow this  

Drawing Sprites

This topic is 4851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The way I'm planning my ISO game is to pretty much have any object attatched to a tile be it a corpse, an item, or a solid object(player, wall, chest, etc). What I am trying to figure out is, since all my objects/players/monsters are attatched to the tiles, if an object leaks into other tiles and I try to click it with the mouse, what do i need to do so that it will select the object and not the tile or w/e is linked to that tile?

Share this post


Link to post
Share on other sites
In Golem 2D, selection is done by maintaining a list which is constructed each time the screen is drawn. Each object drawn constructs and inserts a Label into the list A Label contains the on-screen bounding rectangle of the object, and the object ID tag of the object. The list is kept sorted back to front, so that Labels for more recently drawn objects are on top. Finding the object beneath the mouse cursor, then, is as simple as iterating the list from top to bottom (in reverse order that the Labels were inserted) and testing each bounding rectangle until the first intersection is found, and returning the ID tag of the associated object. This way, hit testing is not bound to tile boundaries, but rather to actual on-screen space.

If you desire, you can mix a per-pixel accurate secondary test to further verify a possible intersection match when iterating the list. If the mouse cursor is shown to intersect a sprite's Label, then a further test is performed against the animation frame of the sprite for that frame, to see if the mouse cursor intersects the drawn image of the sprite. I do not take it this far myself, since the cruder bounding rectangle gives me plenty of accuracy for my tastes, but it is possible.

Share this post


Link to post
Share on other sites
I recomend doing the secondary per-pixel test, after the bounding rect has checked out, most people expect it in games, and without it, you can get some really weird hit testing issues, especialy with concave sprites. My engine creates a bit array of images in software which is used for boolean per-pixel hit testing, it works pretty well, the hit test pixel it determined by transformation of where the mouse is relative to the frame rectangle and the current frame that is being displayed of the item, this way if an object is animating their hit test region changes with it, so as not to cause possibhle false tests.

Share this post


Link to post
Share on other sites

This topic is 4851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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