Guest User

Untitled

a guest
Aug 16th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. iPhone Game Development, collision detection that creates a wall effect
  2. -(void)goDown{
  3. mainSprite.center = CGPointMake(mainSprite.center.x, mainSprite.center.y+5);
  4. }
  5.  
  6. -(IBAction)down{
  7. [self downAnimation];
  8. goDown = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(goDown) userInfo:nil repeats:YES];
  9. if (goDown == nil) {
  10. goUp = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(goDown) userInfo:nil repeats:YES];
  11.  
  12. }
  13. }
  14.  
  15. -(void)collision {
  16. if (CGRectIntersectsRect(mainSprite.frame, collisionImage.frame)) {
  17.  
  18. }
  19. }
  20.  
  21. - (void)goDown {
  22. float delta = [self checkCollision];
  23. mainSprite.center = CGPointMake(mainSprite.center.x, mainSprite.center.y + delta);
  24. }
  25.  
  26. - (float)checkCollision {
  27. CGRect testFrame = CGRectMake(mainSprite.frame.origin.x, mainSprite.frame.origin.y + 5.0f, mainSprite.frame.size.width, mainSprite.frame.size.height);
  28. if (CGRectIntersectsRect(testFrame, collisionImage.frame)) {
  29. return 0.0f;
  30. // stop the sprite from moving anymore so it doesn't actually intersect, just stops "on top"
  31. }
  32. return 5.0f;
  33. // if they have not collided then just continue on your way
Add Comment
Please, Sign In to add comment