<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>cocos2d for iPhone &#187; Tag: singleton - Recent Topics</title>
		<link>http://www.cocos2d-iphone.org/forum/tags/singleton</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 04:14:06 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://www.cocos2d-iphone.org/forum/search.php</link>
		</textInput>
		<atom:link href="http://www.cocos2d-iphone.org/forum/rss/tags/singleton/topics" rel="self" type="application/rss+xml" />

		<item>
			<title>Duckwit on "[?]Class A imports B, B needs to import A too..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/29119#post-143466</link>
			<pubDate>Thu, 09 Feb 2012 16:50:53 +0000</pubDate>
			<dc:creator>Duckwit</dc:creator>
			<guid isPermaLink="false">143466@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>This is one of those stupid technical problem that I should be able to solve by now, but being bogged down by work and struggling to find programming time I can't seem to figure this out. </p>
<p>Class A is a singleton, it receives input from the user interface using Interface Builder.<br />
Class B is a CCLayer subclass (HelloWorldLayer)</p>
<p>B needs to know about a to send it some data via a method.<br />
A needs to know about B to call some methods in it when it receives certain file data from the NSOpenPanel. </p>
<p>B #imports A<br />
But if A imports B there are problems - (circular importing)  </p>
<p>How should I properly reference each class?
</p></description>
		</item>
		<item>
			<title>tiffanyPea on "confuusing method"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28735#post-141618</link>
			<pubDate>Sat, 28 Jan 2012 07:32:05 +0000</pubDate>
			<dc:creator>tiffanyPea</dc:creator>
			<guid isPermaLink="false">141618@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>hai guys, haven't talked in a while, been suuuper busy.</p>
<p>Anywayz, I've been trying to write an accessor for my BulletCache class, but I've been trying to figure out where to put it in this game kit I've been playing with &#62;&#60;<br />
The game class files include a GameScene, a GameLayer, and a LevelObject class. </p>
<p>Here's the intended accessor:<br />
<pre><code>-(BulletCache*) bulletCache
{
	CCNode *node = [self getChildByTag:kTagBulletCache];
	NSAssert([node isKindOfClass:[BulletCache class]], @”not a 	BulletCache”);
	return (BulletCache*)node;
}</code></pre>
<p>I am tempted to put the BulletCache accessor in the GameScene, because I have seen conventional small game code put it there before. On the other hand, a small part of me wants to put it in the LevelObject, because this is the superclass of the Characters, Players, Enemies, and Items classes.
</p></description>
		</item>
		<item>
			<title>mijator on "HUD Layer Display and Controls"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28690#post-141396</link>
			<pubDate>Thu, 26 Jan 2012 18:12:39 +0000</pubDate>
			<dc:creator>mijator</dc:creator>
			<guid isPermaLink="false">141396@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I've been trying to combine the code from 2 tutorials by Ray Wenderlich (Toggle Buttons and HUD Layer). It's sort of working, but not exactly as I want it to...</p>
