Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- iPhone Game Development, collision detection that creates a wall effect
- -(void)goDown{
- mainSprite.center = CGPointMake(mainSprite.center.x, mainSprite.center.y+5);
- }
- -(IBAction)down{
- [self downAnimation];
- goDown = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(goDown) userInfo:nil repeats:YES];
- if (goDown == nil) {
- goUp = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(goDown) userInfo:nil repeats:YES];
- }
- }
- -(void)collision {
- if (CGRectIntersectsRect(mainSprite.frame, collisionImage.frame)) {
- }
- }
- - (void)goDown {
- float delta = [self checkCollision];
- mainSprite.center = CGPointMake(mainSprite.center.x, mainSprite.center.y + delta);
- }
- - (float)checkCollision {
- CGRect testFrame = CGRectMake(mainSprite.frame.origin.x, mainSprite.frame.origin.y + 5.0f, mainSprite.frame.size.width, mainSprite.frame.size.height);
- if (CGRectIntersectsRect(testFrame, collisionImage.frame)) {
- return 0.0f;
- // stop the sprite from moving anymore so it doesn't actually intersect, just stops "on top"
- }
- return 5.0f;
- // if they have not collided then just continue on your way
Add Comment
Please, Sign In to add comment