-2

can someone code for me please how to add an overlay start scene in swift?

I want to add a startMenu like in Flappy Bird, and then when you click play it just moves/fades away and the game begins. Can someone help me achieve this effect?

Looking to achieve this.

I will be more than thankful!

cooldood
  • 145
  • 9
  • 1
    Please see http://stackoverflow.com/help/dont-ask along with http://stackoverflow.com/help/on-topic – Knight0fDragon Nov 18 '16 at 18:23
  • the irony is deep in @Knight0fDragon, in an answer to one of my questions he very nearly answers this question. Start here: http://stackoverflow.com/a/40640973/2109038, Mr Yannai. – Confused Nov 18 '16 at 18:44
  • 1
    There is no irony here, @Confused, you at least provided code and were looking to solve a problem. Yannai Harel is asking people for the code to solve the problem. – Knight0fDragon Nov 18 '16 at 18:48
  • I know. I'm teasing. He's new. Cut him some slack. "Enough rope..." etc. ;) – Confused Nov 18 '16 at 18:49
  • To be fair, I was scrimping. This is a problem I'm about to try to solve. I have done my menus in independent projects, and now need to merge them into the gameplay project to instruct modes, levels and difficulty settings. And I don't want to use Scenes, I'm going to try make an overlay that pops up with options, and jumps back into the game, etc. – Confused Nov 18 '16 at 18:51
  • I am giving him some slack, this is my second attempt explaining how things work here on SO – Knight0fDragon Nov 18 '16 at 18:54
  • thanks @Confused looking forward to it – cooldood Nov 19 '16 at 11:43
  • I'm voting to close this question as off-topic because SO is not a code writing service. – mhall Nov 19 '16 at 18:52

1 Answers1

1

Try to post some code of what you have tried so far when asking a question on stack overflow, people tend to not write code for you.

You can basically do this 2 ways.

1)

Either create a StartScene and transition to GameScene with your preferred SKTransition when the play button is pressed e.g SKTransition.crossFade

2)

If you want to do it in the same scene you can just create a SKNode/SKSpriteNode class to use as a menu.

class Menu: SKSpriteNode {

     lazy var playLabel: SKLabelNode = {
        let label = SKLabelNode(fontNamed: "HelveticaNeue")
        label.text = "Play"
        label.fontSize = 22
        label.fontColor = .yellow
        label.position = CGPoint(x: self.frame.midX, y: self.frame.midY)
        return label
     }()

     /// Init with size
     init(size: CGSize) {
          super.init(texture: nil, color: .red, size: size)

          addChild(playLabel)
     }
}

}

Than in your GameScene Scene you can add the menu like so with your preferred size, in this example the size of the scene.

 class GameScene: SKScene {

     lazy var menu: Menu = Menu(size: self.size)

     override func didMove(to view: SKView) {

           addChild(menu)
     }
 }

You can add other nodes for UI, including sprites for buttons etc, to that menu class.

Than in GameScene in touches Began you can look for nodes that are touched, e.g the play button and than do your thing e.g to animate out the menu

 let action1 = SKAction.fadeAlpha(to: 0, duration: 0.5)
 let action2 = SKAction.removeFromParent()
 let sequence = SKAction.sequence([action1, action2])
 menu.run(sequence)

If you stuck there and want more coding samples you should google how to do this, is basic SpriteKit stuff that you need to know and there is plenty tutorials available. This includes samples of how to make button subclasses using SKSpriteNodes.

Hope this helps

crashoverride777
  • 10,581
  • 2
  • 32
  • 56