Title scene: Buttons
Finally we need a play button.
The play button is another Pulpcore widget that acts just like a button.
Since the play button is also a sprite like the labels we place also most exactly the same.
The only difference is that the button graphics is driven off a sprite image. In this case the PlayButton.png
Button sprites are made of three images a normal, hover and pressed image. For ease I have placed all three images into the PlayButton.png and used the CoreImage split function to cut it into the three sprite images needed to load the button.
Another cool fact is that since the button is a sprite like the text we can also do the cool pop up trick with it too!
Now that we have a play button we need something to happen when people press it.
To achieve this we need to add an update function to our scene.
This function gets called by the scene each time in its internal game loop. I am not sure the exact details of that game loop but all we need to know is that if we put our game logic in an update it gets called.
So each time the game loops we check the buttons status with its isClicked() method. When the player clicks the button this will get set and we can run some more code to handle it.
What we do in this example is to create an interruptScene event on our timeline. What this does is change the current scene to the new scene specified after a delay.
To make this transition a little more interesting we have also added an animation to the scene groups x value.
This will make the scene and thus all the sprites contained in it magically slide away when you press the play button. This is the reason we did not add the background sprite to the scene group. It stays in place and the GUI elements slide over it.
So now you know how to use a few of the widgets and animate them with the timeline object.
It makes for a much more dynamic title scene don’t you think?