<?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: Layer - Recent Topics</title>
		<link>http://www.cocos2d-iphone.org/forum/tags/layer</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 03:53:55 +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/layer/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>mijator on "Z order(s) and Layers"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/29055#post-143322</link>
			<pubDate>Wed, 08 Feb 2012 21:36:09 +0000</pubDate>
			<dc:creator>mijator</dc:creator>
			<guid isPermaLink="false">143322@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Just wondering if I am right about the priority of z orders and layers...</p>
<p>&#62;&#62;&#62;<br />
That is:</p>
<p>Layer 1 : z:0</p>
<p>CCSprite *a-sprite z:100  // a-sprite is contained within Layer 1 so even though it has an individual z order of 100, it stays within the z:0 layer and all objects (on different layers) are above it if the layer they are on is greater than z:0 (see below)</p>
<p>//it also means I can have 99 more sprite "sub layers" within layer 1 before things start to get confusing</p>
<p>Layer 2 z:1  // everything in this layer is above all of the objects in Layer 1</p>
<p>CCSprite *b-sprite z:100 //i.e., even though they have the same z value, b-sprite is NOT in the same layer as a-sprite because it has been created in layer 2...</p>
<p>&#62;&#62;&#62;<br />
Am I right with the above?
</p></description>
		</item>
		<item>
			<title>FJ on "100% working solution for the pinch-zoom &amp; pan-move with boundaries control??"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/19178#post-107524</link>
			<pubDate>Thu, 28 Jul 2011 06:08:10 +0000</pubDate>
			<dc:creator>FJ</dc:creator>
			<guid isPermaLink="false">107524@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi everybody,</p>
<p>I decide to create this thread because after going through a lot of threads I'm still stuck with this problem:<br />
I want to be able to pinch and zoom in/out (anywhere on the screen) and pan-move my layer (bigger than the screen size: 960x640) but keeping it within the limits, thus is no showing any "black background".<br />
I would like to achieve this using gesture recognizers.</p>
<p>Anybody has a 100% working code? So far I couldn't find a solution that works 100%.<br />
Just to be sure that we have the same image about what I would like to achieve, think about the "angry birds" interface and how it works.</p>
<p>Thanks to everybody in advance! :)
</p></description>
		</item>
		<item>
			<title>eshirt on "Pinch-Zoom like Fieldrunners"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2229#post-13992</link>
			<pubDate>Thu, 01 Oct 2009 18:00:47 +0000</pubDate>
			<dc:creator>eshirt</dc:creator>
			<guid isPermaLink="false">13992@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I know it's been discussed on some old posts, but I don't think I quite got the full picture from them.  In 0.8.1, I'm trying to achieve a pinch-zoom effect similar to Fieldrunners.  </p>
<p>For those not familiar, the scene would load with a background image of 2x the screen size (960x640) and set the background, etc.  I would want the camera to be "zoomed out" to fit the whole scene in the screen when the scene is loaded.  Then using the pinch gesture in ccTouchesBegan and ccTouchesMoved, I would want to modify the zoom factor.</p>
<p>Would I set my bg image, camera view, etc. in the init method, then adjust the zoom factor in the touches events?  </p>
<p>Any tips or references on how I should go about setting this up are appreciated!
</p></description>
		</item>
		<item>
			<title>plugisto on "someLayer.opacity not working"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/540#post-3198</link>
			<pubDate>Wed, 08 Jul 2009 12:38:59 +0000</pubDate>
			<dc:creator>plugisto</dc:creator>
			<guid isPermaLink="false">3198@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>hello,<br />
layer and opacity are not good friends. is this right?<br />
isn't it possible to set opacity for a layer to e.g. 50, 60. (the same way i do with a sprite.)?</p>
<p>when i try this:<br />
id go = [FadeOut actionWithDuration:.5];<br />
[introLayer runAction: go];</p>
<p>i get this message:<br />
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[IntroLayer setOpacity:]: unrecognized selector sent to instance 0xe8d2d0'</p>
<p>i am using version 0.8.</p>
<p>thanks.<br />
eugen
</p></description>
		</item>
		<item>
			<title>dgtheman on "Pinch, Zoom, and Boundries? cocoswd 0.99.5??"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28737#post-141621</link>
			<pubDate>Sat, 28 Jan 2012 11:18:07 +0000</pubDate>
			<dc:creator>dgtheman</dc:creator>
			<guid isPermaLink="false">141621@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have searched forever for a good solution to pinching/zooming and a standard algrithm for detecting the boundries on a map but have not come up with any good results. I found some but the -(void)ccTouchesMoved:withEvent: method doesnt seem to work anymore...and I have multiple touches enabled. Also, I have seen the UIPinchGestureRecognizer but it does not seem to be working for landscape mode? And one more thing...this is probably the most important...can someone provide me an alogrithm for detecting the edges of a map? So, if the user scrolls the layer moves and it does not go pass a certain boundry. The thing is I need it to work with scale as well and it is NOT a tiled map.</p>
<p>Thanks In Advance! I would appreciate any help!!
</p></description>
		</item>
		<item>
			<title>3ncrypt0 on "Draw health bar after calling -(void) initializeControls in ProjektLayer.m"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28576#post-140713</link>
			<pubDate>Sun, 22 Jan 2012 21:48:41 +0000</pubDate>
			<dc:creator>3ncrypt0</dc:creator>
			<guid isPermaLink="false">140713@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey guys,</p>
<p>i have a question: I will draw a health bar and time bar in my 3DWorld. But i will draw it after calling the -(void) initializeControls in the MyProjectLayer.m. First, i called a Level menu. Now i will select a level an then i will show my 3D Game World. It works fine, but how can i add a health bar into the 3D World, after calling the -(void) initializeControls? When i do this in the MyProjectLayer.m:</p>
<pre><code>-(void) initializeControls {
    self.isTouchEnabled = YES;
    [self showPoints];

}

-(void)showPoints{
    CCSprite *healthBar = [CCSprite spriteWithFile:@&#34;SpielenBtn.png&#34;];
    healthBar.position = ccp(50,50);

    [self addChild:healthBar];
    NSLog(@&#34;Jetzt&#34;);
}</code></pre>
<p>Then it will show the healthBar, but from the beginning. So, when i call the method showPoints in the MyProjectWorld.mm</p>
<pre><code>layer = [[MyProjectLayer alloc] init];
    [layer showPoints];</code></pre>
<p>then it will not show the health or points bar. I am not sure, where`s the problem, but i think the problem is the z-order. What can i do? Any ideas? Or do I do it completely wrong?</p>
<p>Thanks
</p></description>
		</item>
		<item>
			<title>jackrabbit on "Swallowing touches disables touches on layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22712#post-125838</link>
			<pubDate>Sun, 13 Nov 2011 19:36:14 +0000</pubDate>
			<dc:creator>jackrabbit</dc:creator>
			<guid isPermaLink="false">125838@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I basically have a layer with a scrolling picture (CCScrollView) and a CCMenuItem. When I add:</p>
<pre><code>- (void)onEnter {
    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:1 swallowsTouches:YES];
    [super onEnter];
}

- (void)onExit {
    [[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
    [super onExit];
}

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {

    return TRUE;

}</code></pre>
<p>to swallow touches, the CCMenuItem doesn't work anymore, and the picture becomes unscrollable. I tried to make another layer to swallow touches and put it behind this layer. However, I still have the same problem (I also tried playing around with the priorities of the two layers). What am I missing?
</p></description>
		</item>
		<item>
			<title>JavaWizKid on "Check if child exists?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4033#post-24148</link>
			<pubDate>Sun, 24 Jan 2010 15:52:59 +0000</pubDate>
			<dc:creator>JavaWizKid</dc:creator>
			<guid isPermaLink="false">24148@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>How can I check if a child is already on the layer before I add it?<br />
[self addChild: this];</p>
<p>Thanks.
</p></description>
		</item>
		<item>
			<title>dozeone on "call init() function of layer everytime you switchTo: that layer"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28243#post-138946</link>
			<pubDate>Tue, 10 Jan 2012 19:15:50 +0000</pubDate>
			<dc:creator>dozeone</dc:creator>
			<guid isPermaLink="false">138946@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I n my code the main menu starts the game by:<br />
[(CCLayerMultiplex*)parent_ switchTo:1];<br />
and the game over screen:<br />
[(CCLayerMultiplex*)parent_ switchTo:2];<br />
and then it switches back to the main menu.<br />
However when i then jump back to layer 1 (the game) a second time, (it should be restarted by calling the init function again) all the sprite movements are just stopped and the score is not reseted.</p>
<p>is there any similar to viewDidAppear or something like that i need to use?</p>
<p><code><br />
-(id) init{<br />
if( ! [super init] )<br />
    return nil;</p>
<p>    self.isTouchEnabled = YES;<br />
    self.isAccelerometerEnabled = YES;<br />
    self.score=0;<br />
    self.life=100;<br />
    self.fuel=1000;<br />
  ....</code>
</p></description>
		</item>
		<item>
			<title>stuffradio on "Level select ideas"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/3558#post-21634</link>
			<pubDate>Wed, 23 Dec 2009 17:36:55 +0000</pubDate>
			<dc:creator>stuffradio</dc:creator>
			<guid isPermaLink="false">21634@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I was thinking of doing a UIScrollView with paging, but it looks hard to implement, so I wonder if a UITableView would be best. What do you guys use for your Level select?</p>
<p>I tried searching for UIScrollView and I saw that you have to uncomment a line in Director.m or something, just not sure what the best solution is. I also want to know something for scrolling text when I want to display lots of information. (Which would be best displayed in a scroll view).
</p></description>
		</item>
		<item>
			<title>Jamorn on "Help! Creating an extension I need: Scrollable Layer (CCSuperMenuAdvanced)"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/20903#post-116167</link>
			<pubDate>Thu, 15 Sep 2011 18:10:25 +0000</pubDate>
			<dc:creator>Jamorn</dc:creator>
			<guid isPermaLink="false">116167@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi guys, I'm working on a game that has a pretty complex menu system and it requires some scrolling through content.</p>
<p>If you can imagine, the screen is in landscape, I will have a list of navigation item on the left (scrollable) and the content on the right (scrollable) which changes based on the item the player selects on the right.</p>
<p>The navigation pane (left side) consists of just CCMenuItem aligned vertically.</p>
<p>The content pane (right side) consists of any CCNode including buttons (aka CCMenuItem) which should responds to touches normally, but once the layer is scrolled, any CCMenuItem under the touch should be "deselected."</p>
<p>Currently the navigation pane is using CCMenuAdvanced and that works perfectly well for the navigation. However, CCMenuAdvanced will not cut it for the content as CCMenuAdvanced does not take CCNode as children.</p>
<p>As I feel that the scrolling code should be written in one place (DRY principle) so I have to create another class that is a cross between CCLayer &#38; CCMenuAdvanced with the benefits of both. In this case the new class will take any CCNode BUT still activates CCMenuItems correctly.</p>
<p>Here's what I have so far, and it works (to an extent):</p>
<p><strong>CCSuperMenuAdvanced.h</strong><br />
<pre><code>//
//  CCSuperMenuAdvanced.h
//  PrototypeZero
//
//  Created by Jamorn Ho on 9/4/11.
//  Copyright 2011 Jamorn Ho &#38; Paul Vishayanuroj. All rights reserved.
//

#<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;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;Debug.h&#34;

/** A CCSuperMenuAdvanced
 *
 * Features and Limitation:
 *  - You can add ANY CCNode objects in runtime using addChild:
 *  - Any CCMenuItem objects will be activated as if they are within a menu
 *  - Scrolls vertically when swiped up or down
 *  - Does not work with Mac
 */
@interface CCSuperMenuAdvanced : CCLayer &#60;CCRGBAProtocol&#62; {
    /** Copied from CCMenu */
    tCCMenuState state_;
	CCMenuItem	*selectedItem_;
	GLubyte		opacity_;
	ccColor3B	color_;

    /** Copied from CCMenuAdvanced */
    NSInteger priority_;
	int selectedItemNumber_;

	CGRect boundaryRect_; //&#60; external boundaries in which menu can slide
	CGFloat minimumTouchLengthToSlide_; //&#60; how long user must slide finger to start scrolling menu
	CGFloat curTouchLength_;

    tCCMenuState prevState_;
    CGPoint prevPosition_;
    CGFloat velocity_;
    int direction_;

	BOOL isDisabled_;

#ifdef DEBUG_SUPER_MENU_ADVANCED
	BOOL debugDraw_;
#endif
}
/** Copied from CCMenu */
/** creates a CCMenu with it&#39;s items */
+ (id) menuWithItems: (CCNode*) item, ... NS_REQUIRES_NIL_TERMINATION;

/** initializes a CCMenu with it&#39;s items */
- (id) initWithItems: (CCNode*) item vaList: (va_list) args;

/** align items vertically */
-(void) alignItemsVertically;

/** align items horizontally */
-(void) alignItemsHorizontally;

/** conforms to CCRGBAProtocol protocol */
@property (nonatomic,readonly) GLubyte opacity;
/** conforms to CCRGBAProtocol protocol */
@property (nonatomic,readonly) ccColor3B color;

/** Copied from CCMenuAdvanced */

#pragma mark Advanced Menu - Align
/** AlignH items horizontal from left to right.
 * @param padding space between elements.
 */
-(void) alignItemsHorizontallyWithPadding:(float)padding;

/** Designated alignVerticall from bottom to top.
 * @param padding space between elements.
 */
-(void) alignItemsVerticallyWithPadding:(float)padding;

/** Designated alignHorizontal Method
 *
 * @param padding space between elements.
 * @param leftRoRight If YES - align items from left to right, if NO - right to left.
 */
-(void) alignItemsHorizontallyWithPadding:(float)padding leftToRight: (BOOL) leftToRight;

/** Designated alignVerticall Method
 *
 * @param padding space between elements.
 * @param bottomToTop If YES - align items from bottom to top, if NO - top to bottom.
 */
-(void) alignItemsVerticallyWithPadding:(float)padding bottomToTop: (BOOL) bottomToTop;

/** Rectangle in parent&#39;s coordinate system, which menu must fill with it&#39;s boundingBox.
 *
 * Note: boundaryRect must have greater size then menu&#39;s boundingBox to make scrolling possible.
 * Think about boundaryRect like about hole in paper sheet under which you would like to put CCMenuAdvanced
 * and scroll it, but you never want to see the table - hole must be covered with paper.
 */
@property(readwrite, assign) CGRect boundaryRect;

/** Minimum length of touch, that will disable selected menu item &#38; start scrolling. */
@property(readwrite, assign) CGFloat minimumTouchLengthToSlide;

/** Priority property for touch, mouse &#38; keyboard for menu.
 * Must be set before onEnter called.
 */
@property(readwrite, assign) NSInteger priority;

/** If YES - all touches &#38; keyboard events will be ignored.
 * If NO - all events will work, except for disabled items.
 * Default is NO.
 */
@property(readwrite, assign) BOOL isDisabled;

#ifdef DEBUG
/** If YES - draw rectangle around CCMenuAdvanced. */
@property(readwrite, assign) BOOL debugDraw;
#endif

#pragma mark Advanced Menu - Scrolling

/** Changes menu position to stay inside of boundaryRect if it is non-null. */
- (void) fixPosition;

#pragma mark Advanced Menu - Selecting Items
- (void) selectNextMenuItem;
- (void) selectPrevMenuItem;

#pragma mark Advanced Menu - Activating/Cancelling Selected Items.
- (void) activateSelectedItem;
- (void) cancelSelectedItem;

@end</code></pre>
<p><strong>CCSuperMenuAdvanced.m</strong><br />
<pre><code>//
//  CCSuperMenuAdvanced.m
//  PrototypeZero
//
//  Created by Jamorn Ho on 9/4/11.
//  Copyright 2011 Jamorn Ho &#38; Paul Vishayanuroj. All rights reserved.
//

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

enum {
	kDefaultPadding =  5,
};

@implementation NSString (UnicharExtensions)

+ (NSString *) stringWithUnichar: (unichar) anUnichar
{
	return [[[NSString alloc] initWithCharacters:&#38;anUnichar length:1] autorelease];
}

- (unichar) unicharFromFirstCharacter: (NSString *) aString
{
	if ([aString length])
		return [aString characterAtIndex:0];
	return 0;
}

@end

@interface CCMenu (Private)
-(void) update:(ccTime)dt;
-(CCMenuItem *) itemForTouch: (UITouch *) touch;
@end

@implementation CCSuperMenuAdvanced

@synthesize opacity = opacity_, color = color_;
@synthesize boundaryRect = boundaryRect_;
@synthesize minimumTouchLengthToSlide = minimumTouchLengthToSlide_;
@synthesize priority = priority_;
@synthesize isDisabled = isDisabled_;

#ifdef DEBUG
@synthesize debugDraw = debugDraw_;
#endif

- (id) init
{
    NSAssert(NO, @&#34;CCMenu: Init not supported.&#34;);
	[self release];
	return nil;
}

+(id) menuWithItems: (CCNode*) item, ...
{
	va_list args;
	va_start(args,item);

	id s = [[[self alloc] initWithItems: item vaList:args] autorelease];

	va_end(args);
	return s;
}

-(id) initWithItems: (CCNode*) item vaList: (va_list) args
{
    if( (self=[super init]) ) {

		self.isTouchEnabled = YES;

		// menu in the center of the screen
		CGSize s = [[CCDirector sharedDirector] winSize];

		self.isRelativeAnchorPoint = NO;
		anchorPoint_ = ccp(0.5f, 0.5f);
		[self setContentSize:s];

		// XXX: in v0.7, winSize should return the visible size
		// XXX: so the bar calculation should be done there
		CGRect r = [[UIApplication sharedApplication] statusBarFrame];
		ccDeviceOrientation orientation = [[CCDirector sharedDirector] deviceOrientation];
		if( orientation == CCDeviceOrientationLandscapeLeft &#124;&#124; orientation == CCDeviceOrientationLandscapeRight )
			s.height -= r.size.width;
		else
			s.height -= r.size.height;

		self.position = ccp(s.width/2, s.height/2);

		int z=0;

		if (item) {
			[self addChild: item z:z];
			CCNode *i = va_arg(args, CCNode*);
			while(i) {
				z++;
				[self addChild: i z:z];
				i = va_arg(args, CCNode*);
			}
		}

		selectedItem_ = nil;
		state_ = kCCMenuStateWaiting;

        self.isRelativeAnchorPoint = YES;
		selectedItemNumber_ = -1;
		self.boundaryRect = CGRectNull;
		self.minimumTouchLengthToSlide = 30.0f;

		if (item)
			[self alignItemsVertically];

        prevState_ = kCCMenuStateWaiting;
        prevPosition_ = self.position;
        velocity_ = 0;

        //[self schedule:@selector(update:) interval:1.0/25.0];
	}

	return self;
}

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

- (void) onExit
{
	if(state_ == kCCMenuStateTrackingTouch)
	{
		[selectedItem_ unselected];
		state_ = kCCMenuStateWaiting;
		selectedItem_ = nil;
	}
	[super onExit];
}

#pragma mark Advanced Menu - Priority
-(NSInteger) mouseDelegatePriority
{
	return priority_;
}

-(NSInteger) keyboardDelegatePriority
{
	return priority_;
}

#pragma mark Menu - Touches

-(void) registerWithTouchDispatcher
{
	[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate: self
													 priority:[self mouseDelegatePriority]
											  swallowsTouches: YES ];
}

-(CCMenuItem *) itemForTouch: (UITouch *) touch
{
	CGPoint touchLocation = [touch locationInView: [touch view]];
	touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];

	CCNode* itemTemp;
	CCARRAY_FOREACH(children_, itemTemp){

        if ([itemTemp isKindOfClass:[CCMenuItem class]]) {

            CCMenuItem *item = (CCMenuItem *)itemTemp;

            // ignore invisible and disabled items: issue #779, #866
            if ( [item visible] &#38;&#38; [item isEnabled] ) {

                CGPoint local = [item convertToNodeSpace:touchLocation];
                CGRect r = [item rect];
                r.origin = CGPointZero;

                if( CGRectContainsPoint( r, local ) )
                    return item;
            }
        }
	}
	return nil;
}

#pragma mark Advanced Menu - Draw

#ifdef DEBUG_SUPER_MENU_ADVANCED
- (void) draw
{
	[super draw];

	if (self.debugDraw)
	{
		CGSize s = [self contentSize];
		CGPoint vertices[4]={
			ccp(0,0),ccp(s.width,0),
			ccp(s.width,s.height),ccp(0,s.height),
		};
		ccDrawPoly(vertices, 4, YES);
	}
}
#endif

#pragma mark Advanced Menu - Selecting/Activating Items

- (void) selectNextMenuItem
{
	if ([children_ count] &#60; 2)
		return;

	selectedItemNumber_++;

	// borders
	if (selectedItemNumber_ &#62;= (int)[children_ count])
		selectedItemNumber_ = 0;
	if (selectedItemNumber_ &#60; 0)
		selectedItemNumber_ = [children_ count] - 1;

	// select selected
	int i = 0;
	for (CCMenuItem *item in children_)
	{
		[item unselected];
		if ( i == selectedItemNumber_ )
			[item selected];
		++i;
	}
}

- (void) selectPrevMenuItem
{
	if ([children_ count] &#60; 2)
		return;

	selectedItemNumber_--;

	// borders
	if (selectedItemNumber_ &#62;= (int)[children_ count])
		selectedItemNumber_ = 0;
	if (selectedItemNumber_ &#60; 0)
		selectedItemNumber_ = [children_ count] - 1;

	// select selected
	int i = 0;
	for (CCMenuItem *item in children_)
	{
		if ( i == selectedItemNumber_ )
			[item selected];
		else
			[item unselected];

		++i;
	}
}

- (void) activateSelectedItem
{
	if (selectedItemNumber_ &#60; 0)
		return;

	// Unselect selected menu item.
	CCMenuItem *item = [children_ objectAtIndex: selectedItemNumber_];
	[item unselected];
	selectedItemNumber_ = -1;

	[item activate];

}

- (void) cancelSelectedItem
{
	if( selectedItem_ ) {
		[selectedItem_ unselected];
		selectedItem_ = nil;
	}

	selectedItemNumber_ = -1;

	state_ = kCCMenuStateWaiting;
}

#pragma mark Menu - Alignment
-(void) alignItemsVertically
{
	[self alignItemsVerticallyWithPadding:kDefaultPadding];
}

-(void) alignItemsHorizontally
{
	[self alignItemsHorizontallyWithPadding:kDefaultPadding];
}

#pragma mark Advanced Menu - Alignment
// differences from std impl:
//		* 1 auto setContentSize
//		* 2 each item.x = width / 2
//		* 3 item starts from top, not from center on y
//		* [MAC] binds keyboard keys for verticall taking care about direction
-(void) alignItemsVerticallyWithPadding:(float)padding bottomToTop: (BOOL) bottomToTop
{
	float height = -padding;
	float width = 0;

	// calculate and set contentSize,
	CCMenuItem *item;
	CCARRAY_FOREACH(children_, item)
	{
		height += item.contentSize.height * item.scaleY + padding;
		width = MAX(item.contentSize.width * item.scaleX, width);
	}
	[self setContentSize: CGSizeMake(width, height)];

	// allign items
	float y = 0;
	if (! bottomToTop)
		y = height;

	CCARRAY_FOREACH(children_, item) {
		CGSize itemSize = item.contentSize;
	    [item setPosition:ccp(width / 2.0f, y - itemSize.height * item.scaleY / 2.0f)];

		if (bottomToTop)
			y += itemSize.height * item.scaleY + padding;
		else
			y -= itemSize.height * item.scaleY + padding;
	}

	// Fix position of menuItem if it&#39;s the only one.
	if ([children_ count] == 1)
		[[children_ objectAtIndex: 0] setPosition: ccp(width / 2.0f, height / 2.0f ) ];
}

// differences from std impl:
//		* 1 auto setContentSize
//		* 2 each item.y = height / 2
//		* items start from zero - i dunno why
//		* supports both directions
//		* [MAC] binds keyboard keys for horizontal taking care about direction
-(void) alignItemsHorizontallyWithPadding:(float)padding leftToRight: (BOOL) leftToRight
{
	float width = -padding;
	float height = 0;

	// calculate and set content size
	CCMenuItem *item;
	CCARRAY_FOREACH(children_, item)
	{
		width += item.contentSize.width * item.scaleX + padding;
		height = MAX(item.contentSize.height * item.scaleY, height);
	}
	[self setContentSize: CGSizeMake(width, height)];

	float x = 0;
	if ( !leftToRight )
		x = width;

	// align items
	CCARRAY_FOREACH(children_, item)
	{
		CGSize itemSize = item.contentSize;

		CGPoint curPos = ccp(x + itemSize.width * item.scaleX / 2.0f, height / 2.0f);
		if (!leftToRight) {
			curPos.x = x - itemSize.width * item.scaleX / 2.0f;
		}

		[item setPosition:curPos];

		if (leftToRight)
			x += itemSize.width * item.scaleX + padding;
		else
			x -= itemSize.width * item.scaleX + padding;
	}
}

-(void) alignItemsHorizontallyWithPadding:(float)padding
{
	[self alignItemsHorizontallyWithPadding: padding leftToRight: YES];
}

-(void) alignItemsVerticallyWithPadding:(float)padding
{
	[self alignItemsVerticallyWithPadding: padding bottomToTop: YES];
}

#pragma mark Advanced Menu - Scrolling

- (void) fixPosition
{
	if ( CGRectIsNull( boundaryRect_) &#124;&#124; CGRectIsInfinite(boundaryRect_) )
		return;

#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> CLAMP(x,y,z) MIN(MAX(x,y),z)

	// get right top corner coords
	CGRect rect = [self boundingBox];
	CGPoint rightTopCorner = ccp(rect.origin.x + rect.size.width,
								 rect.origin.y + rect.size.height);
	CGPoint originalRightTopCorner = rightTopCorner;
	CGSize s = rect.size;

	// reposition right top corner to stay in boundary
	CGFloat leftBoundary = boundaryRect_.origin.x + boundaryRect_.size.width;
	CGFloat rightBoundary = boundaryRect_.origin.x + MAX(s.width, boundaryRect_.size.width);
	CGFloat bottomBoundary = boundaryRect_.origin.y + boundaryRect_.size.height;
	CGFloat topBoundary = boundaryRect_.origin.y + MAX(s.height,boundaryRect_.size.height);

	rightTopCorner = ccp( CLAMP(rightTopCorner.x,leftBoundary,rightBoundary),
						 CLAMP(rightTopCorner.y,bottomBoundary,topBoundary));

	// calculate and add position delta
	CGPoint delta = ccpSub(rightTopCorner, originalRightTopCorner);
	self.position = ccpAdd(self.position, delta);		

#undef CLAMP

}

- (void) update:(ccTime)dt
{
    if (prevState_ == kCCMenuStateTrackingTouch &#38;&#38; state_ == kCCMenuStateWaiting) {
        velocity_ = self.position.y - prevPosition_.y;
        direction_ = velocity_ &#62; 0 ? 1 : -1;
    }

    if (direction_ &#62; 0) {
        if (velocity_ &#62; 0 &#38;&#38; state_ != kCCMenuStateTrackingTouch) {
            self.position = ccp(self.position.x, self.position.y + velocity_);
            velocity_ -= 2.0;
        }
        else {
            velocity_ = 0;
        }
    }
    else {
        if (velocity_ &#60; 0 &#38;&#38; state_ != kCCMenuStateTrackingTouch) {
            self.position = ccp(self.position.x, self.position.y + velocity_);
            velocity_ += 2.0;
        }
        else {
            velocity_ = 0;
        }
    }

    prevPosition_ = self.position;
    prevState_ = state_;

    [self fixPosition];
}

// returns YES if touch is inside our boundingBox
-(BOOL) isTouchForMe:(UITouch *) touch
{
	CGPoint point = [self convertToNodeSpace:[[CCDirector sharedDirector] convertToGL:[touch locationInView: [touch view]]]];
	CGPoint prevPoint = [self convertToNodeSpace:[[CCDirector sharedDirector] convertToGL:[touch previousLocationInView: [touch view]]]];

	CGRect rect = CGRectMake(0, 0, self.contentSize.width, self.contentSize.height);

    if ( CGRectContainsPoint(rect, point) &#124;&#124; CGRectContainsPoint(rect, prevPoint) )
		return YES;

	return NO;
}

-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
	if( state_ != kCCMenuStateWaiting &#124;&#124; !visible_ &#124;&#124; self.isDisabled )
		return NO;

	curTouchLength_ = 0; //&#60; every new touch should reset previous touch length

	selectedItem_ = [self itemForTouch:touch];
	[selectedItem_ selected];

    // start slide if touch began inside of menuitems or outside menuitem but inside menu rect
	if( selectedItem_ &#124;&#124; (!CGRectIsNull(boundaryRect_) &#38;&#38; [self isTouchForMe: touch])) {
		state_ = kCCMenuStateTrackingTouch;
		return YES;
	}

	return NO;
}

-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
	NSAssert(state_ == kCCMenuStateTrackingTouch, @&#34;[Menu ccTouchEnded] -- invalid state&#34;);

	[selectedItem_ unselected];
	[selectedItem_ activate];

	state_ = kCCMenuStateWaiting;
}

-(void) ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event
{
	NSAssert(state_ == kCCMenuStateTrackingTouch, @&#34;[Menu ccTouchCancelled] -- invalid state&#34;);

	[selectedItem_ unselected];

	state_ = kCCMenuStateWaiting;
}

-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
	NSAssert(state_ == kCCMenuStateTrackingTouch, @&#34;[Menu ccTouchMoved] -- invalid state&#34;);

	CCMenuItem *currentItem = [self itemForTouch:touch];

	if (currentItem != selectedItem_) {
		[selectedItem_ unselected];
		selectedItem_ = currentItem;
		[selectedItem_ selected];
	}

	// scrolling is allowed only with non-zero boundaryRect
	if (!CGRectIsNull(boundaryRect_))
	{
        NSLog(@&#34;SCROLLING SCROLLING&#34;);
		// get touch move delta
		CGPoint point = [touch locationInView: [touch view]];
		CGPoint prevPoint = [ touch previousLocationInView: [touch view] ];
		point =  [ [CCDirector sharedDirector] convertToGL: point ];
		prevPoint =  [ [CCDirector sharedDirector] convertToGL: prevPoint ];
		CGPoint delta = ccpSub(point, prevPoint);

		curTouchLength_ += ccpLength( delta ); 

		if (curTouchLength_ &#62;= self.minimumTouchLengthToSlide)
		{
			[selectedItem_ unselected];
			selectedItem_ = nil;

			// add delta
			CGPoint newPosition = ccpAdd(self.position, delta );
			self.position = newPosition;

			// stay in externalBorders
			[self fixPosition];

            NSLog(@&#34;Position: %f, %f&#34;, self.position.x, self.position.y);
		}
	}
}

#pragma mark Menu - Opacity Protocol

/** Override synthesized setOpacity to recurse items */
- (void) setOpacity:(GLubyte)newOpacity
{
	opacity_ = newOpacity;

	id&#60;CCRGBAProtocol&#62; item;
	CCARRAY_FOREACH(children_, item)
    [item setOpacity:opacity_];
}

-(void) setColor:(ccColor3B)color
{
	color_ = color;

	id&#60;CCRGBAProtocol&#62; item;
	CCARRAY_FOREACH(children_, item)
    [item setColor:color_];
}

-(void) setPosition:(CGPoint)position
{
    prevPosition_ = self.position;
    position_ = position;
}

@end</code></pre>
<p>Now, this works in a sense that you can add CCMenuItem or CCNode and it will handle them properly. CCMenuItems activates when tapped, CCNode does nothing. This also works when a CCMenuItem is on top of a CCNode, so no problem there if you want to put a button on a background (CCSprite).</p>
<p>But I'm having issues with the scrolling and positioning the layer. It seems changing the position value of the CCSuperMenuAdvanced does nothing. The layer is stuck for some reason even when the position value is being updated. I have no idea why and it's driving me crazy.</p>
<p>If anybody could help me see what could be wrong I'd really appreciate it. Once this class is complete, I'll post the final product to share as well as credit those who helped.</p>
<p>The code for this class was taken from CCMenu and CCMenuAdvanced and merged together, if you were wondering. Thanks in advance to anybody who helps!
</p></description>
		</item>
		<item>
			<title>alokin on "transition (replaceScene) problem"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/27930#post-137134</link>
			<pubDate>Thu, 29 Dec 2011 02:27:10 +0000</pubDate>
			<dc:creator>alokin</dc:creator>
			<guid isPermaLink="false">137134@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello,</p>
<p>I am having a problem with scene transitions. What seems to be happening is after I call a function to do a scene transition, during the 0.5 seconds of transition time (which I set), the main loop of the current scene still runs, which can cause some quirky problems. Here is an example of some code which produces some weird results (but inevitably works):</p>
<p>- (void) update : (ccTime) delta<br />
{<br />
    ...</p>
<p>    if ([computer hp] &#60;= 0)<br />
    {<br />
        [self gotoUserWinsLayer];<br />
    }<br />
}</p>
<p>…</p>
<p>- (void) gotoUserWinsLayer<br />
{<br />
    // go to the UserWinsLayer scene<br />
    [[CCDirector sharedDirector] replaceScene :<br />
	 [CCTransitionFade transitionWithDuration : 0.5f<br />
                                        scene : [UserWinsLayer scene]]];<br />
}</p>
<p>So here, "replaceScene" is called several times awkwardly since the "update" method is still being called during the 0.5 seconds of transition time.. This is probably a n00b question, hopefully I'm just being stupid. Any help would be greatly appreciated.</p>
<p>Thanks,<br />
Nikola
</p></description>
		</item>
		<item>
			<title>belkode on "CCMotionStreak within moving layer"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/15715#post-88939</link>
			<pubDate>Tue, 19 Apr 2011 04:47:33 +0000</pubDate>
			<dc:creator>belkode</dc:creator>
			<guid isPermaLink="false">88939@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Currently working of 0.99.5, and I am having an issue getting CCMotionStreak to shift along with its layer.</p>
<p>The scenario is: I have a "ship" moving along vector leaving a fading contrail (the CCMStreak). The thing is, the ship is a child in a CCLayer called MapLayer. MapLayer is often moved about by changing its .position - like a shifting map in an RTS. This ship icon (CCSprite) moves along fine as the MapLayer is moved around, but the contrail seems to go nuts. The new points are added correctly, but the previous points in the CCMotionStreak do not shift (respecting the contrail shape) according to what I would expect, given the fact that the CCMotionStreak is also added as a child of MapLayer). Below is some code:</p>
<p>In MapLayer.m<br />
-(id) init<br />
{<br />
	if ((self = [super init]))<br />
	{<br />
               // The tilemap shifts fine within the MapLayer<br />
		CCTMXTiledMap *tileMap = [CCTMXTiledMap tiledMapWithTMXFile:@"grid.tmx"];<br />
		[self addChild:tileMap z:-1 tag:1];</p>
<p>		// Add a unit - the ship icon - this shifts fine as well<br />
		[self addUnitAt:ccp(300,100) withHeading:270.0f];</p>
<p>		// Add contrail to blip - as a child to MapLayer CCLayer<br />
	       CCMotionStreak *ribbon = [CCMotionStreak streakWithFade:8.0f minSeg:10 image:@"whiteRibbon.png" width:2 length:50 color:ccc4(200, 200, 200, 200)];<br />
		[self addChild:ribbon z:1 tag:2];</p>
<p>		[self scheduleUpdate];</p>
<p>		self.isTouchEnabled = YES;<br />
	}<br />
	return self;<br />
}</p>
<p>the update method:</p>
<p>-(void) update:(ccTime)delta<br />
{<br />
	[blip moveUnit:delta];   // updates ship position</p>
<p>	CCMotionStreak *ribbon = [self getRibbon];   // this just gets the CCMStreak by tag reference<br />
	[ribbon.ribbon addPointAt:ccpAdd(self.position, blip.sprite.position) width:2];<br />
	[ribbon update:delta];<br />
}</p>
<p>So the question is: if the ship and the layer move accordingly (i.e. MapLayer is moved within the scene, while another layer UILayer is not), why does the CCMotionStreak not accompany the motion? Do I need to explicitly move the streak as well, even though it is a child of MapLayer? Am I fundamentally misunderstanding how child/parent nodes work?</p>
<p>Hope someone can help
</p></description>
		</item>
		<item>
			<title>dgtheman on "Do too many updates take up too much memory?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22659#post-125685</link>
			<pubDate>Sat, 12 Nov 2011 07:12:43 +0000</pubDate>
			<dc:creator>dgtheman</dc:creator>
			<guid isPermaLink="false">125685@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have a lot of updates running at once in my app. These updates are categorized for the important sprites in my game, so the Ais are running their own update, a cabinet which generates random loot and is opened when tapped is going through its own update, etc. Does this take up too much memory? Because on a 2g ipod the app gives a memory warning level = 2 when in the main city (with the most sprites in the scene at once) and gives a memory warning level = 1 when the updates for some major sprites are remove. Pretty much Im trying to ask if it is worth it to almost destroy my way of organization and only update in one scene...so run only one update and pass in every sprite's data in that one update. This would take a very long time and I would have to restructure a lot of well organized code. Thats why I really want to know if it is worth doing so. I want to make this app playable on the ipod 2g with no memory issues and if I need to do this then I will. Also, here is some more background info that is contributing to the memory issues. I would like to know if I can resolve these issues instead of the update issue which does not fix the whole thing anyway...</p>
<p>1.)I have 11 plists loaded in at once (each 1024 x 1024) and I will need some frames from each of them in the scene at one time. Should I organize it so that I use less? If so how many should be in the scene at once?</p>
<p>2.)I have a lot of arrays initalized at the beginning of the game. Should I restructure my code to get rid of all these arrays? The arrays contain CCSprites and b2Bodys (pointers)</p>
<p>3.) I have a NSDictionary thats stores a lot of NSNumbers. I had posted another question regarding whether or not these take up too much memory and almost evreyone said that unless you are storing 1 million of them it will ot matter. I am only storing maybe 200.</p>
<p>4.)I have some global variables that need to be retained (including arrays and ccsprites) should I somehow get rid of these global variables? I know its not good practice to use them but I did not know this when I first started programming my game....Also, if possible this option should be ruled out because I need the GameScene layer and the hero sprite as global variables no matter what...</p>
<p>Thanks for any suggestions!!
</p></description>
		</item>
		<item>
			<title>NOG on "Getting CCParticleSystem to move along with layer"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22534#post-125090</link>
			<pubDate>Tue, 08 Nov 2011 18:24:44 +0000</pubDate>
			<dc:creator>NOG</dc:creator>
			<guid isPermaLink="false">125090@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>It didn't bother me too much before, but now I've reached a point where I have to do this.  I need an emitter to follow along by repositioning itself with the position of the map. For instance, when the map scrolls, the emitter should to.</p>
<p>I create my emitter like this:</p>
<pre><code>CCParticleSystem *emitter = [CCParticleSystemQuad particleWithFile:@&#34;ringExplosion.plist&#34;];
                [emitter setPosition:ccp(tempSp.position.x, tempSp.position.y)];
                [self addChild:emitter z:11];
                emitter.autoRemoveOnFinish = YES;</code></pre></description>
		</item>
		<item>
			<title>hugocosta on "Fade In or Out a CCLayer"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/5088#post-30380</link>
			<pubDate>Wed, 17 Mar 2010 00:36:41 +0000</pubDate>
			<dc:creator>hugocosta</dc:creator>
			<guid isPermaLink="false">30380@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi,</p>
<p>I've searched and i can't find a way to fade in and out a CCLayer.<br />
I'm trying to fade in and then fade out a Menu.<br />
As i understand it a CCLayer is a CCNode so it would be possible to perform Actions on it, but the game crashes.</p>
<p>I've tried doing it when i create it, and on the init method, same result.</p>
<p><code><br />
-(void)showMenu {</p>
<p>	CCLayer* menuLayer = [MenuLayer node];<br />
	id actionFadeIn = [CCFadeIn actionWithDuration:0.3];<br />
	[menuLayer runAction:[CCSequence actions:actionFadeIn, nil]];</p>
<p>	[self addChild:menuLayer z:1];<br />
}<br />
</code></p>
<p>Thank you
</p></description>
		</item>
		<item>
			<title>bvarasse on "Adding a score layer to the main scene"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22036#post-122495</link>
			<pubDate>Sat, 22 Oct 2011 12:08:21 +0000</pubDate>
			<dc:creator>bvarasse</dc:creator>
			<guid isPermaLink="false">122495@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi Everybody</p>
<p>I have a scene that i get the static member by:</p>
<p><code></p>
<p>+(id) scene<br />
{<br />
    CCScene *scene = [CCScene node];<br />
   [scene addChild:[Game node] z:0 tag:GAME_TAG];<br />
    return scene;<br />
}<br />
</code></p>
<p>I also have a ScoreLayer class, subclass of CCLayer that is done that way:</p>
<p><code><br />
@implementation ScoreLayer</p>
<p>-(id) initWithTarget:(Target *)_target{<br />
    self = [super init];<br />
    if (!self) {<br />
        return nil;<br />
    }<br />
    target=_target;<br />
    return self;<br />
}</p>
<p>-(void) setUp{<br />
    int w=self.contentSize.width;<br />
    int h=self.contentSize.height;<br />
    UIImage *img=[UIImage imageNamed:[target getRetina:[NSString stringWithFormat:@"sc0"]]];<br />
    int scw=(img.size.width/[target getScale])/1;<br />
    int sch=(img.size.height/[target getScale]);<br />
    sc1=[CCSprite  spriteWithTexture:[[CCTextureCache sharedTextureCache] addImage:[target getUnRetina:[NSString stringWithFormat:@"sc0"]]] rect:CGRectMake(0, 0, scw,sch)];<br />
    sc2=[CCSprite  spriteWithTexture:[[CCTextureCache sharedTextureCache] addImage:[target getUnRetina:[NSString stringWithFormat:@"sc0"]]] rect:CGRectMake(0, 0, scw,sch)];<br />
    sc3=[CCSprite  spriteWithTexture:[[CCTextureCache sharedTextureCache] addImage:[target getUnRetina:[NSString stringWithFormat:@"sc0"]]] rect:CGRectMake(0, 0, scw,sch)];<br />
    sc4=[CCSprite  spriteWithTexture:[[CCTextureCache sharedTextureCache] addImage:[target getUnRetina:[NSString stringWithFormat:@"sc0"]]] rect:CGRectMake(0, 0, scw,sch)];<br />
    sc5=[CCSprite  spriteWithTexture:[[CCTextureCache sharedTextureCache] addImage:[target getUnRetina:[NSString stringWithFormat:@"sc0"]]] rect:CGRectMake(0, 0, scw,sch)];<br />
    sc6=[CCSprite  spriteWithTexture:[[CCTextureCache sharedTextureCache] addImage:[target getUnRetina:[NSString stringWithFormat:@"sc0"]]] rect:CGRectMake(0, 0, scw,sch)];<br />
    sc1.position=CGPointMake(w-scw,h-sch/2);<br />
    sc2.position=CGPointMake(w-scw*2,h-sch/2);<br />
    sc3.position=CGPointMake(w-scw*3,h-sch/2);<br />
    sc4.position=CGPointMake(w-scw*4,h-sch/2);<br />
    sc5.position=CGPointMake(w-scw*5,h-sch/2);<br />
    sc6.position=CGPointMake(w-scw*6,h-sch/2);<br />
    [self addChild:sc1 z:1];<br />
    [self addChild:sc2 z:1];<br />
    [self addChild:sc3 z:1];<br />
    [self addChild:sc4 z:1];<br />
    [self addChild:sc5 z:1];<br />
    [self addChild:sc6 z:1];<br />
    NSLog(@"score added");<br />
}</p>
<p>-(void) dealloc {<br />
    [super dealloc];</p>
<p>}<br />
@end<br />
</code></p>
<p>the problem is to add the score layer to the main scene so it overlap the game node<br />
I tried in the Game init method:</p>
<p><code><br />
target=[[Target alloc] init];<br />
sclayer=[[ScoreLayer alloc] initWithTarget:target];<br />
[sclayer setUp];<br />
CCScene *scene = [CCScene node];<br />
[scene addChild:[ScoreLayer node] z:1000 tag:SCORE_TAG];<br />
//[scene addChild:sclayer z:1000 tag:SCORE_TAG];</p>
<p></code><br />
i tried adding sclayer and [SCLayer node] without success</p>
<p>Unfortunately the score layer doesn't appear on the top of the game scene<br />
If i add it as a child of the game scene, it shows ok, but unfortunately i have a zoom in the game scene that interfer then with the score layer, so i cannot leave it that way.</p>
<p>Any idea how to add the score layer to the main scene. Many thanks for the help,</p>
<p>Benoit - France
</p></description>
		</item>
		<item>
			<title>nickthedude on "Is there a way to render the layer tree before presenting it onscreen?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21807#post-121111</link>
			<pubDate>Thu, 13 Oct 2011 18:35:30 +0000</pubDate>
			<dc:creator>nickthedude</dc:creator>
			<guid isPermaLink="false">121111@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I am building a layer with several layer one of which the player shouldn't see right away, but the way it's displaying / building itself is displaying the obscured sprite for a split second and I need to fix this, any thoughts? I guess I could hide it until the rest of the top layers are placed but it still looks a little weird, id rather not show it until it's fully rendered.</p>
<p>Thanks for the help.</p>
<p>Nick
</p></description>
		</item>
		<item>
			<title>Thnx4TheXP on "Scale Layer to Keep Body Onscreen???"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21683#post-120493</link>
			<pubDate>Mon, 10 Oct 2011 19:09:27 +0000</pubDate>
			<dc:creator>Thnx4TheXP</dc:creator>
			<guid isPermaLink="false">120493@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Is there a way that I can scale the layer to keep the body to track onscreen? Here is my code to track the body. It is called whenever update is called. I am also using cocos2d 2.0.</p>
<pre><code>-(void)followBody:(b2Body *)b {
	CGSize s = [[CCDirector sharedDirector] winSize];

	b2Vec2 position = b-&#62;GetPosition();

        // boxToCocos is to convert b2vec2 to CGPoint
	CGPoint cgPosition = boxToCocos(position);

	float fixedPosition = s.width/4;
	float newX = fixedPosition - cgPosition.x;

	CGPoint newPos = ccp(newX*self.scale, self.position.y);
	[self setPosition:newPos];
}</code></pre></description>
		</item>
		<item>
			<title>VanTheManiac on "Advice on best practice using Scene and Layers - updating a score layer"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21501#post-119474</link>
			<pubDate>Tue, 04 Oct 2011 06:59:20 +0000</pubDate>
			<dc:creator>VanTheManiac</dc:creator>
			<guid isPermaLink="false">119474@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi,<br />
I'm working on my first Cocos-game and doing progress everyday but I need some advice on how to use layers properly and how to call methods on them.</p>
<p>My game will have several scenes (intro, menu, level1, level2,level3 etc).<br />
On each level scene I'll have one layer handling the gameplay for that level.<br />
I'm thinking on having a ScoreLayer that I put on top on each level-layer to make the score and # lives visible. I'll have a few methods on this layer to do the init and update etc.</p>
<p>Is this the proper way to think about Scene's and Layers?<br />
For example in the Scene init method for level 1:</p>
<p>        level1Layer = [Level1Layer node];<br />
        [self addChild:level1Layer z:5];</p>
<p>        scoreLayer = [ScoreLayer node];<br />
        [self addChild:scoreLayer z:100];</p>
<p>And now for the most important question, how to I call the updateScore-method in ScoreLayer from Level1Layer?
</p></description>
		</item>
		<item>
			<title>Bongeh on "Making a transparent pause menu"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4368#post-26069</link>
			<pubDate>Tue, 09 Feb 2010 09:35:21 +0000</pubDate>
			<dc:creator>Bongeh</dc:creator>
			<guid isPermaLink="false">26069@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I want to make a pause menu that appears when i pause my game.</p>
<p>I understand that there are several things here i can use.</p>
<p>I could 'push' the old scene making my current scene freeze and bringing in a new one</p>
<p>	PauseScene *ps = [PauseScene node];<br />
	[[CCDirector sharedDirector] pushScene:ps];	</p>
<p>the only problem here is the old scene is not left in the background, its hidden away in memory.</p>
<p>I can pause the game using the following command</p>
<p>[[CCDirector sharedDirector] pause];</p>
<p>and then pull in a new layer to the current scene.</p>
<p>although i think touches may pass onto the gamescene that is paused behind and 'stack up' so that when you unpause, it may do lots of things you did not expect.</p>
<p>What is the correct way to do this? or a suggested way that someone has found works and is wiling to share?
</p></description>
		</item>
		<item>
			<title>gyazbek on "[solved] Touches not detected over ccsprite"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21234#post-118071</link>
			<pubDate>Mon, 26 Sep 2011 02:21:18 +0000</pubDate>
			<dc:creator>gyazbek</dc:creator>
			<guid isPermaLink="false">118071@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>The problem I am having is that touches over a specific ccsprite is not being detected.  Since things weren't working, I created a gameLayer and tried on that with no avail. When I output data to the console, it detects all points just outside 200,200. The ccsprite is 50px by 50px (positioned at x=200 y=200). So it doesnt detect between 200x or y, to 250x,y.  I have gotten as close as 199 x. </p>
<p>The code I have is as follows:</p>
<p>HelloWorld.mm</p>
<pre><code>-(id) init
{
	if( (self=[super init])) {

		// add gamelayer
		gameLayer = [CCLayer node];
		gameLayer.isTouchEnabled = YES;
		[self addChild:gameLayer];

                //add clicker
                clickLaunch = [CCSprite spriteWithFile:@&#34;click.png&#34;];
		clickerPoint = ccp(200,200);

                [gameLayer addChild:clickLaunch];
	        [clickLaunch setPosition:clickerPoint];

        }
	return self;

}

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

	UITouch *touch = [touches anyObject];
	CGPoint location = [gameLayer convertTouchToNodeSpace: touch];

	if ([touches count] == 1) {

                        CGPoint locationA = [gameLayer convertTouchToNodeSpace: touch];			

                        // Get the camera&#39;s current values.
			float centerX, centerY, centerZ;

			[gameLayer.camera centerX:&#38;centerX centerY:&#38;centerY centerZ:&#38;centerZ];

                        // I move around my gameLayer, this was the way I could get accurate positions.
			locationA.x = (centerX + locationA.x);
			locationA.y = (centerY + locationA.y); 

			/*

			CGRect rect=CGRectMake((clickLaunch.position.x), (clickLaunch.position.y), 50,50);

			if (CGRectContainsPoint(rect, locationA)) {

                        NSLOG(@&#34;Clicked&#34;);	

                        }

            }

}</code></pre>
<p>HelloWorld.h declaration<br />
<pre><code>@interface HelloWorld : CCLayer //&#60;CCTargetedTouchDelegate&#62;
{

	CGPoint clickerPoint;
	CCSprite *clickLaunch;

	/* layers */
	CCLayer *gameLayer;

}</code></pre>
<p>I have a feeling I did a very stupid mistake. Any help would be appreciated :)</p>
<p>Thanks</p>
<p>-Gui
</p></description>
		</item>
		<item>
			<title>user0001 on "Attach .mov in CCNode, not on OpenGLView"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/9220#post-53251</link>
			<pubDate>Wed, 01 Sep 2010 18:39:28 +0000</pubDate>
			<dc:creator>user0001</dc:creator>
			<guid isPermaLink="false">53251@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi,<br />
is there a way to attach a movie (MPMoviePlayer) within a cocos2d node vs. on top in its OpenGLView? if i attach the MPMoviePlayer like so:</p>
<p>[[[CCDirector sharedDirector] openGLView] addSubview:myMPMoviePlayer]; </p>
<p>i have layering (z depth) problems between my video and other CCSprites and also the video doesn't animate along with my scene transitions, since its sitting on top of everything.</p>
<p>thanks!<br />
Jer
</p></description>
		</item>
		<item>
			<title>diegof18 on "sneaky joystick inside a layer not gettin touch event??? why???"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12983#post-72662</link>
			<pubDate>Wed, 26 Jan 2011 19:18:16 +0000</pubDate>
			<dc:creator>diegof18</dc:creator>
			<guid isPermaLink="false">72662@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>hi, im a newbe and my english its a little lame. but hopefully someone will have pitty of my soul and help understand this.</p>
<p>i have my game layer that it is touchenabled inside my scene. and its working. i have somen menus there, and use to have seakyjoy added directly to the scene and working too. but now i need to add my sneakyJoy to the game layer that have been previosly added to the scene. i can see my joy but i cant touch it.??? </p>
<p>inputLayer = [InputLayer node];<br />
		[self addChild:inputLayer z:999999999999999999 tag:6002];<br />
		inputLayer.position = ccp(-90,11);<br />
		//self.isTouchEnabled = YES;<br />
		//inputLayer.isTouchEnabled = YES;<br />
		[self setIsTouchEnabled:YES];<br />
		[inputLayer setIsTouchEnabled:YES];<br />
		//check control not responding!!!<br />
///////////////////////////////////////////////////////////////////////////////////////<br />
this was set on my appdelegate in order to make layers added to the schene touchenabled<br />
[view setMultipleTouchEnabled:YES];</p>
<p>and afeter that i just add layers to the scene and work...<br />
thanks in advance!
</p></description>
		</item>
		<item>
			<title>mruffa on "replaceScene - problem"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18931#post-106147</link>
			<pubDate>Thu, 21 Jul 2011 08:16:11 +0000</pubDate>
			<dc:creator>mruffa</dc:creator>
			<guid isPermaLink="false">106147@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey </p>
<p>When I call replaceScene I got only white blank view. All things like Network stuff, touch callbacks are working, but Cocos seems to have problem with displaying graphics on Layer. My Class inherites CClayer.</p>
<p>I use Cocos2D 1.0.0. Can anybody please help me with that? :)</p>
<p>thanks!
</p></description>
		</item>
		<item>
			<title>zhangxi_1989 on "should i move the layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/19866#post-111078</link>
			<pubDate>Wed, 17 Aug 2011 16:52:27 +0000</pubDate>
			<dc:creator>zhangxi_1989</dc:creator>
			<guid isPermaLink="false">111078@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>hi,</p>
<p>i am developing a game with cocos2D.</p>
<p>sometimes , i want to move a large of sprites, should i move the layer? or i should add all this sprites into a parent node,than move the parent node.</p>
<p>i mean is it right to move the layer?
</p></description>
		</item>
		<item>
			<title>cocos2dbeginner on "What&#039;s better? CCFollow or CCCamera?? And how can I use CCCamera?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12632#post-70919</link>
			<pubDate>Sat, 15 Jan 2011 17:30:57 +0000</pubDate>
			<dc:creator>cocos2dbeginner</dc:creator>
			<guid isPermaLink="false">70919@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi,</p>
<p>what's better? CCFollow or CCCamera? How does both work? <strong>Are they only moving the ´layer' or are they really moving the 'camera' </strong>? Does the touch detecting get messed up with cccamera? </p>
<p><strong>How can I use CCCamera?<br />
</strong><br />
I know I have many questions :) But if someone could answer me my questions it would be great :D</p>
<p>Thank you very much!</p>
<p>:)
</p></description>
		</item>
		<item>
			<title>phantomsri on "loading scene problem"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/17260#post-97203</link>
			<pubDate>Sat, 04 Jun 2011 15:17:35 +0000</pubDate>
			<dc:creator>phantomsri</dc:creator>
			<guid isPermaLink="false">97203@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi, I have a game, with 2 layer.<br />
the first layer there is 2 icons, when i touch the first icon it will load the second layer(game layer) with tilemap one.<br />
when i touch the second icon it will load the second layer with tilemap two.</p>
<p>i have created </p>
<pre><code>-(void) tileMapOne
{
//tile map first level code
}

-(void) tileMapTwo
{
//tile map second level code
}</code></pre>
<p>I have used this code to load the scene<br />
<pre><code>GameScene *gameOverScene = [GameScene node];
        [[CCDirector sharedDirector] replaceScene:gameOverScene];</code></pre>
<p>My questions is, is there a way to write a code where when i load the new scene it can load the -(void) tileMapOne method when click icon 1. and when i click icon 2 it loads<br />
the new scene with -(void) tileMapTwo.</p>
<p>i hope some one can advice me coz im a little new to cocos2d
</p></description>
		</item>
		<item>
			<title>petemyster on "How do you convert absolute co-ordinates to co-ordinates on a scaled layer"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/19190#post-107598</link>
			<pubDate>Thu, 28 Jul 2011 14:39:59 +0000</pubDate>
			<dc:creator>petemyster</dc:creator>
			<guid isPermaLink="false">107598@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey, </p>
<p>I have a layer which is scaled, and I want to be able to click on the screen and it gets the co-ordinates of that click on the layer which could be scaled by any decimal, and return it as the co-ordinates in that layer instead of the co-ordinates on the main screen.</p>
<p>Can anyone help me? Thanks
</p></description>
		</item>

	</channel>
</rss>

