Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

NauticalJuly

macrumors newbie
Original poster
Jul 6, 2014
2
0
Hi,

I am building a game where part of the functionality requires me to swipe down and make the character drop a level. In order to do this I have set the UIImage for the platform to equal nil when swiped down but cannot figure out how to make this only happen for a second so that the character will fall through on swipe but when jumps back up the image has returned. Below is my code so far. Any help would be very much appreciated!

Code:
- (void)oneFingerSwipeDown:(UITapGestureRecognizer *)recognizer {
    platform = nil;
}

Thanks
 
I'm not sure I understand fully, but, why are you setting the platform to nil? If you do, then you have to recreate another one for later use. If you don't want it dispyed then perhaps try platform.hidden = YES

Also, wouldn't the platform appear above your character?

Lastly, I'm surprised you are using a tap grater instead of a swipe gesture you have described.
 
Thanks for your reply.

I have updated the code to:

Code:
- (void)oneFingerSwipeDown:(UISwipeGestureRecognizer *)recognizer {
    platform3 = nil;
}

But when I try platform.hidden = YES, it only hides the graphic, the character can still walk on it defeating the purpose of the swipe to drop a level. Any ideas how i can temporarily remove the graphic altogether and have it return in the exact same position seconds later?
 
We know nothing about the structure of your game. This could be done in a million different ways. What are you using to build the game? We don't even know what platform or plarform3 are

Tell us more about it
 
As JohnsonK said, more information is needed.

It sounds to me like you have bound the character to the platform. I'm no game developer, but I'd think your character should be controlled by its relative position within the world it lives in.
 
Hi NauticalJuly,

I confirm with xStep: platform.hidden = YES

Your collision check should also contain a check if the platform is not hidden.
So then the sollution of xStep does work.

Or:

You could also just disable the collision check for a second or less (the time it takes for the character to pass the platform) with an timer.
Make sure your collisionCheck only works when for example:
collisionEnabled == YES

Then you can use the following:

Code:
-(void)enableCollision {
 collisionEnabled = YES;
}
- (void)oneFingerSwipeDown:(UISwipeGestureRecognizer *)recognizer {
 //Disable collision check NOW.
 collisionEnabled = NO;
 //Start timer to enable it after .. 1.0 second?
 NSTimer *timedDisableCollision = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(enableCollision) userInfo:nil repeats:NO];
}

The timer will kick in after 1 second, and will not repeat.

Hopefully this will help you out a little.
 
Hi NauticalJuly,

I confirm with xStep: platform.hidden = YES

Your collision check should also contain a check if the platform is not hidden.
So then the sollution of xStep does work.

Or:

You could also just disable the collision check for a second or less (the time it takes for the character to pass the platform) with an timer.
Make sure your collisionCheck only works when for example:
collisionEnabled == YES

Then you can use the following:

Code:
-(void)enableCollision {
 collisionEnabled = YES;
}
- (void)oneFingerSwipeDown:(UISwipeGestureRecognizer *)recognizer {
 //Disable collision check NOW.
 collisionEnabled = NO;
 //Start timer to enable it after .. 1.0 second?
 NSTimer *timedDisableCollision = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(enableCollision) userInfo:nil repeats:NO];
}

The timer will kick in after 1 second, and will not repeat.

Hopefully this will help you out a little.

This is going to be a mess for multiple objects
 
It depends how you do your collision check
For this you shud put it only in the place where you check for the platform
No real need for a timer
Just a bool to see if the character must fall down and make the check more complicated but as the TO doesnt provide more this is the best I can come up with

A simpl boolean wud be good enough if you only check player bottom and platform top
When boolean is true dont collide it
But its same concept only without timer
Again, you dont know enough to provide a correct answer
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.