<p>I want the HUD Layer to control a couple of boolean control buttons; e.g. similar to muting/turn-on background music, change mode of the active layer from A to B (i.e, if A Mode -&#62; doThis, if B Mode -&#62;doThat), turn special effects display on in the Hud Layer, etc.</p>
<p>I used (id)initWithHUD:(CCLayer *)hud; in the HelloWorldLayer as explained in the tutorial and a Toggle Button (explained in a separate tutorial).  Then I added a CCMenuItemToggle statement (in the HelloWorldLayer) that calls a method located in the HUD layer like so:</p>
<p>CCMenuItemToggle *toggleItem = [CCMenuItemToggle itemWithTarget:_hud<br />
           selector:@selector(plusMinusButtonTapped:) items:_plusItem, _minusItem, nil];</p>
<p>This works (i.e. the button appears in the HUD layer and switches from - to + when touched.  However, the method (plusMinusButtonTapped - located in the HUD Layer implementation file) only works the way it does in the tutorial if I don't use a HUD layer.  By using CCLog, I have determined that the method is called, i.e.</p>
<p>//in the HUD implementation file</p>
<p>- (void)plusMinusButtonTapped:(id)sender {  </p>
<p>    CCLOG(@"Info Mode Particle System17 Is Active."); //this message appears when init<br />
    CCMenuItemToggle *toggleItem = (CCMenuItemToggle *)sender;<br />
    CCLOG(@"toggleItem is %@ OR %@ ???",_plusItem, _minusItem); //this message appears when the button is touched</p>
<p>//the problem is that the CCLog says "toggleItem is (null) OR (null) ???" which means it doesn't have _plusItem or _minusItem (i.e. not sent when button is touched)...why does it work at all then???</p>
<p>//hence the following never gets called</p>
<p>    if (toggleItem.selectedItem == _plusItem) {</p>
<p>//set the Bool statement here, etc.</p>
<p>}</p>
<p>Please help!
</p></description>
		</item>
		<item>
			<title>virag0 on "Hello from new member"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28471#post-140138</link>
			<pubDate>Thu, 19 Jan 2012 01:05:00 +0000</pubDate>
			<dc:creator>virag0</dc:creator>
			<guid isPermaLink="false">140138@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi,<br />
I just wanted to introduce myself.   My name is rachel and I am just stepping into ObjC/Cocos2d and iOS programming.   My background is as a Solaris admin at an Australian Uni.  I am getting pretty old now and was looking for something to stimulate my mind while I watch my job get dumbed down.   In any case, I have a bit of experience in C/C++/shell and Perl.   I am not a programmer by any means though.   I did once work on some missions that were written in C++ for a game called "Starfleet Command" - this is what piqued my interest in Cocos2D, as I made a lot of progress learning in that sandbox and see Cocos2D as another framework that gives the developer a lot of power without them getting too caught up in the details. </p>
<p>So, I bought Stephan Itterheim's first book and am trying to get the Nathan Burba one as well.</p>
<p>My focus initially was to develop a hex tile based turn based strategy game, but I am still<br />
finding the hex coordinate stuff a little too deep for me, so I am going back for a simpler<br />
structure. </p>
<p>What I am mainly interested at this stage though, is just getting some Turn Based logic<br />
going.   I understand GameKit has something to do with this, but I do not understand how<br />
to just create the basic "I go, U go" logic of a turn based game.   The kind of structure<br />
I am looking at is like "Tactical Warrior" where the player selects their team and then<br />
plays turn by turn.   I do not know if you need GK to just do that bit, or if I can use GK<br />
to provide the framework, or if I have to write my own!?</p>
<p>So, if there is anyone who can advise on a very simple (at this stage) turn based structure,<br />
with player vs computer (for now), I am interested in how this is managed in Cocos2d and<br />
event driven logic etc!  </p>
<p>That is enough from me for now.  I am catching up (lurking) on the forum etc.<br />
BTW, I got the iTiled QT version that has the hex tilemap support (like the Java one). </p>
<p>I found a thread in this forum somewhere that mentioned it, so I pulled it from the<br />
person's repo (thankyou!) and successfully compiled it up for PPC (G5) and used it to<br />
create a tilemap.  I can load all this into my game sandbox no problems, but mapping the<br />
pixels to a hex coordinate is not working - I tried the example someone listed but it<br />
still skews halfway off the map.   So, I am looking for answers to that one as well.</p>
<p>If anyone wants my PPC QT/hex itiled, I will make it available somehow, but it compiles<br />
fine against MacPorts so it is not that hard for you experts ;) </p>
<p>Also, my dev environment is schizophrenic.  At home, I have a G5 desktop that I use<br />
Screen sharing to build apps in Xcode on our Mac Mini Server.   At work I have the latest<br />
and greatest iMac 27" with Lion and I use that one to learn the tutorials on (so there is<br />
no constraint over IP ownership should it come to that!).  So that makes it "interesting"<br />
as well. </p>
<p>Finally, reading the forum on here, you all seem like really nice helpful people who<br />
are enthusiastic about this platform and I note lots of egalitarian behaviour unlike<br />
some other forums which seem to have tetchy BOFH's who would rather point people to a man page<br />
than provide a simple example - I hope I do not become like that or a whiny annoying type,<br />
either!  </p>
<p>rachel
</p></description>
		</item>
		<item>
			<title>johntmcintosh on "Restart Level with Box2d"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/19159#post-107371</link>
			<pubDate>Wed, 27 Jul 2011 15:48:30 +0000</pubDate>
			<dc:creator>johntmcintosh</dc:creator>
			<guid isPermaLink="false">107371@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi all,</p>
<p>I'm working on a cocos2d and box2d game and have been having some trouble implementing the ability to restart a level. First, here's my conceptual understanding of the correct approach:</p>
<p>I'm storing the data for my levels in XML files, so I have a single scene which loads which ever level is appropriate. The app delegate is in charge of replacing scenes whenever necessary. I have a menu scene which lets me choose which level to play. If I choose level 2, the app delegate replaces the scene with GameScene, which allows me to play that level. In GameScene I have the following methods (among others):</p>
<p>- init - which performs the first initialization<br />
- reset - which resets the values to an initial state and loads the data relevant to the current<br />
- dealloc - for the final deallocation</p>
<p>In my app delegate, I have a single instance of GameScene. Each time a level is selected, I call reset on that scene, that call replaceScene to make that the current scene.</p>
<p>Now, let's say I start on the menu to select a level. I press level 1, which calls nextLevel in my app delegate:<br />
<code><br />
- (void)nextLevel {<br />
    [_mainScene.layer reset];<br />
    [[CCDirector sharedDirector] replaceScene:_mainScene];<br />
}<br />
</code></p>
<p>The levels plays correctly. From here I can replaceScene to go back to the menu, and then back to a level with no problem. However, things do not work when I try to restart a level. To restart, I call:<br />
<code><br />
[appDelegate nextLevel];<br />
</code></p>
<p>This should reset the scene, and start it again. However, what I see is the scene in its initial state, but there is no physics behavior, and my <code>tick:</code> function only gets called once. For example, I have a ball that should fall when the level starts. When I restart, the ball is at the top of the screen but never falls.</p>
<p>So, I have a world, my sprites, and my bodies. I suspect I am not handling them correctly between the init, reset, and dealloc methods.</p>
<p>For example, right now, in init, I am simply adding a menu to the scene.<br />
In reset, I am removing the sprites and bodies and setting them to nil. Then I delete the world, then recreate the world and add the sprites and bodies to it.<br />
In dealloc, I remove the sprites and bodies and set them to nil, then delete the world.</p>
<p> Can anyone offer some insight into how this should be handled? I have seen some examples of resetting levels with cocos2d, but not when box2d is used as well.</p>
<p>Thanks so much.
</p></description>
		</item>
		<item>
			<title>riousdelie on "Singleton Box2D Scene"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28474#post-140153</link>
			<pubDate>Thu, 19 Jan 2012 04:09:21 +0000</pubDate>
			<dc:creator>riousdelie</dc:creator>
			<guid isPermaLink="false">140153@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>related thread: <a href="http://www.cocos2d-iphone.org/forum/topic/19159" rel="nofollow">http://www.cocos2d-iphone.org/forum/topic/19159</a> (Restart Level with Box2d)</p>
<p>Hi All cocos2d-iphone Amazing Community Members,</p>
<p>I am trying to use a singleton pattern while designing my game. But encountering an issue when replace scene back to instantiated scene. The Box2D simulation is not working anymore.</p>
<p>Attached project source sample is here: <a href="http://siriusdely.com/dl/SingletonBox2D.zip" rel="nofollow">http://siriusdely.com/dl/SingletonBox2D.zip</a></p>
<p>Any help is appreciated. Thank you All.
</p></description>
		</item>
		<item>
			<title>prashn64 on "Having a problem with the schedule method."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/19965#post-111437</link>
			<pubDate>Fri, 19 Aug 2011 13:48:23 +0000</pubDate>
			<dc:creator>prashn64</dc:creator>
			<guid isPermaLink="false">111437@http://www.cocos2d-iphone.org/forum/</guid>
			<description><pre><code>//
//  AudioListManager.m
//  WhatsUp
//
//  Created by john doe on 8/18/11.
//  Copyright 2011 Dreamkind. All rights reserved.
//

#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;AudioListManager.h&#34;

@implementation AudioListManager
@synthesize currentIndex = currentIndex_;
@synthesize soundList = soundList_;
static AudioListManager* sharedSingleton;

+ (AudioListManager*) getInstance {
    static BOOL initialized = NO;
    if(!initialized)
    {
        initialized = YES;
        sharedSingleton = [[AudioListManager alloc] init];
        sharedSingleton.currentIndex = 0;
        sharedSingleton.soundList = [[NSMutableArray alloc] init];
    }
    return sharedSingleton;
}

- (id)init
{
    self = [super init];
    if (self) {

    }

    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void) startPlayBack {
    timeTracker = 0;
    currentIndex_ = 0;
    [[SimpleAudioEngine sharedEngine] playEffect:[soundList_ objectAtIndex:currentIndex_]];
    [self schedule:@selector(checkAudioFileEnded:)];
}

- (void) checkAudioFileEnded:(ccTime)dt {
    NSLog(@&#34;Ticking&#34;);
    timeTracker += dt;
    if(currentIndex_ &#60; [soundList_ count]) {
        if(timeTracker &#62; [[[SimpleAudioEngine sharedEngine] soundSourceForFile:[soundList_ objectAtIndex:currentIndex_]] durationInSeconds]) {
            currentIndex_ ++;
            [[SimpleAudioEngine sharedEngine] playEffect:[soundList_ objectAtIndex:currentIndex_]];
            timeTracker = 0;
        }
    }
    else
    {
        [self unschedule:@selector(checkAudioFileEnded:)];
    }
}

@end</code></pre>
<p>This is the entire class.  The problem line is [self schedule:@selector(checkAudioFileEnded:)];</p>
<p>The program gets to startPlayBack method, that I know, because it plays the audio file, and I've checked it using breakpoints, but the NSLog in checkAudioFileEnded never fires, and a breakpoint never gets there.</p>
<p>It seems like pretty simple schedule code, and I've used the same syntax in other parts of the project but can't get it to work here.
</p></description>
		</item>
		<item>
			<title>IdonZaki on "implementing a score/lives system"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/19556#post-109345</link>
			<pubDate>Mon, 08 Aug 2011 06:13:28 +0000</pubDate>
			<dc:creator>IdonZaki</dc:creator>
			<guid isPermaLink="false">109345@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I am trying to implement a live/score system using cocos2d and box2d. my bodies are box2d bodies which collide as I want them to but the problem is that I have been trying to implement a score system where on each collision a life is removed or reduced from the lives left and after a certain number of collisions(say 3) the game is supposed to stop. On this occasion it doesn't but from the CCLOG I find out that it actually prints out the message I put in to display when the game manager is called but a weird thing is that it calls it forever(see the debugging window below)also it removes the object, "man" from the scene completely on starting the application.</p>
<p>I have a gameManager(singleton) class where in the .h file I have this declared</p>
<p>    @interface GameManager : NSObject {</p>
<p>    int lives;</p>
<p>    }<br />
    -(void)removeLives : (int)val;</p>
<p>  and in the gameManager.m file I have this method </p>
<p>        -(void)removeLives : (int)val<br />
        {</p>
<p>	   lives -=val;<br />
	  CCLOG(@"YOU HAVE LOST A LIFE MAN");</p>
<p>        }</p>
<p>In my main gameLayer.mm file in the update method I have this code</p>
<p>         if(kStateColliding){</p>
<p>        if (lives &#62; 0) {</p>
<p>		man.visible = TRUE;<br />
		}<br />
		else if(lives &#60;= 0){</p>
<p>		[man stopAllActions];</p>
<p>		man.visible = FALSE;</p>
<p>    [[GameManager sharedGameManager] removeLives:1];</p>
<p>          }<br />
       }<br />
and the lives is initialised in gameManager init method thus</p>
<p>    -(id)init {                                                        // 8<br />
    self = [super init];<br />
    if (self != nil) {<br />
        // Game Manager initialized<br />
        CCLOG(@"Game Manager Singleton, init");</p>
<p>		lives = 3;<br />
    }</p>
<p>Also note that I have a "Man" class which is Box2d class. </p>
<p>Am I doing the correct thing? Please can anyone help me out with how to go about implementing this system and where and how to make the appropriate calls. </p>
<p>Thanks.
</p></description>
		</item>
		<item>
			<title>javy on "Debugging advice - CCSpriteBatchNode removing child when I don&#039;t want it to."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/19637#post-109871</link>
			<pubDate>Wed, 10 Aug 2011 15:41:25 +0000</pubDate>
			<dc:creator>javy</dc:creator>
			<guid isPermaLink="false">109871@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have a singleton subclassed from NSObject that holds a ref to CCSpriteBatchNode containing all my game sprites. It also has references to individual sprites themselves.</p>
<p>At some point, one of the sprites is being removed form the sprite batch, although I never explicitly call the "removeFromParentAndCleanup" method.</p>
<p>Since the only debugging knowledge I have relates to stepping in and out of methods, can anyone give me good advice on how to track down when and where this sprite is being removed, as well as what is doing it?
</p></description>
		</item>
		<item>
			<title>Mettich on "Design Pattern - Singleton or many Scenes?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18573#post-104183</link>
			<pubDate>Mon, 11 Jul 2011 18:28:40 +0000</pubDate>
			<dc:creator>Mettich</dc:creator>
			<guid isPermaLink="false">104183@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello,</p>
<p>I have a design question. I have an App with different levels. I can think of two ways to achieve this:</p>
<p>1. Make a singleton, which hold the currently selected level. Then in the game class, the logic is held. Within this class i setup every level according the currently selected level. The disadvantage is, that the setup section gets somehow huge.</p>
<p>2. Make a new scene for every level. This way the setup for every level is clear. the disadvantage is, that the logic is redundant. Thus changing game logic needs to be done more than once.</p>
<p>Which is the best approach? Is there even a better one, than the two above?<br />
Best regards,<br />
Mettich
</p></description>
		</item>
		<item>
			<title>gramlin on "Experience/ideas for an inventory list?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/3012#post-18605</link>
			<pubDate>Sun, 15 Nov 2009 14:03:32 +0000</pubDate>
			<dc:creator>gramlin</dc:creator>
			<guid isPermaLink="false">18605@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi all,<br />
I'm sketching on an inventory class where I would be able to store equipment for my game characters. The idea is to be able to browse through a fairly large list and drag/drop inventory items into/from it. If anyone implemented such a thing already I'd be most interested in ideas/experience/good practice...
</p></description>
		</item>
		<item>
			<title>ashmira on "Singleton vs static function?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/17401#post-97859</link>
			<pubDate>Wed, 08 Jun 2011 01:18:36 +0000</pubDate>
			<dc:creator>ashmira</dc:creator>
			<guid isPermaLink="false">97859@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>i would like to ask a question, which 1 is the more fastest? Singleton or static function within class? </p>
<p>For example</p>
<p><code>[[Achievements sharedFile] checkComboAchievementsWithCombo:combo Level:level subLevel:subLevel];</code></p>
<p>or </p>
<p><code>[self checkComboAchievementsWithCombo:combo Level:level subLevel:subLevel];</code>
</p></description>
		</item>
		<item>
			<title>Final1 on "Please help with making a score system."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/16331#post-92165</link>
			<pubDate>Sat, 07 May 2011 18:00:42 +0000</pubDate>
			<dc:creator>Final1</dc:creator>
			<guid isPermaLink="false">92165@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi there,</p>
<p>I have recently been working on my first iphone game with cocos2D. I am at the point where i need a score system. I had a long look around the internet and saw that i need to make a label and then record and render the score with a singleton. I of cource know how to add a label to the scene so i have done that with a custom font with the code below.</p>
<pre><code>// create and initialize a Label
		CCLabelBMFont *score = [CCLabelBMFont labelWithString:@&#34;Score: 0000&#34; fntFile:@&#34;1.fnt&#34;];

		// position the label on the center of the screen
		[score setPositionInPixels:ccp(100, 300)];

		// add the label as a child to this Layer
		[self addChild:score];</code></pre>
<p>The problem is that i dont know how to implement a singleton so it records the score, i looked around and found a tutorial on how to implement a sinleton but it had nothing to do with use a singleton to record the score. I used this video: <a href="http://videos.71squared.com/6378572" rel="nofollow">http://videos.71squared.com/6378572</a> . </p>
<p>The aim of the game to to kill as as many monsters without them going past the character to the house. So obviously i need the score to go up every monster that is killed by the character.</p>
<p>As i am not really that experienced with programming in cocos2D and am still learning please could you give me a bit more detail on how to implement this please.</p>
<p>If you need any more information please ask.</p>
<p>Thank you in advance,<br />
Zack.
</p></description>
		</item>
		<item>
			<title>Amrita on "How to access variable of class inside other class"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/16960#post-95596</link>
			<pubDate>Thu, 26 May 2011 08:04:50 +0000</pubDate>
			<dc:creator>Amrita</dc:creator>
			<guid isPermaLink="false">95596@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>if I have two classes one is main " helloworld " class and other is " mySpritClass " like<br />
IS the HelloWorldScene.m file<br />
<pre><code>#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;HelloWorldScene.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;spritClass.h&#34;
@implementation HelloWorld
@synthesize No;
+(id) scene
{
	CCScene *scene = [CCScene node];
	HelloWorld *layer = [HelloWorld node];
	[scene addChild: layer];
	return scene;
}
-(id) init
{
	if( (self=[super init] )) {
		No = 100;
		spritClass *temp = [spritClass spriteWithFile:@&#34;Icon.png&#34;];
		temp.position = ccp(100,100);
		[self addChild:temp];
	}
	return self;
}
- (void) dealloc
{
	[super dealloc];
}
@end</code></pre>
<p>in HelloWorldScene.h file<br />
<pre><code>#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;cocos2d.h&#34;
@interface HelloWorld : CCLayer
{
	int No;
}
@property (readwrite) int No;
+(id) scene;

@end</code></pre>
<p>in spritClass.h file<br />
<pre><code>#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#60;Foundation/Foundation.h&#62;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;cocos2d.h&#34;

@interface spritClass : CCSprite {

}
@end</code></pre>
<p>in spritClass.m file<br />
<pre><code>#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;spritClass.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;cocos2d.h&#34;

@implementation spritClass
-(id) init
{
	if( (self=[super init] )) {
             // here i want to access &#34; No &#34; which is variable define in &#34; helloworld &#34; class
	}
	return self;
}
- (void) dealloc
{
	[super dealloc];
}
@end</code></pre>
<p>Now here in spritClass.m file, in its init function how can i access " No " variable of "helloWorld" class<br />
Is there any way to access such variable..?
</p></description>
		</item>
		<item>
			<title>ClintWall on "Passing objects between scenes"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/16805#post-94645</link>
			<pubDate>Fri, 20 May 2011 22:16:09 +0000</pubDate>
			<dc:creator>ClintWall</dc:creator>
			<guid isPermaLink="false">94645@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey guys, I am having trouble passing objects between different scenes in my app. I have a class called player1Info the contains all of my information about player1 using getter and setter methods. I need to call a setter method in one scene then call the getter method in another. I have tried using global variables and singleton classes but have had no luck, and I may have been doing them wrong. If you know a way to do this please reply.</p>
<p>Thanks<br />
Clinton Walsh
</p></description>
		</item>
		<item>
			<title>ClintWall on "Using an object in all scenes"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/16678#post-93989</link>
			<pubDate>Tue, 17 May 2011 23:43:42 +0000</pubDate>
			<dc:creator>ClintWall</dc:creator>
			<guid isPermaLink="false">93989@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey guys,</p>
<p>I have a class which is called Player1Info and I need to have an object created form that class which can be accessed by all the other classes in my app. I have tried to implement multiple solutions including Singletons and global variables, but I cannot get any of them to work. Does anyone know how to do this?</p>
<p>Thanks<br />
Clinton Walsh
</p></description>
		</item>
		<item>
			<title>lee on "Serializing Data - Subclass vs Categories vs Singleton"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/14345#post-81198</link>
			<pubDate>Thu, 10 Mar 2011 01:32:47 +0000</pubDate>
			<dc:creator>lee</dc:creator>
			<guid isPermaLink="false">81198@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I've been thinking about how I want to serialize my cocos2d data to a plist. I've worked out what I want to serialize and how, but what I can't decide on is where to implement it.</p>
<p>For example, I intend to store...</p>
<p>NSDictionary (represents a CCScene)<br />
     NSArray<br />
          NSDictionary (represents CCLayer)<br />
               NSArray<br />
                    NSDictionary (represents CCSprite)</p>
<p>I may end up changing the Dictionaries and Arrays to NSData blobs for speed. But for now I'm going for readability.</p>
<p>What I can't decided is if I want to...<br />
1) Subclass CCScene, CCLayer, and CCSprite and add methods to read and write the data I'm am interested in<br />
2) Create a Singleton object that would read in the plist file and create the Scene, layers and sprites<br />
3) Create Categories for CCScene, CCLayer and CCSprite with methods to read and write the data</p>
<p>The Subclass option has the advantage of being clear which part is working on each object, but I don't see much advantage, since one part won't necessarily work without the others</p>
<p>The Singleton has the advantage of being simple and I would image fairly easy to transition to new versions of cocos2d (very important to me given the development pace of cocos2d). However there wouldn't be any ability to add ivars to the saved objects using this method.</p>
<p>The Categories seems like the worst of the three options to me. I don't see much benefit here and once again the inability to add ivars might be an issue.</p>
<p>I'm very interested on others thoughts and opinions on which would be best.
</p></description>
		</item>
		<item>
			<title>macgeo on "How to reset player without using a singleton"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12304#post-69300</link>
			<pubDate>Mon, 03 Jan 2011 05:09:18 +0000</pubDate>
			<dc:creator>macgeo</dc:creator>
			<guid isPermaLink="false">69300@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Quick question: What's best way to "reset" a player (as in, after death) if he's a node that contains other items? Currently I do this...</p>
<p>Inside mainscene.h:<br />
<pre><code>{
//create a member variable for the player. He is a subclass of CCNode.
Player *m_player;
}</code></pre>
<p>Inside mainscene.m:<br />
<pre><code>//initialize player and add to scene
m_player = [Player node];
[self addChild:m_player];</code></pre>
<p>Within the method to kill the player:<br />
<pre><code>//likely doing this wrong...
[self removeChild:m_player];</code></pre>
<p>Then I bring him back in the same way I created the first version of him, [Player node] and addChild. Something about this isn't right because I believe the new player is inheriting some of the old one's values. Is this a pointer issue, or something else I'm screwing up? </p>
<p>Considering making my player a singleton, which may help, but would rather be "tidy" and just have the single gamestate singleton. Lemme know what you think.
</p></description>
		</item>
		<item>
			<title>sir_seagill on "if (NSString == @&quot;on&quot;) not working?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/11925#post-67265</link>
			<pubDate>Thu, 16 Dec 2010 12:58:55 +0000</pubDate>
			<dc:creator>sir_seagill</dc:creator>
			<guid isPermaLink="false">67265@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Got something strange going on that's doing my head in. Hope someone can help :&#62;</p>
<p>I'm using the singleton class from here<br />
<a href="http://getsetgames.com/2009/10/07/saving-and-loading-user-data-and-preferences/" rel="nofollow">http://getsetgames.com/2009/10/07/saving-and-loading-user-data-and-preferences/</a><br />
(tweaked it some, cos the code there was dodgy)</p>
<p>Was using an older version of cocos/xcode and all was well.</p>
<p>I update to cocos2d v0.99.5-rc1 and xcode 3.2.5 and everything is working fine including 2 other instances of the singleton class saving and loading data fine. </p>
<p>Come the issue - I have a button that changes depending on a singleton value. If 'accelSetting' == @"on" (ie use accelerometer) the button defaults to on so they can turn it off. It starts as "off" if there's no singleton value.</p>
<p>This is the method to save the data:<br />
<pre><code>-(void)setValue:(NSString*)value newString:(NSString *)aValue {
	[settings setObject:aValue forKey:value];
}</code></pre>
<p>On the button press, I save the data using:<br />
<pre><code>CCMenuItemToggle *toggleItem = (CCMenuItemToggle *)sender;
	if (toggleItem.selectedItem == _onItem){
		[[SettingsManager sharedSettingsManager]setValue:@&#34;accelSetting&#34; newString:@&#34;on&#34;];
	} else if(toggleItem.selectedItem == _offItem){
		[[SettingsManager sharedSettingsManager]setValue:@&#34;accelSetting&#34; newString:@&#34;off&#34;];
	}</code></pre>
<p>I have a test label set up and NSLog tracking the value of "accelSetting" in SettingsManager.</p>
<p>So when you open the app, it starts as off. You press the button, button goes on. Next time you open the app, it should still be 'on'. Both the nslog and label show this is happening (accelSetting goes from "off to "on") so that means the data is being saved properly.</p>
<p>This is the code that switches the button depending on "accelSetting":<br />
<pre><code>_onItem = [[CCMenuItemImage itemFromNormalImage:@&#34;on.png&#34; selectedImage:@&#34;on.png&#34; target:nil selector:nil] retain];
		_offItem = [[CCMenuItemImage itemFromNormalImage:@&#34;off.png&#34; selectedImage:@&#34;off.png&#34; target:nil selector:nil] retain];
		[[SettingsManager sharedSettingsManager] logSettings];
		[_testLabel setString:[NSString stringWithFormat:@&#34;Acel is %@&#34;,[[SettingsManager sharedSettingsManager] getString:@&#34;accelSetting&#34;]]];

		if([[SettingsManager sharedSettingsManager] getString:@&#34;accelSetting&#34;] == @&#34;on&#34;){
			_accel_toggle = [CCMenuItemToggle itemWithTarget:self selector:@selector(acceltapped:) items:_onItem,_offItem, nil];
		}else {
			_accel_toggle = [CCMenuItemToggle itemWithTarget:self selector:@selector(acceltapped:) items:_offItem,_onItem, nil];
		}</code></pre>
<p>For some reason it will never trigger the "on" condition. </p>
<p>Here's 2 things that WORKED:<br />
1) if "accelSetting" is saved with an int value (eg. 20) the if statement can detect and trigger the on button.<br />
2) if I put <code>[[SettingsManager sharedSettingsManager]setValue:@&#34;accelSetting&#34; newString:@&#34;on&#34;];</code> right before the if statement, it works. </p>
<p>I'm not sure what's going anymore. I've zipped up a test project (and recreated the error)<br />
<a href="http://uploading.com/files/a2f114b4/TEST.zip/" rel="nofollow">http://uploading.com/files/a2f114b4/TEST.zip/</a></p>
<p>Any help would be appreciated. I've already spend a couple days trying to fix this</p>
<p>Mark
</p></description>
		</item>
		<item>
			<title>timTheMystic on "Share your handy MACROS here __&gt;__"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/10219#post-58570</link>
			<pubDate>Sat, 09 Oct 2010 16:30:41 +0000</pubDate>
			<dc:creator>timTheMystic</dc:creator>
			<guid isPermaLink="false">58570@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Some handy macros I'd like to share, anyone else is welcome share if they'd like.</p>
<p>This is already in cocos2d, and this will have less accuracy (when less accuracy will do), slight better performance on calculations, since having less floating point precision.</p>
<p>// degree to radians<br />
#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> ARAD								0.017453f<br />
#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> DEG2RAD(x) ((x) * ARAD)</p>
<p>Converting PTM ratios back &#38; forth for box2d</p>
<p>#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> PTM_RATIO                       	        32.0f<br />
#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> RECIP_PTM_RATIO                 	0.03125f<br />
#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> CC_PTM(x) ((x) * RECIP_PTM_RATIO)<br />
#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> CC_RVPTM(x) ((x) * PTM_RATIO)
</p></description>
		</item>
		<item>
			<title>Sneeza on "initWithCoder and NSKeyedUnarchiver problems."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/11327#post-64156</link>
			<pubDate>Mon, 22 Nov 2010 19:00:46 +0000</pubDate>
			<dc:creator>Sneeza</dc:creator>
			<guid isPermaLink="false">64156@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi everybody,</p>
<p>I've been working on implementing a singleton to save some variables containing game progress and what not. I've run into a slight snag, where initWithCoder is not called when NSKeyedUnarchiver is called. I'm not sure why, but it's probably better if I just give you the code and you can take a little look through:</p>
<pre><code>//
//  GameState.h
//

#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;SynthesizeSingleton.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;cocos2d.h&#34;

@interface GameState: NSObject &#60;NSCoding, UIAlertViewDelegate&#62; {
    int totalDistance;
}

@property int totalDistance;

+(GameState *) sharedGameState;
+(void) loadState;
+(void) saveState;

@end</code></pre>
<pre><code>//
//  GameState.m
//

#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;SynthesizeSingleton.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;GameState.h&#34;

@implementation GameState

@synthesize totalDistance; // ints

SYNTHESIZE_SINGLETON_FOR_CLASS(GameState);

-(id) init {
    if((self = [super init])) {
		// erase all data
		self.totalDistance = 0;
    }
    return self;
}

+(void) loadState {
    @synchronized([GameState class]) {
        // just in case loadState is called before GameState inits
        if(!sharedGameState)
            [GameState sharedGameState];

		NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *file = [documentsDirectory stringByAppendingPathComponent:@&#34;gamestate.sav&#34;];
        Boolean saveFileExists = [[NSFileManager defaultManager] fileExistsAtPath:file];
		NSLog(@&#34;saveFileExists: %i&#34;, (saveFileExists)?1:0);

        if(saveFileExists) {
            NSLog(@&#34;Called NSKeyedUnarchiver&#34;);
			// don&#39;t need to set the result to anything here since we&#39;re just getting initwithCoder to be called.
            // if you try to overwrite sharedGameState here, an assert will be thrown.
			[NSKeyedUnarchiver unarchiveObjectWithFile:file];
		}
    }

    NSLog(@&#34;sharedGameState: load&#34;);
}

+(void) saveState {
    @synchronized([GameState class]) {
        GameState *state = [GameState sharedGameState];

        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *saveFile = [documentsDirectory stringByAppendingPathComponent:@&#34;gamestate.sav&#34;];

        [NSKeyedArchiver archiveRootObject:state toFile:saveFile];
    }
    NSLog(@&#34;sharedGameState: save&#34;);
}

-(id) initWithCoder:(NSCoder *)coder {
    NSLog(@&#34;Called initWithCoder:&#34;);
	self = [super init];
    if(self != nil) {
		self.totalDistance = [coder decodeIntForKey:@&#34;totalDistance&#34;];
    }
    return self;
}

-(void) encodeWithCoder:(NSCoder *)coder {
    NSLog(@&#34;Called encodeWithCoder:&#34;);
    [coder encodeInt:self.totalDistance forKey:@&#34;totalDistance&#34;];
}

@end</code></pre>
<blockquote><p>2010-11-22 18:58:37.462 ~[2820:207] Called encodeWithCoder:<br />
2010-11-22 18:58:37.466 ~[2820:207] sharedGameState: save<br />
2010-11-22 18:58:37.467 ~[2820:207] saveFileExists: 1<br />
2010-11-22 18:58:37.467 ~[2820:207] Called NSKeyedUnarchiver<br />
2010-11-22 18:58:37.550 ~[2820:207] sharedGameState: load</p>
</blockquote>
<p>As you can see, NSKeyedUnarchiver is being called, but initWithCoder doesn't get logged. I'm at a loss as to why. Any ideas?
</p></description>
		</item>
		<item>
			<title>vultuk on "Problems using singleton from ccTouchesEnded"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/10989#post-62515</link>
			<pubDate>Tue, 09 Nov 2010 11:41:37 +0000</pubDate>
			<dc:creator>vultuk</dc:creator>
			<guid isPermaLink="false">62515@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi,</p>
<p>Just getting into Cocos2d and game development in general and i'm having a bit of trouble using a singleton directly from the ccTouchesEnded method. Below is the code i'm using to test this.</p>
<pre><code>-(id) init
{
	if( (self=[super init])) {

		self.isTouchEnabled = YES;

		// This works fine and can be called any number of times
		[[characterInformation sharedCharacterInformation] addXP:[NSNumber numberWithInt:100]];
		[[characterInformation sharedCharacterInformation] addXP:[NSNumber numberWithInt:100]];
		[[characterInformation sharedCharacterInformation] addXP:[NSNumber numberWithInt:100]];
		[[characterInformation sharedCharacterInformation] addXP:[NSNumber numberWithInt:100]];

	}
	return self;
}

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

	// This doesn&#39;t work and crashes the application
	[[characterInformation sharedCharacterInformation] addXP:[NSNumber numberWithInt:100]];

}</code></pre>
<p>I'm not entirely sure why it's crashing on touching the screen as it doesn't from the init method (or any other method I create) can anyone shed any light on it?</p>
<p>Thanks in advance
</p></description>
		</item>
		<item>
			<title>supapally on "okay to subclass CCDirector?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/8915#post-51541</link>
			<pubDate>Sat, 21 Aug 2010 21:15:51 +0000</pubDate>
			<dc:creator>supapally</dc:creator>
			<guid isPermaLink="false">51541@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>This is a NOOB question that I didn't see a reply for: I need a singleton for my game for global state, etc. Is there any reason to not subclass CCDirector to get one? It would seem to be the most integrated way to work with cocos2d.
</p></description>
		</item>
		<item>
			<title>MikeTron on "How can I use a singleton to call animations"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/5218#post-31150</link>
			<pubDate>Tue, 23 Mar 2010 05:56:55 +0000</pubDate>
			<dc:creator>MikeTron</dc:creator>
			<guid isPermaLink="false">31150@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>This is a very newbie question but Im new also in objective-c, I want to call an animation in a game loop, I try to find how in this forum but I find ansers like "make an singleton dictionary for your animations and call them when you need" ???????? I understand the concept but not how to doit  can some post the code of a hole singleton with an animation and the call, pleeees :)
</p></description>
		</item>
		<item>
			<title>Neo-Dragon on "How to do Global Variables?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/5416#post-32387</link>
			<pubDate>Thu, 01 Apr 2010 02:56:44 +0000</pubDate>
			<dc:creator>Neo-Dragon</dc:creator>
			<guid isPermaLink="false">32387@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I'm just wondering how to do global variables, like an extern int Global; or something.<br />
I've been messing around my code and can't seem to get the variables to work over classes.<br />
I thought if I placed a extern int in my AppDelgate.h, I'd be able to call it from anywhere, so I thought I could put a Global=10; in my HelloWorld.m and it would work fine, but I keep getting "GLOBAL Not declared in this scope" so I'm doing it wrong lol.</p>
<p>I think globals are needed for game dev, so can someone help me by giving me an example code or even how to call an int from a singleton class.
</p></description>
		</item>
		<item>
			<title>mack on "Is this Singleton class correct? values don&#039;t change."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4944#post-29491</link>
			<pubDate>Wed, 10 Mar 2010 08:46:07 +0000</pubDate>
			<dc:creator>mack</dc:creator>
			<guid isPermaLink="false">29491@http://www.cocos2d-iphone.org/forum/</guid>
			<description><pre><code>@interface DataManager : NSObject {

	int correctAnswers;
	int incorrectAnswers;

	int raceTime;
	int speed;
	int score;

}

@property(readwrite) int correctAnswers;
@property(readwrite) int incorrectAnswers;
@property(readwrite) int raceTime;
@property(readwrite) int speed;
@property(readwrite) int score;

+ (DataManager*)sharedData;

@end

#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;DataManager.h&#34;

@implementation DataManager
@synthesize score,speed,correctAnswers,incorrectAnswers,raceTime;

static DataManager *DataManager_Singleton = nil;

+(DataManager *)sharedData
{
	if (nil == DataManager_Singleton) {
		DataManager_Singleton = [[DataManager_Singleton alloc] init];
	}
	return DataManager_Singleton;

}

@end</code></pre>
<p>Whenever I type [[DataManager sharedData] setScore = 100] or any value in another class(cocos2d layer), it remains 0.
</p></description>
		</item>
		<item>
			<title>balaji on "How to create a Animated HUD layer"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4775#post-28411</link>
			<pubDate>Mon, 01 Mar 2010 21:01:04 +0000</pubDate>
			<dc:creator>balaji</dc:creator>
			<guid isPermaLink="false">28411@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I was wondering if someone could help me with the creation of a nice animated HUD layer.<br />
I wanted an arrow button on the right top side of my screen which when pressed, smoothly opens up a transparent background HUD layer. And it can contain many in game counters and the pause button, maybe and few other stuff. Basically like a Pause screen on any PC game.
</p></description>
		</item>
		<item>
			<title>arsenio on "Moving the SharedDirector stuff out of the AppDelegate"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4809#post-28621</link>
			<pubDate>Wed, 03 Mar 2010 06:13:37 +0000</pubDate>
			<dc:creator>arsenio</dc:creator>
			<guid isPermaLink="false">28621@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi guys!</p>
<p>I hope this post isn't that confusing, but I have a problem that is making my brain hurt. I am not good at programming haha! So my problem is this and I am very sorry if it just sounds like confusion:</p>
<p>I started a project using the Cocos template.</p>
<p>My project has a Session class and a Game class. The Session class contains a couple of variables that must exist throughout the life of my program.</p>
<p>Game = a single hand of blackjack<br />
Session = 5 hands of a blackjack (i.e. 5 Games)</p>
<p>So, what I want to do ideally is that when the game starts, a new Session instance is created, which tracks how much money the player has left (let's call this session.moneyLeft)</p>
<p>Then I start an instance of Game which is a Cocos scene, and when that Game is done, the session.moneyLeft variable is updated, and then a new Game begins which checks out the session.moneyLeft variable to set it's game conditions.</p>
<p>So my problem is that I just can't figure out how to get this going, my program is like this right now:</p>
<p>BlackJackAppDelegate : applicationDidFinishLaunching<br />
   --&#62; this method sets up a sharedDirector and calls runWithScene:Game</p>
<p>Game : +(id) scene<br />
              -(void) init        These methods set up a blackjack table and play out a hand of blackjack</p>
<p>This is all fine, but I can't figure out how to get the Game instances to read the Session.moneyLeft variables - I would just move all the stuff in BlackJackAppDelegate : applicationDidFinishLaunching to the Session class, but when I do that it doesn't work.</p>
<p>I guess what I am asking is, how could I move the SharedDirector and runScene somewhere other than the AppDelegate, can I? Or is that totally idiotic?</p>
<p>(By the way, that is why this is a Cocos2d question, not just an objective C question)</p>
<p>Argh, is this super obvious and I'm just tired and whatever? Thoughts?
</p></description>
		</item>
		<item>
			<title>Taylor Jasko on "Globally Declare Sprite?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4433#post-26433</link>
			<pubDate>Fri, 12 Feb 2010 03:55:36 +0000</pubDate>
			<dc:creator>Taylor Jasko</dc:creator>
			<guid isPermaLink="false">26433@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi Everyone,</p>
<p>Please excuse me, but I am new to Objective C. But I'm not a dumby at it either because I know other programming languages like it.</p>
<p>I'm wondering how would you globally declare a sprite to be able to do certain things to it when the code (like a RunAction) isn't in the file it's declared in. Would I have to do something with the header (.h) file to make the sprite global?</p>
<p>I've heard of a singleton, but I don't know if that's what I want to use or even exactly how to use it for a sprite.</p>
<p>Would any of you be willing to give me some pointers?</p>
<p>Thanks so much! And by the way, I love your framework.
</p></description>
		</item>
		<item>
			<title>liquidchaz on "Questions about singleton classes and performance"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/3379#post-20767</link>
			<pubDate>Fri, 11 Dec 2009 16:42:35 +0000</pubDate>
			<dc:creator>liquidchaz</dc:creator>
			<guid isPermaLink="false">20767@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello all… I have a couple of noob performance questions that I wanted to ask about before I went about making drastic changes to my code.</p>
<p>First, does using a singleton class drastically reduce performance? Would it be a huge mistake to use one in a step routine that updates every frame to check for collisions?</p>
<p>Basically, the code I’m using for enemy movement is getting a little too complex and I’d like to move it out of my game scene and into the enemy class itself. Since the movements are based on the positions of the other enemies (so they don’t collide with each other) I was thinking of creating a singleton class to keep track of all the sprites in the scene. Would this be okay?</p>
<p>My other question is along these same lines… I currently have a step method in the game scene that has a nested loop to determine if any enemies are near collision with each other.  Considering my game should have no more than 6 enemies active at a time, this seems to run fine despite the O(n^2) running time. If I move the code into my enemy class, I would need a selector method running a single loop in each enemy instance… Should I expect a comparable running time?</p>
<p>I realize the fact that I’m only using a limited number of sprites should make both of the above cases work… but what if I were theoretically to have 100 sprites?</p>
<p>Thanks in advance for any clarification!
</p></description>
		</item>

	</channel>
</rss>

