Game Platform Question - UIImage

Discussion in 'iOS Programming' started by NauticalJuly, Jul 6, 2014.

  1. NauticalJuly macrumors newbie

    Joined:
    Jul 6, 2014
    #1
    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
     
  2. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #2
    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.
     
  3. NauticalJuly thread starter macrumors newbie

    Joined:
    Jul 6, 2014
    #3
    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?
     
  4. JohnsonK macrumors regular

    Joined:
    Mar 6, 2014
    #4
    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
     
  5. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #5
    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.
     
  6. DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #6
    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.
     
  7. JohnsonK macrumors regular

    Joined:
    Mar 6, 2014
    #7
    This is going to be a mess for multiple objects
     
  8. DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #8
    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
     

Share This Page