Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorials:making_a_button [2012/01/14 20:12]
24.7.210.149
tutorials:making_a_button [2013/03/05 10:19] (current)
Line 1: Line 1:
 +====== 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:
 +
 +<code objc>
 +SPTexture *texturename = [SPTexture textureWithContentsOfFile:​@"​filename.png"​];​
 +</​code>​
 +
 +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:
 +
 +<code objc>
 +SPButton *buttonname = [SPButton buttonWithUpState:​texturename];​
 +</​code>​
 +
 +Or you can combine the 2 lines of code into:
 +
 +<code objc>
 +SPButton *buttonname = [SPButton buttonWithUpState:​[SPTexture textureWithContentsOfFile:​@"​filename.png"​]];​
 +</​code>​
 +
 +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...
 +
 +<code objc>
 +[self addChild: buttonname];​
 +</​code>​
 +
 +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