Jump to content
  • Advertisement
Sign in to follow this  
Zherebyatyev

How to initiate all physics with the button? Xcode 6, Swift

This topic is 1323 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How to initiate all physics with the button?

Now my game (all physics inside it) initiates just when i run it on the iOS Simulator, but i would like to initiate it with pushing a PLAY button.

This is my button's code:

var playButton:SKSpriteNode = SKSpriteNode(imageNamed:"playButton")
playButton.position = CGPoint(x: self.frame.size.width / 2 , y: self.frame.size.height / 2)
playButton.setScale(0.5)
self.addChild(playButton)

Share this post


Link to post
Share on other sites
Advertisement

I don't know much about Swift, but you can have a state variable (that can  be START, PLAY, GAME_OVER) and in your update method you can check what the state is and respond differently. Like so:

-(void)update
{
 if (self.state == START)
 {
  if (button pressed)
   self.state = PLAY;
 }
 else if (self.state == PLAY)
 {
  if (!physics)
   [physics init];
  [physics update];
 }
 else if (self.state == GAME_OVER)
 {
  //...
 }



}

It's called finite state machine.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!