Easier way to setup collision detection ?

Discussion in 'iOS Development' started by JesseEtzler, Jun 15, 2009.

  1. JesseEtzler

    JesseEtzler New Member

    Joined:
    Jun 7, 2009
    Messages:
    19
    Likes Received:
    0
    Device:
    iPod touch
    I'm currently doing all my collision using UIImageViews along with collision code but it's getting to the point where it's beginning to be overwhelming. My level designs need a ton of collision done but I'm not sure if there's an easier way to do so and was hoping someone might have an easier method for getting the job done in a much faster and easier fashion.

    BTW I'm using a view based application.
  2. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    Easier collision detection than what?

    I mean, what are you using?

    I don't know if you are already doing this, but you should put your objects in an array and have every object in the array check if it's colliding with any of the other objects in the array.
  3. JesseEtzler

    JesseEtzler New Member

    Joined:
    Jun 7, 2009
    Messages:
    19
    Likes Received:
    0
    Device:
    iPod touch

    I know I'm able to put them into an array but is there an easier way than having to create Imageviews for wall1,wall2,wall3,wall4,ect.. then create seperate CGRectIntersects to check if character is colliding with wall1 and so on for all the walls. Also each of my walls are not the same width or height. So what I'm trying to ask is there a way to merge all my imageviews into 1 single object and have just 1 method for calling CGRectIntersects rather than a hundred.
  4. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    Well, two things jump to my mind.

    First would be to use a system similar to this one:
    http://www.ifans.com/forums/showthread.php?t=196086

    Second is to have an array and, as you move, add and remove objects from it, depending if they are close enough. Then have check collisions for the objects in that array. (It's cheaper to compute the distance than a CGRect intersection)

    The first one is easier to implement. And probably better, I'd go with that one.
  5. JesseEtzler

    JesseEtzler New Member

    Joined:
    Jun 7, 2009
    Messages:
    19
    Likes Received:
    0
    Device:
    iPod touch


    Ya the color collision I've known about for a long time now but haven't been successful in implementing it yet. what I have found out how to tell if a pixels alpha channel is lower than 0.5 so a image could have pixel perfect collision for touches, just not sure how to transfer that over to collision detection between two imageviews.

Share This Page