objective c - iOS Pong Development, Collision Detection -



objective c - iOS Pong Development, Collision Detection -

i in late phase of finishing first usable ios app. creating simple pong game using simple collision detection using cgrectintersectsrect, came problem.

if(cgrectintersectsrect(mic.frame,plosina_a.frame)) { if(mic.center.y < (plosina_a.center.y + plosina_a.frame.size.height)) { rychlostmice.y = -rychlostmice.y; } } if(cgrectintersectsrect(mic.frame,plosina_b.frame)) { if(mic.center.y < (plosina_b.center.y + plosina_b.frame.size.height)) { rychlostmice.y = -rychlostmice.y; } }

when utilize ball (mic) sort of gets paddles (plosina) , starts moving other way sort of in middle of paddle. programming teacher managed prepare problem 1 of paddles (the _b one) adding .frame.size.height instead of .frame have used before, when did same thing other paddle didn't work don't know what's that.

also creates problem there situation ball get's caught in paddle - i'm looking definition of whole object , not 1 side probably?

i hope can help.

i can see 3 potential problems here.

the first waiting until ball overlaps paddle before counting touch. sounds want start ball moving in other direction when ball touches paddle, not when intersects it. cgrectintersectsrect waits until overlap before returning true. if create either rectangle 1 pixel larger phone call cgrectinset, test homecoming true ball reaches paddle--by time, there 1 pixel overlapping expand rectangle. test this:

if(cgrectintersectsrect(cgrectinset(mic.frame, -1, -1),plosina_a.frame)) { if(mic.center.y < (plosina_a.center.y + plosina_a.frame.size.height)) { rychlostmice.y = -rychlostmice.y; } } if(cgrectintersectsrect(cgrectinset(mic.frame, -1, -1),plosina_b.frame)) { if(mic.center.y < (plosina_b.center.y + plosina_b.frame.size.height)) { rychlostmice.y = -rychlostmice.y; } }

the sec potential problem has velocity of ball. without seeing of code, don't know if problem or not. if ball can move more 1 pixel @ time, overlap--or pass through--the paddle without nail detection. there lots of logic changes can add together take care of this, easiest solution may create sure ball doesn't move more 1 pixel @ time.

finally, if want utilize hack both paddles, reverse sign of comparing on other side of game.

objective-c ios collision-detection

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -