Jump to content

Tile map gid collision musings


d13
 Share

Recommended Posts

Here's the setup:

 

I have an integer array full of gid (tileset grid id numbers).

Each of those gid numbers represents a single kind of item.

I have nameless sprites that represent these items on the screen.

For example, there might be ten sprites, and all have the gid number, "5", in the array

 

Ok, got it?

 

Cool!

Then my question is this:

 

If I detect a collision with one of those gid numbers in the array, how can I link it back to the specific sprite on the screen?

For example, I know I'm hitting a sprite with gid of "5", but I don't know which specific sprite that is.

 

I've thought about giving sprites an "index" property to track this, but it seems sort of messy to do that.

... but then again, maybe it's the best way?

Or, I could reverse look-up each sprite's xy coordinate to find its matching array index number... but maybe that's too much extra overhead?

I also don't want to add more complexity by replacing the integer array with an array of sprite objects.

 

I'm testing a few approaches, but any clever insights from any of you smart people would be most welcome!

 

- d13.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...