How can I create a pop-up window using Cocos2d, SpriteBuilder and Objective-c?

260 views Asked by At

So I'm trying to do exactly this:

http://blog.typpz.com/2013/12/09/ios-sdk-create-a-pop-up-window/

But since I am not using SpriteKit i can't use this exact method. I imagine that there should be a way to create this same pop up window effect using sprite builders layer option maybe? Then animating it using some of the CCAction methods that exist. Im not sure though and don't really know how to go about figuring out.

Any help is appreciated.

1

There are 1 answers

0
Zachary Espiritu On BEST ANSWER

A simple way to do this would be to create a CCLayer, as you said, and animate it.

Once you've created a CCLayer to the size of the "popup" you want, and then added whatever you want to put in it, you can then start animating it.

If you want to get a similar effect to the animation in the tutorial you linked, the best way would be to use a combination of CCActionFadeIn and CCActionScaleTo. Conveniently, Spritebuilder's animation set has both of these for use, and you can easily set up an keyframe animation from within Spritebuilder without too much code. (Make sure to name the animation sequence to something you can easily remember since you'll need to refer back to it when you start coding - I'd call it "PopupAnimation", or something like that.)

Once you've finished doing that, all you have to do is call the animation from your code. For example, if I have a CCButton whose selector is "showPopup", I would do:

func showPopup() {
    self.animationManager.runAnimationsForSequenceNamed("PopupAnimation")
}

Assuming you've done everything right, the popup will now appear! But now you're stuck with the popup on the screen, and with no way out.

To fix this, make another animation sequence (I'll call this "RemovePopup") which will remove the popup from the screen. Add a button to your CCLayer, and set its selector to "hidePopup". From your code, you can then run:

func hidePopup() {
    self.animationManager.runAnimationsForSequenceNamed("RemovePopup")
}

And now you have a "popup" window that you can animate!