Making a Button

Making a Button in Sparrow is simple. The first thing you need to do is create a texture by using the following code:

SPTexture *texturename = [SPTexture textureWithContentsOfFile:@"filename.png"];

This create a placeholder named texturename that you can use many times to make buttons or just put it to the screen. This helps with speed of loading so you only have to load an image once and you can use it many times.

Now to use the texture into making a button you use this code:

SPButton *buttonname = [SPButton buttonWithUpState:texturename];

Or you can combine the 2 lines of code into:

SPButton *buttonname = [SPButton buttonWithUpState:[SPTexture textureWithContentsOfFile:@"filename.png"]];

This code makes the button and loads the image at the same time so you can not use it in other ways unless reloading it.

Now you have to put it to the screen like any other image,label,etc…

[self addChild: buttonname];

Now your on your way to creating your first game!

Happy Coding

  tutorials/making_a_button.txt · Last modified: 2013/03/05 10:19 (external edit)
 
Powered by DokuWiki