<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Quique&#039;s Blog</title>
	<atom:link href="http://quique123.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://quique123.wordpress.com</link>
	<description>Quique&#039;s iphone programming blog</description>
	<lastBuildDate>Sat, 18 May 2013 12:43:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='quique123.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/90131f5d5bd7dd781bbea966c998f45d?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Quique&#039;s Blog</title>
		<link>http://quique123.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://quique123.wordpress.com/osd.xml" title="Quique&#039;s Blog" />
	<atom:link rel='hub' href='http://quique123.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Cocos2d Tips: Sounds &amp; Text</title>
		<link>http://quique123.wordpress.com/2013/05/09/cocos2d-tips-sounds-text/</link>
		<comments>http://quique123.wordpress.com/2013/05/09/cocos2d-tips-sounds-text/#comments</comments>
		<pubDate>Thu, 09 May 2013 12:30:42 +0000</pubDate>
		<dc:creator>marskoko</dc:creator>
				<category><![CDATA[Cocos2d]]></category>

		<guid isPermaLink="false">http://quique123.wordpress.com/?p=458</guid>
		<description><![CDATA[Professionalize your game by adding sounds and text for menus and labels throughout your game. SOUND To play sounds you need the Sound Engine, which you import into your layer like so: #import &#8220;SimpleAudioEngine.h&#8221; Then you can just code a method to handle some background music playing: -(void)loadAudio { // Loading Sounds Synchronously [CDSoundEngine setMixerSampleRate:CD_SAMPLE_RATE_MID]; [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=458&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Professionalize your game by adding sounds and text for menus and labels throughout your game.</p>
<div id="attachment_465" class="wp-caption aligncenter" style="width: 360px"><a href="http://quique123.files.wordpress.com/2013/05/fa-18_hornet_breaking_sound_barrier_7_july_1999_-_filtered.jpg"><img class="size-full wp-image-465" alt="Sound Creates Impacts!" src="http://quique123.files.wordpress.com/2013/05/fa-18_hornet_breaking_sound_barrier_7_july_1999_-_filtered.jpg?w=595"   /></a><p class="wp-caption-text">Sound Creates Impacts!</p></div>
<h1 style="text-align:center;"><b>SOUND</b></h1>
<p>To play sounds you need the Sound Engine, which you import into your layer like so:</p>
<p>#import &#8220;SimpleAudioEngine.h&#8221;</p>
<p>Then you can just code a method to handle some background music playing:</p>
<blockquote><p>-(void)loadAudio {</p>
<p>// Loading Sounds Synchronously</p>
<p>[CDSoundEngine setMixerSampleRate:CD_SAMPLE_RATE_MID];</p>
<p>[[CDAudioManager sharedManager] setResignBehavior:kAMRBStopPlay</p>
<p>autoHandle:YES];</p>
<p>soundEngine = [SimpleAudioEngine sharedEngine];</p>
<p>[soundEngine preloadBackgroundMusic:BACKGROUND_MUSIC];</p>
<p>[soundEngine playBackgroundMusic:BACKGROUND_MUSIC];</p>
<p>}</p></blockquote>
<p>You can see immediately that you can preload the audio in one place and then play it in another. This is great for game performance. This means you can preload audio in the main menu, for example, and then play it when you actually need it.</p>
<p>Another way to put this into perspective is to preload an audio when an object such as an enemy ship or main player is created and then play the specific sound when his state is changed. For example, if you create a main player class which manage the player&#8217;s state between walking, jumping, running, flying&#8230;you can make the calls to play different sound effects when the player&#8217;s state changes.</p>
<p>For example;</p>
<blockquote><p>-(void)changeState:(CharacterStates)newState {</p>
<p>// stop all, nil action, nil move, newPosition ivar, set new state passed into it&#8230;</p>
<p>[self stopAllActions];</p>
<p>id action = nil;</p>
<p>[self setCharacterState:newState];</p>
<p>switch (newState) {</p>
<p>case kStateFlying:</p>
<p>action = [CCAnimate actionWithAnimation:flyingAnim];</p>
<p>break;</p>
<p>default:</p>
<p>break;</p>
<p>} // ends the switch that checks for state</p>
<p>if (action != nil) {</p>
<p>[self runAction:[CCRepeatForever actionWithAction:action]];</p>
<p>}</p>
<p>}</p></blockquote>
<p>You can also get more sophisticated and preload audio into your layer using plists for lists of files which are loaded as soon as the scene is loaded. We will look at this in the Advanced flavor of this post!</p>
<div id="attachment_466" class="wp-caption aligncenter" style="width: 360px"><a href="http://quique123.files.wordpress.com/2013/05/slidingtext_fr.jpg"><img class="size-full wp-image-466" alt="Text is Terrific!" src="http://quique123.files.wordpress.com/2013/05/slidingtext_fr.jpg?w=595"   /></a><p class="wp-caption-text">Text is Terrific!</p></div>
<p><b>TEXT</b></p>
<p>Now let&#8217;s move on to some text. One of my favorite places to add text is at the beginning of a layer when the game is about to start. For this we create a label like so:</p>
<blockquote><p>CGSize winSize = [CCDirector sharedDirector].winSize;</p>
<p>label = [CCLabelTTF labelWithString:@"hello!" dimensions:CGSizeMake(300, 250) hAlignment:UITextAlignmentCenter fontName:@"Stencil" fontSize:40];</p>
<p>label.color = ccc3(000,000,000);</p>
<p>label.position = ccp(winSize.width/2, winSize.height/2);</p>
<p>This creates a simple label which you can place anywhere on the screen, change its color etc. Let&#8217;s say you also wanted to animate this label, you could string this along at the bottom:</p>
<p>CCScaleTo *scaleUp = [CCScaleTo actionWithDuration:2.5 scale:1.8];</p>
<p>CCScaleTo *scaleBack = [CCScaleTo actionWithDuration:0.5 scale:1.5];</p>
<p>CCDelayTime *delay = [CCDelayTime actionWithDuration:3.0];</p>
<p>CCFadeOut *fade = [CCFadeOut actionWithDuration:1.5];</p>
<p>CCHide *hide = [CCHide action];</p>
<p>CCSequence *sequence = [CCSequence actions:scaleUp, scaleBack, delay, fade, hide, nil];</p>
<p>[label runAction:sequence];</p></blockquote>
<p>Cool! Now you&#8217;ve got the workings of some awesome eye candy for your games.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/quique123.wordpress.com/458/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/quique123.wordpress.com/458/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=458&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://quique123.wordpress.com/2013/05/09/cocos2d-tips-sounds-text/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/eca64ed04a39c23b1bb8f6267524c961?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marskoko</media:title>
		</media:content>

		<media:content url="http://quique123.files.wordpress.com/2013/05/fa-18_hornet_breaking_sound_barrier_7_july_1999_-_filtered.jpg" medium="image">
			<media:title type="html">Sound Creates Impacts!</media:title>
		</media:content>

		<media:content url="http://quique123.files.wordpress.com/2013/05/slidingtext_fr.jpg" medium="image">
			<media:title type="html">Text is Terrific!</media:title>
		</media:content>
	</item>
		<item>
		<title>GrandCentralDispatch &amp; Blocks</title>
		<link>http://quique123.wordpress.com/2013/04/21/grandcentraldispatch-blocks-2/</link>
		<comments>http://quique123.wordpress.com/2013/04/21/grandcentraldispatch-blocks-2/#comments</comments>
		<pubDate>Sun, 21 Apr 2013 23:06:56 +0000</pubDate>
		<dc:creator>marskoko</dc:creator>
				<category><![CDATA[Iphone Developer]]></category>

		<guid isPermaLink="false">http://quique123.wordpress.com/2013/04/21/grandcentraldispatch-blocks-2/</guid>
		<description><![CDATA[Reblogged from Quique&#039;s Blog: GCD helps improve your apps performance and responsiveness by outsourcing processes that require a lot or computing power to the background while keeping your UI responsive.  Normally you might want to do some heavy lifting. Let's create an Empty Application.  You need to declare a IBOutlet UIImageView *imageView ivar in your [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=463&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<div class="reblog-post"><p class="reblog-from"><img alt='' src='http://2.gravatar.com/avatar/eca64ed04a39c23b1bb8f6267524c961?s=25&amp;d=identicon&amp;r=G' class='avatar avatar-25' height='25' width='25' /> <a href="http://quique123.wordpress.com/2012/12/05/grandcentraldispatch-blocks/">Reblogged from Quique&#039;s Blog:</a></p><div class="wpcom-enhanced-excerpt"><div class="wpcom-enhanced-excerpt-content"><a href="http://quique123.wordpress.com/2012/12/05/grandcentraldispatch-blocks/" target="_self"><img src="http://quique123.files.wordpress.com/2012/02/images-5.jpeg?w=595" alt="Click to visit the original post" class="size-full" /></a>

<p>GCD helps improve your apps performance and responsiveness by outsourcing processes that require a lot or computing power to the background while keeping your UI responsive.  Normally you might want to do some heavy lifting.</p>
<p>Let's create an Empty Application.  You need to declare a IBOutlet UIImageView *imageView ivar in your appDelegate, make it a property and synthesize it in .m and make the connection in Interface Builder, IB.  </p>
</div> <p class="read-more"><a href="http://quique123.wordpress.com/2012/12/05/grandcentraldispatch-blocks/" target="_self"><span>Read more&hellip;</span> 524 more words</a></p></div></div><div class="reblogger-note"><div class='reblogger-note-content'>
GCD!
</div></div>]]></content:encoded>
			<wfw:commentRss>http://quique123.wordpress.com/2013/04/21/grandcentraldispatch-blocks-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/eca64ed04a39c23b1bb8f6267524c961?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marskoko</media:title>
		</media:content>
	</item>
		<item>
		<title>Cocos2d Tips: Design Game Objects for your game</title>
		<link>http://quique123.wordpress.com/2013/04/15/cocos2d-tips-design-game-objects-for-your-game/</link>
		<comments>http://quique123.wordpress.com/2013/04/15/cocos2d-tips-design-game-objects-for-your-game/#comments</comments>
		<pubDate>Mon, 15 Apr 2013 10:05:54 +0000</pubDate>
		<dc:creator>marskoko</dc:creator>
				<category><![CDATA[Cocos2d]]></category>
		<category><![CDATA[Iphone Developer]]></category>
		<category><![CDATA[Technological]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[cocos2d]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[subclasses]]></category>

		<guid isPermaLink="false">https://quique123.wordpress.com/?p=297</guid>
		<description><![CDATA[Keep your game classes organized and logically ordered. Create a GameObject class, a GameCharacter class and then subclass these. Its important to keep your Game Objects ordered as well as your code.  The more you order your objects, the cleaner your code will be as well.  A GameObject is anything used in a game from [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=297&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<div id="attachment_461" class="wp-caption aligncenter" style="width: 605px"><a href="http://quique123.files.wordpress.com/2013/02/gameobjecthierarchy.png"><img class="size-full wp-image-461" alt="GameObjectHierarchy" src="http://quique123.files.wordpress.com/2013/02/gameobjecthierarchy.png?w=595&#038;h=319" width="595" height="319" /></a><p class="wp-caption-text">GameObjectHierarchy</p></div>
<p>Keep your game classes organized and logically ordered. Create a GameObject class, a GameCharacter class and then subclass these.</p>
<p>Its important to keep your Game Objects ordered as well as your code.  The more you order your objects, the cleaner your code will be as well.  A GameObject is anything used in a game from labels to sprites to power ups.</p>
<p>Its important to create a base class for all objects because, as a simple example, you want to be able to constrain all game objects to your screen.  Its not unthinkable to believe that at some point you might inadvertently cause a game object to be pushed off screen.  Thus it would be nice to have a method, something like keepObjectInBounds, to make sure you can call it on any or all objects to make sure they are not halfway or all the way offscreen.</p>
<p>After you build you base class, GameObject, you will subclass it to build objects.  But you can also subclass GameObject to build functionally similar types of objects like a Powerups subclass or an Enemy subclass.  For example, you might want all Powerup class objects to have a setAutoDestroyTime method that gives any object of that class a specific time to live onscreen before it disappears.</p>
<p>So let&#8217;s look at init methods, designated initializers, self and super.</p>
<p>You can create a GameObject Class in 1 file set or in different file sets.  This is where self and super take hold in your brain.  Self means, that very same class you are currently in.  Super means its super or parent class.  For example, lets say we create this hierarchy:</p>
<ol>
<li><span style="color:#339966;">GameObject (Everything is a GameObject)</span>
<ol>
<li><span style="color:#339966;">GameCharacter (Distinguish between GameCharacters and GamePowerUps)</span>
<ol>
<li><span style="color:#339966;">GameEnemy (Some GameCharacters are bad and some are good)</span>
<ol>
<li><span style="color:#339966;">GameBigBossEnemy</span></li>
</ol>
</li>
<li><span style="color:#339966;">GamePlayer</span>
<ol>
<li><span style="color:#339966;">GamePlayerHero </span></li>
<li><span style="color:#339966;">GamePlayerFriend</span></li>
</ol>
</li>
</ol>
</li>
<li><span style="color:#339966;">GamePowerup</span></li>
</ol>
</li>
</ol>
<p>GameCharacter is a subclass of GameObject.  Which is to say, GameObject is the parent of GameCharacter.  This makes sense because your GameObjects may be characters that have a personality and animation and perform actions.  But some GameObjects will just sit there, like trees and clouds.  Clouds may be moved by wind and that is about it!  But a GamePlayer, our hero, needs to have a lot more internal logic, his own Artificial Intelligence logic if you will.</p>
<p>By the same token, GamePlayer may include our hero instance but it may also include a friend instance, which may be like his sidekick or something.  The logic for a friend will not include any methods to follow or attach our hero, whereas enemies will have to have that sort of logic.</p>
<p>This is the reason we subclass objects, in order to use a base functionality for all (all game objects must remain onscreen at all times) but give specific functionality to others (followMainPlayer method).</p>
<p>Lets say you&#8217;re inside GamePlayerHero and you are coding away.  If you say</p>
<blockquote><p>[self blowHisNose];</p></blockquote>
<p>You are calling the blowHisNose method which should exist in our GamePlayerHero class.  If it doesn&#8217;t exist in self, that object will look to its super for a corresponding method.  You don&#8217;t need to call:</p>
<blockquote><p>[super blowHisNose];</p></blockquote>
<p>That is what object inheritance in OOP is all about.  So if the method doesn&#8217;t exist in GamePlayerHero, the hero object looks to its parent class or super class, GamePlayer.  If GamePlayer doesn&#8217;t have that method then it will keep going until it finds that method.  If it doesn&#8217;t, your game will crash <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>So lets take a look at a practical example, an initializer.  An initializer is just another name for a Class&#8217; init method.  Every class must have an init method.  Here is a typical one:</p>
<blockquote><p>-(id) init {</p>
<p>if((self=[super init]);</p>
<p>}</p>
<p>return self;</p>
<p>}</p></blockquote>
<p>This means, if this class is equal to super&#8217;s init, then do this and return self.  Since a class will always have a super class, this basically says, if I have a super class (which is always) then return myself.</p>
<p>Now if a child class (lets call it GameCharacter class) of this previous class (GameObject class) wants to add functionality to its parent class, then it will NOT OVERRIDE its parent class methods, it will simply add methods.  So the new GameCharacter class could just have a method like this:</p>
<blockquote><p>-(void)checkAndClampSpritePosition {</p>
<p>CGPoint currentSpritePosition = [self position];</p>
<p>CGSize levelSize = [[GameManager sharedGameManager]</p>
<p>getDimensionsOfCurrentScene];</p>
<p>float xOffset;</p>
<p>if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {</p>
<p>// Clamp for the iPad</p>
<p>xOffset = 30.0f;</p>
<p>} else {</p>
<p>// Clamp for iPhone, iPhone 4, or iPod touch</p>
<p>xOffset = 24.0f;</p>
<p>}</p>
<p>if (currentSpritePosition.x &lt; xOffset) {</p>
<p>[self setPosition:ccp(xOffset, currentSpritePosition.y)];</p>
<p>} else if (currentSpritePosition.x &gt; (levelSize.width &#8211; xOffset)) {</p>
<p>[self setPosition:ccp((levelSize.width - xOffset),</p>
<p>currentSpritePosition.y)];</p>
<p>}</p>
<p>}</p></blockquote>
<p>Which says, Im not initializing anything (because if it does, it will erase its parent&#8217;s init method), Im just adding this method to any instance of GameCharacter AND every instance of GameCharacter will still have to be initialized from GameObject&#8217;s init.</p>
<p>Let&#8217;s see a more practical example.  Let&#8217;s look at an Enemy Class which can generate many different kinds of instances, all from the same code:</p>
<blockquote><p>@interface ShipTarget : CCSprite {</p>
<p>int _curHp;</p>
<p>int _minMoveDuration;</p>
<p>int _maxMoveDuration;</p>
<p>NSString *filename;</p>
<p>}</p>
<p>@property (nonatomic, assign) int hp;</p>
<p>@property (nonatomic, assign) int minMoveDuration;</p>
<p>@property (nonatomic, assign) int maxMoveDuration;</p>
<p>@property (nonatomic, retain) NSString *filename;</p>
<p>@end</p>
<p>@interface Asteroid : ShipTarget {</p>
<p>}</p>
<p>+(id)target;</p>
<p>@end</p></blockquote>
<p>This says, Im a ShipTarget class and my instances will all be based off of CCSprite.  This means all my instances will have any methods and properties of CCSprite unless I override them (create new ones).  At the same time, I wish to create an Asteroid class which derives from this ShipTarget class and it will return an object by calling its class method named target.  Then in its implementation you have:</p>
<blockquote><p>@implementation ShipTarget</p>
<p>@synthesize hp = _curHp;</p>
<p>@synthesize minMoveDuration = _minMoveDuration;</p>
<p>@synthesize maxMoveDuration = _maxMoveDuration;</p>
<p>@synthesize filename;</p>
<p>@end</p>
<p>@implementation Asteroid</p>
<p>+ (id)target {</p>
<p>Asteroid *target = nil;</p>
<p>if ((target = [[[super alloc] initWithFile:@&#8221;Comet.png&#8221;] autorelease])) {</p>
<p>target.hp = 1;</p>
<p>target.minMoveDuration = 2;</p>
<p>target.maxMoveDuration = 4;</p>
<p>}</p>
<p>return target;</p>
<p>}</p>
<p>@end</p></blockquote>
<p>Notice again, the use of self, or target.  If there is such a thing returned from calling target&#8217;s super class, (target is ShipTarget class and ShipTarget&#8217;s super class is CCSprite) initWithFile&#8230; then set those properties and return it.  There is such a thing as target&#8217;s super class initWithFile method.  CCSprite has an initWithFile method.  Don&#8217;t believe me?  Then don&#8217;t, right click over initWithFile and select Jump to Definition and watch Xcode take you to CCSprite:</p>
<p>-(id) initWithFile:(NSString*)filename</p>
<div> So we set the properties hp, min and maxMoveDuration.  Even though those properties don&#8217;t exist in CCSprite, they exist in the new subclass, ShipTarget.  We added them ourselves in the interface and later synthesized them in the implementation file.  Since target is of Asteroid class (which is itself type of ShipTarget), it therefore must have ShipTarget properties hp, min and maxMoveDuration.  This also means that any ShipTarget target we create, will have those 3 properties and we can set it.</div>
<div></div>
<div>This is very handy when creating the different GameObjects we discussed because they can all be based on a set of properties common to all enemies, or to all players, or to all powerups etc.  This saves you time when creating subclasses because you don&#8217;t have to create repetitive code for each object type.  And more importantly, it keeps your code tidy because if you need to add a property to all enemies, you simply add it to ShipTarget and voila&#8230;all your enemy targets will now have that property for you to assign.</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/quique123.wordpress.com/297/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/quique123.wordpress.com/297/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=297&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://quique123.wordpress.com/2013/04/15/cocos2d-tips-design-game-objects-for-your-game/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/eca64ed04a39c23b1bb8f6267524c961?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marskoko</media:title>
		</media:content>

		<media:content url="http://quique123.files.wordpress.com/2013/02/gameobjecthierarchy.png" medium="image">
			<media:title type="html">GameObjectHierarchy</media:title>
		</media:content>
	</item>
		<item>
		<title>Cocos2d Tips: Scrolling, Parallax and wider levels</title>
		<link>http://quique123.wordpress.com/2013/03/21/cocos2d-tips-scrolling-parallax-and-wider-levels/</link>
		<comments>http://quique123.wordpress.com/2013/03/21/cocos2d-tips-scrolling-parallax-and-wider-levels/#comments</comments>
		<pubDate>Thu, 21 Mar 2013 04:09:04 +0000</pubDate>
		<dc:creator>marskoko</dc:creator>
				<category><![CDATA[Cocos2d]]></category>
		<category><![CDATA[cocos2d]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[level]]></category>
		<category><![CDATA[parallax]]></category>
		<category><![CDATA[scrolling]]></category>
		<category><![CDATA[wide]]></category>

		<guid isPermaLink="false">https://quique123.wordpress.com/?p=301</guid>
		<description><![CDATA[Wider Levels &#38; Scrolling When you create a game in Cocos2d, your screen measures 960 pixels wide on iPhone4+ and 2048 on iPad. If we want him to move farther to the right then we need to make the level bigger.  Normally we set: levelSize = screenSize; But now we basically wish to make: levelSize [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=301&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<h1>Wider Levels &amp; Scrolling</h1>
<p>When you create a game in Cocos2d, your screen measures 960 pixels wide on iPhone4+ and 2048 on iPad. If we want him to move farther to the right then we need to make the level bigger.  Normally we set:</p>
<p>levelSize = screenSize;</p>
<p>But now we basically wish to make:</p>
<p>levelSize = CGSizeMake(screenSize.width * 2.0f, screenSize.height); // levelSize code</p>
<p>What we are doing is changing our scene levelSize to 2x the screenSize.</p>
<p>Our level is now twice as big and we have a GameScene, which contains a GameplayLayer &amp; a BackgroundLayer with some background image.  We want to add a layer that will scroll in the opposite direction as our player moves.  To do this we will need to add a method a method called adjustLayer:</p>
<blockquote><p>-(void)adjustLayer {</p>
<p>Player *player = (Player*)[sceneSpriteBatchNode getChildByTag:kPlayerSpriteTagValue];</p>
<p>float playerXPosition = player.position.x;</p>
<p>CGSize screenSize = [[CCDirector sharedDirector] winSize];</p>
<p>float halfOfTheScreen = screenSize.width/2.0f;</p>
<p>CGSize levelSize = [[GameManager sharedGameManager] getDimensionsOfCurrentScene];//1</p>
<p>if ((playerXPosition &gt; halfOfTheScreen) &amp;&amp; (playerXPosition &lt; (levelSize.width &#8211; halfOfTheScreen))) {</p>
<p>// then scroll background</p>
<p>float newXPosition = halfOfTheScreen &#8211; playerXPosition;</p>
<p>[self setPosition:ccp(newXPosition,self.position.y)];      // 2 self is the game layer</p>
<p>}</p>
<p>}</p></blockquote>
<p>Here comment //1 is a call to a method which returns the desired levelSize.  Or you can simply hard code it in this case by replacing this line with the //levelSize code line from above.  Remember we are running this method in the GameplayLayer, which is self in this code.  This needs to be called constantly so you must add this line to your update layer.  What we are doing here is keeping the screen centered on the player.  Now in the update method add this code:</p>
<blockquote><p>//1. Get the list of objects on the layer &amp; loop through them</p>
<p>CCArray *listOfGameObjects = [sceneSpriteBatchNode children];</p>
<p>for (GameCharacter *tempChar in listOfGameObjects) {</p>
<p>[tempChar updateStateWithDeltaTime:dt andListOfGameObjects:listOfGameObjects];</p>
<p>}</p>
<p>//2. Call the adjustLayer method</p>
<p>[self adjustLayer];</p>
<p>Perfect!  Now let’s add the image that is actually going to scroll.  Add this method to your GameplayLayer.m:</p>
<p>-(void)addScrollingBackground {</p>
<p>CGSize screenSize = [[CCDirector sharedDirector] winSize];</p>
<p>CGSize levelSize = [[GameManager sharedGameManager] getDimensionsOfCurrentScene];</p>
<p>CCSprite *scrollingBackground;</p>
<p>if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {</p>
<p>// Indicates game is running on iPad</p>
<p>scrollingBackground = [CCSprite spriteWithFile:@"mars_landscape2x.png"];</p>
<p>} else {</p>
<p>scrollingBackground = [CCSprite spriteWithFile:@"mars_landscape2x.png"];</p>
<p>}</p>
<p>[scrollingBackground setPosition:ccp(levelSize.width/2.0f,screenSize.height/2.0f)];</p>
<p>[self addChild:scrollingBackground z:1];</p>
<p>}</p></blockquote>
<p>In order for this to appear, we need to call it from the init method by adding this line:</p>
<p>[self addScrollingBackground];</p>
<p>Let’s review.  addScrollingBackground adds a new image to the GameplayLayer.  (This image is positioned over the true background, which is in the BackgroundLayer.)  Therefore, the new image you add here should be a sort of rocky ground floor that will slide sideways as the player moves.</p>
<p>Make sure the image is twice as big as the screen so there will be enough of it to scroll through as the player moves.</p>
<p>Now Build &amp; Run and watch your ground scroll differently as your background as your player moves left or right.</p>
<h1>Parallax</h1>
<p>Parallax makes one layer scroll faster or slower than the other.  It’s quite easy to achieve this effect.  First add a new instance variable to your GameplayLayer.m file like so:</p>
<blockquote><p>@implementation GameplayLayer {</p>
<p>CCParallaxNode *parallaxNode;</p>
<p>}</p></blockquote>
<p>NOTE: We are extending the @implementation line to include an ivar.  No need to declare it in the @interface file.  Remember .h files (header files) only need to include what properties or methods you want your object to expose to other calling objects.</p>
<p>And now replace your addScrollingBackground method with this one:</p>
<blockquote><p>// Scrolling 3 Parallax backgrounds</p>
<p>-(void)addScrollingBackgroundWithParallax {</p>
<p>CGSize screenSize = [[CCDirector sharedDirector] winSize];</p>
<p>CGSize levelSize = [[GameManager sharedGameManager]</p>
<p>getDimensionsOfCurrentScene];</p>
<p>CCSprite *BGLayer1;</p>
<p>CCSprite *BGLayer2;</p>
<p>CCSprite *BGLayer3;</p>
<p>if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {</p>
<p>// Indicates game is running on iPad</p>
<p>BGLayer1 = [CCSprite spriteWithFile:@"mars_landscape2x.png"];</p>
<p>BGLayer2 = [CCSprite spriteWithFile:@"some_rocks.png"];</p>
<p>BGLayer3 = [CCSprite spriteWithFile:@"some_pillars.png"];</p>
<p>} else {</p>
<p>BGLayer1 = [CCSprite spriteWithFile:@" mars_landscape2x.png"];</p>
<p>BGLayer2 = [CCSprite spriteWithFile:@" some_rocks.png"];</p>
<p>BGLayer3 = [CCSprite spriteWithFile:@" some_pillars.png"];</p>
<p>}</p>
<p>parallaxNode = [CCParallaxNode node];</p>
<p>[parallaxNode setPosition:ccp(levelSize.width/2.0f,screenSize.height/2.0f)];</p>
<p>float xOffset = 0;</p>
<p>// Ground moves at ratio 1,1</p>
<p>[parallaxNode addChild:BGLayer1 z:40 parallaxRatio:ccp(1.0f,1.0f) positionOffset:ccp(0.0f,0.0f)];</p>
<p>xOffset = (levelSize.width/2) * 0.3f;</p>
<p>[parallaxNode addChild:BGLayer2 z:20 parallaxRatio:ccp(0.2f,1.0f) positionOffset:ccp(xOffset, 0)];</p>
<p>xOffset = (levelSize.width/2) * 0.8f;</p>
<p>[parallaxNode addChild:BGLayer3 z:30 parallaxRatio:ccp(0.7f,1.0f) positionOffset:ccp(xOffset, 0)];</p>
<p>[self addChild:parallaxNode z:10];</p>
<p>}</p></blockquote>
<p>Don’t forget to change the GameplayLayer’s init method call to:</p>
<blockquote><p>[self addScrollingBackgroundWithParallax];</p></blockquote>
<p>What we are doing now is adding more layers and offsetting their center positions.  Thus when they move, they will move at different rates.  Build &amp; run the app.</p>
<p>You can use scrolling to add clouds or stars or alien birds to make some eyecandy for your users.  If you choose to scroll many objects on the screen though, you might want to look into reusing them.  This is a very popular technique used to improve performance of a game.  You create one instance of the object at a time and add it to an array for tracking.  When that instance moves offscreen, you remove it from that array.  This saves you a lot of memory.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/quique123.wordpress.com/301/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/quique123.wordpress.com/301/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=301&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://quique123.wordpress.com/2013/03/21/cocos2d-tips-scrolling-parallax-and-wider-levels/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/eca64ed04a39c23b1bb8f6267524c961?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marskoko</media:title>
		</media:content>
	</item>
		<item>
		<title>How Cocos2d taught me iOS and OOP</title>
		<link>http://quique123.wordpress.com/2013/03/13/how-cocos2d-taught-me-ios-and-oop/</link>
		<comments>http://quique123.wordpress.com/2013/03/13/how-cocos2d-taught-me-ios-and-oop/#comments</comments>
		<pubDate>Wed, 13 Mar 2013 03:30:45 +0000</pubDate>
		<dc:creator>marskoko</dc:creator>
				<category><![CDATA[Iphone Developer]]></category>

		<guid isPermaLink="false">http://quique123.wordpress.com/?p=445</guid>
		<description><![CDATA[I started studying iOS in 2009, started studying Cocos2d in 2011.  I never understood how to do things in code for iOS.   It was all a big mystery to me. What do you mean create a button programmatically and add it to the subview and position it and change its attributes?  I can just [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=445&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><div id="attachment_446" class="wp-caption aligncenter" style="width: 605px"><a href="http://quique123.files.wordpress.com/2013/03/cocosios.jpg"><img class="size-full wp-image-446" alt="How Cocos2d taught me iOS" src="http://quique123.files.wordpress.com/2013/03/cocosios.jpg?w=595&#038;h=595" width="595" height="595" /></a><p class="wp-caption-text">How Cocos2d taught me iOS</p></div>
<p>I started studying iOS in 2009, started studying Cocos2d in 2011.  I never understood how to do things in code for iOS.   It was all a big mystery to me.</p>
<p>What do you mean create a button programmatically and add it to the subview and position it and change its attributes?  I can just drag one from the Object Library onto the canvas and put it wherever I want and change its color etc&#8230;</p>
<p>After a year of using Cocos2d, I know cherish its teachings as I find myself trying to make an app which requires objects such as UIPageControl and UIScrollView and UIImageViews with UIImages.  In doing this you run into the situation of:</p>
<p>How do I position a view, or rather a bunch of UIImageViews that are not on the canvas but will be when the UIPageControl&#8217;s value changes!?</p>
<p>EPIPHANY!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/quique123.wordpress.com/445/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/quique123.wordpress.com/445/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=445&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://quique123.wordpress.com/2013/03/13/how-cocos2d-taught-me-ios-and-oop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/eca64ed04a39c23b1bb8f6267524c961?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marskoko</media:title>
		</media:content>

		<media:content url="http://quique123.files.wordpress.com/2013/03/cocosios.jpg" medium="image">
			<media:title type="html">How Cocos2d taught me iOS</media:title>
		</media:content>
	</item>
		<item>
		<title>Cool Image Transparency Gradient Effect</title>
		<link>http://quique123.wordpress.com/2013/03/02/cool-image-transparency-gradient-effect/</link>
		<comments>http://quique123.wordpress.com/2013/03/02/cool-image-transparency-gradient-effect/#comments</comments>
		<pubDate>Sat, 02 Mar 2013 17:43:29 +0000</pubDate>
		<dc:creator>marskoko</dc:creator>
				<category><![CDATA[AV Edits]]></category>
		<category><![CDATA[gradient]]></category>
		<category><![CDATA[pixelmator]]></category>
		<category><![CDATA[transparency]]></category>

		<guid isPermaLink="false">http://quique123.wordpress.com/?p=428</guid>
		<description><![CDATA[So the other day I was trying to figure out how to do something in Pixelmator (Im pretty sure it works for Photoshop) and I accidentally stumbled into this effect. First, I opened up an image that I wanted to spruce up. Second, I Added a Layer Mask in the Layer Menu Then, I used [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=428&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>So the other day I was trying to figure out how to do something in Pixelmator (Im pretty sure it works for Photoshop) and I accidentally stumbled into this effect.</p>
<p>First, I opened up an image that I wanted to spruce up.</p>
<p>Second, I Added a Layer Mask in the Layer Menu</p>
<p>Then, I used a Transparent to Black Gradient and got this:</p>
<div id="attachment_429" class="wp-caption aligncenter" style="width: 605px"><a href="http://quique123.files.wordpress.com/2013/03/result.png"><img class="size-full wp-image-429" alt="Gradient Transparency" src="http://quique123.files.wordpress.com/2013/03/result.png?w=595&#038;h=518" width="595" height="518" /></a><p class="wp-caption-text">Gradient Transparency</p></div>
<p>&nbsp;</p>
<p>Why is this cool?  Well, now you can add a nice background color or even another image in the background to make some very professional looking artwork! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
<div id="attachment_430" class="wp-caption aligncenter" style="width: 605px"><a href="http://quique123.files.wordpress.com/2013/03/resultfinal.png"><img class="size-full wp-image-430" alt="Transparency Gradient" src="http://quique123.files.wordpress.com/2013/03/resultfinal.png?w=595&#038;h=532" width="595" height="532" /></a><p class="wp-caption-text">Transparency Gradient</p></div>
<p>&nbsp;</p>
<p>The original idea I was after was from a tutorial I found online which took a picture, such as this one.  You take a picture such as this:</p>
<p><a href="http://quique123.files.wordpress.com/2013/03/beyonce_smile_face_lips_hair_5905_1920x1080.jpg"><img class="aligncenter size-full wp-image-431" alt="beyonce_smile_face_lips_hair_5905_1920x1080" src="http://quique123.files.wordpress.com/2013/03/beyonce_smile_face_lips_hair_5905_1920x1080.jpg?w=595&#038;h=334" width="595" height="334" /></a></p>
<p>&nbsp;</p>
<p>Add a Layer Mask as before but this time choose Brush 100 with a black foreground color.  Eliminate everything around her by painting with the brush to get this:</p>
<p><a href="http://quique123.files.wordpress.com/2013/03/screen-shot-2013-03-02-at-11-40-03-am.png"><img class="aligncenter size-full wp-image-435" alt="Screen Shot 2013-03-02 at 11.40.03 AM" src="http://quique123.files.wordpress.com/2013/03/screen-shot-2013-03-02-at-11-40-03-am.png?w=595&#038;h=334" width="595" height="334" /></a></p>
<p>Cute huh!</p>
<p>Now create a new layer and Add a Gradient, preferrably one with 2 pastel colors and move it over this one:</p>
<p>Finally change Blending to Screen and voila!</p>
<p><a href="http://quique123.files.wordpress.com/2013/03/screen-shot-2013-03-02-at-11-42-23-am.png"><img class="aligncenter size-full wp-image-436" alt="Screen Shot 2013-03-02 at 11.42.23 AM" src="http://quique123.files.wordpress.com/2013/03/screen-shot-2013-03-02-at-11-42-23-am.png?w=595&#038;h=334" width="595" height="334" /></a></p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/quique123.wordpress.com/428/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/quique123.wordpress.com/428/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=428&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://quique123.wordpress.com/2013/03/02/cool-image-transparency-gradient-effect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/eca64ed04a39c23b1bb8f6267524c961?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marskoko</media:title>
		</media:content>

		<media:content url="http://quique123.files.wordpress.com/2013/03/result.png" medium="image">
			<media:title type="html">Gradient Transparency</media:title>
		</media:content>

		<media:content url="http://quique123.files.wordpress.com/2013/03/resultfinal.png" medium="image">
			<media:title type="html">Transparency Gradient</media:title>
		</media:content>

		<media:content url="http://quique123.files.wordpress.com/2013/03/beyonce_smile_face_lips_hair_5905_1920x1080.jpg" medium="image">
			<media:title type="html">beyonce_smile_face_lips_hair_5905_1920x1080</media:title>
		</media:content>

		<media:content url="http://quique123.files.wordpress.com/2013/03/screen-shot-2013-03-02-at-11-40-03-am.png" medium="image">
			<media:title type="html">Screen Shot 2013-03-02 at 11.40.03 AM</media:title>
		</media:content>

		<media:content url="http://quique123.files.wordpress.com/2013/03/screen-shot-2013-03-02-at-11-42-23-am.png" medium="image">
			<media:title type="html">Screen Shot 2013-03-02 at 11.42.23 AM</media:title>
		</media:content>
	</item>
		<item>
		<title>Give a man an app … but teach a man to c</title>
		<link>http://quique123.wordpress.com/2013/02/26/give-a-man-an-app-but-teach-a-man-to-c/</link>
		<comments>http://quique123.wordpress.com/2013/02/26/give-a-man-an-app-but-teach-a-man-to-c/#comments</comments>
		<pubDate>Tue, 26 Feb 2013 20:50:40 +0000</pubDate>
		<dc:creator>marskoko</dc:creator>
				<category><![CDATA[Iphone Developer]]></category>

		<guid isPermaLink="false">http://quique123.wordpress.com/2013/02/26/give-a-man-an-app-but-teach-a-man-to-c/</guid>
		<description><![CDATA[Give a man an app … but teach a man to code … #iOS #ObjC http://ow.ly/i4FbH<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=427&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Give a man an app … but teach a man to code … #iOS #ObjC <a href="http://ow.ly/i4FbH" rel="nofollow">http://ow.ly/i4FbH</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/quique123.wordpress.com/427/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/quique123.wordpress.com/427/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=427&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://quique123.wordpress.com/2013/02/26/give-a-man-an-app-but-teach-a-man-to-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/eca64ed04a39c23b1bb8f6267524c961?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marskoko</media:title>
		</media:content>
	</item>
		<item>
		<title>Cocos2d Tips: Transitioning between game screens</title>
		<link>http://quique123.wordpress.com/2013/02/03/cocos2d-tips-transitioning-between-game-screens/</link>
		<comments>http://quique123.wordpress.com/2013/02/03/cocos2d-tips-transitioning-between-game-screens/#comments</comments>
		<pubDate>Sun, 03 Feb 2013 10:00:16 +0000</pubDate>
		<dc:creator>marskoko</dc:creator>
				<category><![CDATA[Cocos2d]]></category>
		<category><![CDATA[cocos2d]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[scenes]]></category>

		<guid isPermaLink="false">https://quique123.wordpress.com/?p=287</guid>
		<description><![CDATA[Let&#8217;s learn how to create menu for a cocos2d game and how to move between a menu, the game scene, a level complete scene etc. Eventually your game will grow and you will have to create a clear structure to keep everything organized. As you can see, as with any app, the AppDelegate is the [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=287&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Let&#8217;s learn how to create menu for a cocos2d game and how to move between a menu, the game scene, a level complete scene etc.</p>
<p>Eventually your game will grow and you will have to create a clear structure to keep everything organized.</p>
<p style="text-align:center;"><a href="http://quique123.files.wordpress.com/2012/09/20120911-203055.jpg"><img class="size-full aligncenter" alt="20120911-203055.jpg" src="http://quique123.files.wordpress.com/2012/09/20120911-203055.jpg?w=595"   /></a></p>
<p>As you can see, as with any app, the AppDelegate is the first object called. As such, it is the entry point to your game and will call the very first scene of your game. This means the first scene should probably the main menu which welcomes the user to the game and presents him with options.</p>
<p>As you can see from the Cocos2d tips &#8220;Creating a Menu&#8221;, menus can be quite complex:</p>
<p><a href="http://quique123.wordpress.com/2012/09/12/cocos2d-tips-creating-a-menu/ ‎" rel="nofollow">http://quique123.wordpress.com/2012/09/12/cocos2d-tips-creating-a-menu/ ‎</a></p>
<p>When a cocos2d game is created, a Singleton instance of the GameDirector is instantiated and charged with managing scenes. After all, your Main Menu scene is just another scene/layer called by the game director. Thus it is quite common to create another Singleton class used to tell the director which scene to call.</p>
<p>Let&#8217;s call it the GameManager and his sole job is to tell the director which scene to call. Before we take a look at some code, keep in mind a game may grow to have quite a few scenes and while text is more human readable, it is easier to manage variables as numbers. The main reason is that switch statements use numbers, not text.</p>
<p>So it is common practice to use code such as this in a Constants.h file that you import into your GameManager.m Class:</p>
<blockquote>
<p style="padding-left:30px;">typedef enum {</p>
<p style="padding-left:30px;">kNoSceneUninitialized=0,</p>
<p style="padding-left:30px;">kFirstScene=1,</p>
<p style="padding-left:30px;">kSecondScene=2,</p>
<p style="padding-left:30px;">kThirdScene=3,</p>
<p style="padding-left:30px;">} SceneTypes;</p>
<p style="padding-left:30px;">Now you can easily use a method such as this:</p>
<p style="padding-left:30px;">-(void)runSceneWithID:(SceneTypes)sceneID {</p>
<p style="padding-left:30px;">SceneTypes oldScene = currentScene;</p>
<p style="padding-left:30px;">currentScene = sceneID;</p>
<p style="padding-left:30px;">id sceneToRun = nil;</p>
<p style="padding-left:30px;">switch (sceneID) {</p>
<p style="padding-left:30px;">case kMainMenuScene:</p>
<p style="padding-left:30px;">sceneToRun = [MainMenuScene node];</p>
<p style="padding-left:30px;">break;</p>
<p style="padding-left:30px;">case kFirstScene:</p>
<p style="padding-left:30px;">sceneToRun = [Scene1 node];</p>
<p style="padding-left:30px;">break;</p>
<p style="padding-left:30px;">case kSecondScene:</p>
<p style="padding-left:30px;">sceneToRun = [PlaneScene node];//[Escena2 node];//</p>
<p style="padding-left:30px;">break;</p>
<p style="padding-left:30px;">case kThirdScene:</p>
<p style="padding-left:30px;">sceneToRun = [Scene3 node];</p>
<p style="padding-left:30px;">break;</p>
<p style="padding-left:30px;">default:</p>
<p style="padding-left:30px;">CCLOG(@&#8221;Unknown ID, cannot switch scenes&#8221;);</p>
<p style="padding-left:30px;">return;</p>
<p style="padding-left:30px;">break;</p>
<p style="padding-left:30px;">}</p>
<p style="padding-left:30px;">if (sceneToRun == nil) {</p>
<p style="padding-left:30px;">// Revert back, since no new scene was found</p>
<p style="padding-left:30px;">currentScene = oldScene;</p>
<p style="padding-left:30px;">return;</p>
<p style="padding-left:30px;">}</p>
<p style="padding-left:30px;">}</p>
<p style="padding-left:30px;">if ([[CCDirector sharedDirector] runningScene] == nil) {</p>
<p style="padding-left:30px;">NSLog(@&#8221;runningScene is nil&#8230;its ok because we are in process of setting the new scene???&#8221;);</p>
<p style="padding-left:30px;">[[CCDirector sharedDirector] runWithScene:sceneToRun];</p>
<p style="padding-left:30px;">} else {</p>
<p style="padding-left:30px;">[[CCDirector sharedDirector] replaceScene:[CCTransitionFlipAngular transitionWithDuration:0.5f scene:sceneToRun]];</p>
<p style="padding-left:30px;">}</p>
<p style="padding-left:30px;">currentScene = sceneID;</p>
<p style="padding-left:30px;">}</p>
</blockquote>
<p>GAME START</p>
<p>Now this simple switch can be used to change scenes.  All you have to do at the end of the AppDelegate is call GameManager&#8217;s sceneToRun method and pass it the MainMenuScene.</p>
<p>MAIN MENU SELECTION</p>
<p>At the Main Menu scene, depending on the level selected from the menu you can pass a particular scene constant to GameManager in order to determine the level scene to call.</p>
<p>LEVEL END</p>
<p>From within your game level layer, after defining if your player won or lost, you can call GameManager to run a custom EndOfLevel scene/layer.  Then from that transitional scene you can call the MainMenuScene again.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/quique123.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/quique123.wordpress.com/287/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=287&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://quique123.wordpress.com/2013/02/03/cocos2d-tips-transitioning-between-game-screens/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/eca64ed04a39c23b1bb8f6267524c961?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marskoko</media:title>
		</media:content>

		<media:content url="http://quique123.files.wordpress.com/2012/09/20120911-203055.jpg" medium="image">
			<media:title type="html">20120911-203055.jpg</media:title>
		</media:content>
	</item>
		<item>
		<title>Cocos2d Tips: Connect Layers</title>
		<link>http://quique123.wordpress.com/2013/01/15/cocos2d-tips-connect-layers-needs-content/</link>
		<comments>http://quique123.wordpress.com/2013/01/15/cocos2d-tips-connect-layers-needs-content/#comments</comments>
		<pubDate>Tue, 15 Jan 2013 09:48:54 +0000</pubDate>
		<dc:creator>marskoko</dc:creator>
				<category><![CDATA[Cocos2d]]></category>
		<category><![CDATA[cocos2d]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[layer]]></category>
		<category><![CDATA[pass data]]></category>

		<guid isPermaLink="false">https://quique123.wordpress.com/?p=283</guid>
		<description><![CDATA[Games have many layers. The most common example is the main action layer (where the players and enemies are) having to communicate with the HUD layer (which presents score, health and other info) to the gamer. Let&#8217;s see how we can communicate between layers. Typically you create a Scene and then a Layer in order [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=283&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<h1 style="text-align:center;"><span style="text-decoration:underline;"><strong>Games have many layers. </strong></span></h1>
<h1 style="text-align:center;"><a href="http://quique123.files.wordpress.com/2013/03/layers.png"><img class="aligncenter size-full wp-image-410" alt="layers" src="http://quique123.files.wordpress.com/2013/03/layers.png?w=595"   /></a></h1>
<p>The most common example is the main action layer (where the players and enemies are) having to communicate with the HUD layer (which presents score, health and other info) to the gamer. Let&#8217;s see how we can communicate between layers.</p>
<p>Typically you create a Scene and then a Layer in order to add that Layer as a child to the Scene.</p>
<p>Let&#8217;s say our Scene.h looks like this:</p>
<blockquote><p>#import &lt;Foundation/Foundation.h&gt;</p>
<p>#import &#8220;cocos2d.h&#8221;</p>
<p>@interface Scene1 : CCScene {</p>
<p>}</p>
<p>@end</p></blockquote>
<p>And our Scene.m looks like this:</p>
<blockquote><p>-(id)init {</p>
<p>if ((self = [super init])) {</p>
<p>Scene1ActionLayer * actionLayer = [[[Scene1ActionLayer alloc] init] autorelease];</p>
<p>[self addChild:actionLayer z:0 tag:kActionLayer];</p>
<p>}</p>
<p>return self;</p>
<p>}</p></blockquote>
<p>So we are adding the main action layer, actionLayer, to our scene at z=0 with a tag kActionLayer.  Simple enough.  Now let&#8217;s say we want to create a HUD layer to contain game information.  This can range from points, to level information, to instructions or simply health or powerup information.</p>
<p>Im not much of a designed so I created this simple rectangle as a bottom bar for my game.</p>
<p><a href="http://quique123.files.wordpress.com/2013/03/hudbar.png"><img class="aligncenter size-full wp-image-409" alt="HUDbar" src="http://quique123.files.wordpress.com/2013/03/hudbar.png?w=595"   /></a></p>
<p>The idea here is that those stars will actually represent the powerups a player must collect in order to complete a level.  Thus this will actually be a silhouette and each time the player picks up a power up, the HUD gets updated to place the powerup image in that space.  So we need the actionLayer to communicate with the HUD layer in order to say &#8220;Update the BIG GUNS power up!&#8221;.</p>
<p>We go ahead and create the actionLayer, possibly with a method called updateHUDWithPowerup:(Powerup*)power up; where Powerup is anything as simple as a typedef or as complex as a custom NSObject.</p>
<p>First, we need an instance of the HUD layer inside our actionLayer to call its method.  So inside our actionLayer, we forward declare it in our action layer :</p>
<blockquote><p>@class &#8220;HUDLayer;</p></blockquote>
<p>and then create an ivar for its instance:</p>
<blockquote><p>HUDLayer *hudLayerInstance;</p></blockquote>
<p>Second, we import the class in our action layer.m:</p>
<blockquote><p>#import &#8220;HUDLayer.h&#8221;</p></blockquote>
<p>Third, we simply allocate the instance in our actionLayer&#8217;s init method:</p>
<blockquote><p>hudLayerInstance = [[HUDLayer alloc] initWithActionLayer:self];</p>
<p>[self addChild:backLayer z:0 tag:100];</p></blockquote>
<p>Fourth, when the time comes to update the HUDLayer from the action layer&#8217;s update method (perhaps), we call:</p>
<blockquote><p>[hudLayerInstance someMethodDefinedInHUDLayer:withThisValue];</p></blockquote>
<p>Fifth, don&#8217;t forget to code the HUDLayer.  In its interface, forward declare your action layer class and add the custom initializer as well as your method like so:</p>
<blockquote><p>@class ActionLayer;</p>
<p>@interface HUDLayer : CCLayer {</p>
<p>CCLabelTTF *_scoreLabel;</p>
<p>}</p>
<p>@property (nonatomic, assign) CCLabelTTF *scoreLabel;</p>
<p>-(id)initWithActionLayer:(ActionLayer*)layer;</p>
<p>@end</p></blockquote>
<p>Finally implement your initializer and its &#8220;someMethodDefinedInHUDLayer&#8221; in order to pass it &#8220;withThisValue&#8221;.</p>
<p>Voila!  Another option is using Delegates/Protocols.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>In this case we are adding all children to the Scene.  In order to get them to communicate, we would need to have methods inside the Scene itself to call actions between objects.  I prefer the former method.  I leave this kind of setup for adding layers that don&#8217;t really do much, such as timers, background, eye candy etc.  They are still important layers, they just dont interact with the actionLayer much or at all.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/quique123.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/quique123.wordpress.com/283/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=283&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://quique123.wordpress.com/2013/01/15/cocos2d-tips-connect-layers-needs-content/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/eca64ed04a39c23b1bb8f6267524c961?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marskoko</media:title>
		</media:content>

		<media:content url="http://quique123.files.wordpress.com/2013/03/layers.png" medium="image">
			<media:title type="html">layers</media:title>
		</media:content>

		<media:content url="http://quique123.files.wordpress.com/2013/03/hudbar.png" medium="image">
			<media:title type="html">HUDbar</media:title>
		</media:content>
	</item>
		<item>
		<title>NSOperationQueue &amp; NSInvocationOperation</title>
		<link>http://quique123.wordpress.com/2013/01/15/nsoperationqueue-nsinvocationoperation/</link>
		<comments>http://quique123.wordpress.com/2013/01/15/nsoperationqueue-nsinvocationoperation/#comments</comments>
		<pubDate>Tue, 15 Jan 2013 09:26:41 +0000</pubDate>
		<dc:creator>marskoko</dc:creator>
				<category><![CDATA[Iphone Developer]]></category>
		<category><![CDATA[Technological]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[main thread]]></category>
		<category><![CDATA[NSInvocationOperation]]></category>
		<category><![CDATA[NSOperationQueue]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://quique123.wordpress.com/?p=219</guid>
		<description><![CDATA[1. In your main class&#8217; init method call this: operationQueue = [[NSOperationQueue alloc]init]; [operationQueue setMaxConcurrentOperationCount:1]; 2. Then in your viewWillAppear you can call this: [self showLoadingIndicators]; //calls a method which presents loading indicators (optional) [self beginLoadingTwitterData]; // this is the method that fires it all off 3. In your beginLoadingTwitterData you call this: NSInvocationOperation *operation [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=219&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>1. In your main class&#8217; init method call this:</p>
<p>operationQueue = [[NSOperationQueue alloc]init];<br />
[operationQueue setMaxConcurrentOperationCount:1];</p>
<p>2. Then in your viewWillAppear you can call this:</p>
<p>[self showLoadingIndicators]; //calls a method which presents loading indicators (optional)<br />
[self beginLoadingTwitterData]; // this is the method that fires it all off</p>
<p>3. In your beginLoadingTwitterData you call this:</p>
<p>NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(synchronousLoadTwitterData) object:nil];<br />
[operationQueue addOperation:operation]; // creates and adds NSOperation to a queue<br />
[operation release];</p>
<p>4. In this synchronousLoadTwitterData is where you do the heavy lifting:</p>
<p>NSDictionary *dict = [[NSDictionary alloc] initWithDictionary:[TwitterHelper fetchInfoForUsername:[twitterIds objectAtIndex:count]]]<br />
// this calls for a method &#8220;fetchInfoForUsername&#8221; which returns an NSDictionary, but to do so, it connects to the internet using a synchronous URL fetch which would normally hold up the main thread</p>
<p>Later in this method you call:</p>
<p>[self performSelectorOnMainThread:@selector(didFinishLoadingTwitterDataWithResults:) withObject:tempArray waitUntilDone:YES];<br />
//which returns you to the main thread at said selector&#8230;</p>
<p>5. In this final method, didFinishLoadingTwitterDataWithResults, which gets called once the operation finishes, you call:</p>
<p>self.persons = (NSArray*)result;<br />
[self hideLoadingIndicators];<br />
[self.tableView reloadData];<br />
//and you can do other things like, receive the results, hide the indicators and reload a tableview.</p>
<p>This is very useful when downloading data from the web.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/quique123.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/quique123.wordpress.com/219/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=quique123.wordpress.com&#038;blog=8793658&#038;post=219&#038;subd=quique123&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://quique123.wordpress.com/2013/01/15/nsoperationqueue-nsinvocationoperation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/eca64ed04a39c23b1bb8f6267524c961?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">marskoko</media:title>
		</media:content>
	</item>
	</channel>
</rss>
