<?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: menu - Recent Topics</title>
		<link>http://www.cocos2d-iphone.org/forum/tags/menu</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:47:57 +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/menu/topics" rel="self" type="application/rss+xml" />

		<item>
			<title>beleg on "Amazing breaker style buttons effects"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28422#post-139886</link>
			<pubDate>Tue, 17 Jan 2012 17:15:58 +0000</pubDate>
			<dc:creator>beleg</dc:creator>
			<guid isPermaLink="false">139886@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Anyone have any suggestions for getting CoCos2d to do the button effects on the free amazing breaker game? I really like how when you hit the play button the particles flash across the screen but I am not exactly sure how to implement the effect. Thanks
</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>ranT4 on "CCMenuItemImage button is not responding."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/27963#post-137324</link>
			<pubDate>Fri, 30 Dec 2011 11:24:14 +0000</pubDate>
			<dc:creator>ranT4</dc:creator>
			<guid isPermaLink="false">137324@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>buttons and menu are on screen but nothing happen when buttons pushed:</p>
<p>'<br />
   CCMenuItemImage *menuB = [CCMenuItemImage itemFromNormalImage:@"menuB.png" selectedImage:@"menuB.png" target:self selector:@selector(goMenu:)];<br />
    CCMenuItemImage *tryAgainB = [CCMenuItemImage itemFromNormalImage:@"tryAgainB.png" selectedImage:@"tryAgainB.png" target:self selector:@selector(tryAgain:)];<br />
    CCMenuItemImage *menuGoodByeT = [CCMenuItemImage itemFromNormalImage:@"menu.png" selectedImage:@"menu.png" target:self selector:@selector(nothing:)];</p>
<p>    menuB.position=ccp(-65,-40);<br />
    tryAgainB.position=ccp(15,-40);</p>
<p>    menu = [CCMenu menuWithItems:menu,menuB,tryAgainB, nil];<br />
     menu.isTouchEnabled = YES;<br />
    [self addChild: menu];<br />
'</p>
<p>yes, the method is having : id sender .<br />
whats wrong with this menus ?? it some how always has problems.
</p></description>
		</item>
		<item>
			<title>tiggybouncer on "Error Message help!"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/25247#post-131478</link>
			<pubDate>Sun, 04 Dec 2011 17:52:44 +0000</pubDate>
			<dc:creator>tiggybouncer</dc:creator>
			<guid isPermaLink="false">131478@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I've got an error message in my app, which is: '@synthesize property must be in implementation context'<br />
It is declared in my .h file, and I've done lots of googling. Why isn't it working?</p>
<p>Here is my code (.m file):</p>
<pre><code>#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;MainMenuScene.h&#34;

@implementation MainMenuScene

-(id)init
{
	self = [super init];
	if (self != nil)
	{
		[self addChild:[MainMenuLayer node]];
	}
	return self;
}

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

@end

@synthesize isTouchEnabled,gameScene2; //error is here :/

@implementation MainMenuLayer

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

		CCSprite * menuBackground = [CCSprite spriteWithFile:@&#34;menuBackground.png&#34;];
		[menuBackground setPosition:ccp(240,160)];
		[self addChild:menuBackground];

		CCLabelBMFont * startGameLabel = [CCLabelBMFont labelWithString:@&#34;Start Game&#34; fntFile:@&#34;menuFont.fnt&#34;];

		CCLabelBMFont * optionsLabel = [CCLabelBMFont labelWithString:@&#34;Options&#34; fntFile:@&#34;menuFont.fnt&#34;];

		CCLabelBMFont * aboutLabel = [CCLabelBMFont labelWithString:@&#34;About&#34; fntFile:@&#34;menuFont.fnt&#34;];

		[startGameLabel setColor:ccRED];
		[optionsLabel setColor:ccRED];
		[aboutLabel setColor:ccRED];

		CCMenuItemLabel * menu = [CCMenu menuWithItems:startGameLabel,optionsLabel,aboutLabel,nil];
		[menu alignItemsVerticallyWithPadding:5];
		[self addChild:menu];
		[menu setPosition:ccp(240,120)];
	}
	return self;
}

-(void)startGameLabel:(id)sender
{
	gameScene2 = [gameScene2 node];
	[[CCDirector sharedDirector]replaceScene:gameScene2];
}

-(void)optionsLabel:(id)sender
{

}

-(void)aboutLabel:(id)sender
{

}

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

@end</code></pre>
<p>And my .h file:</p>
<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 MainMenuScene : CCScene
{

}

@end 

@interface MainMenuLayer : CCLayer
{
	BOOL isTouchEnabled;
	CCScene * gameScene2;
}

@property(readwrite, assign)BOOL isTouchEnabled;
@property(nonatomic, retain)CCScene * gameScene2;

@end</code></pre>
<p>Thanks
</p></description>
		</item>
		<item>
			<title>roko on "How to get touch position on the CCMenuItemImage?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/14150#post-79875</link>
			<pubDate>Thu, 03 Mar 2011 10:54:44 +0000</pubDate>
			<dc:creator>roko</dc:creator>
			<guid isPermaLink="false">79875@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi all! Can anybody explain me how i can get touch position in a button(CCMenuItemImage) in the selector method?</p>
<p>for example i have this snippet of code:<br />
<pre><code>CCMenuItemImage *myMenuItem = [CCMenuItemImage itemFromNormalImage:imageNormal
							selectedImage:imageSelected
							disabledImage:imageDisable
								target:self
								selector:@selector(myMenuItemWasOn)];

	CCMenu *myMenu = [CCMenu menuWithItems:myMenuItem,nil];
	[self addChild:myMenu z:100];
	[myMenu setPosition:CGPointMake(200, 200)];</code></pre>
<p>then after i have pressed the button method "myMenuItemWasOn" will be called:</p>
<pre><code>- (void) myMenuItemWasOn
{
	CGPoint touchPos =  ?//how to get touch pos here?
}</code></pre></description>
		</item>
		<item>
			<title>Zero07 on "Add CCMenu to CCSpriteBatchNode"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22948#post-126858</link>
			<pubDate>Sat, 19 Nov 2011 05:51:56 +0000</pubDate>
			<dc:creator>Zero07</dc:creator>
			<guid isPermaLink="false">126858@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>From my research the answer is no.  Can someone confirm this.  If I can't do this, is there any way I can layer the menu to be in between the sprites in the sprite batch?
</p></description>
		</item>
		<item>
			<title>Joe Henry on "MenuItem FadeIn glitch?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/3413#post-20927</link>
			<pubDate>Mon, 14 Dec 2009 15:20:27 +0000</pubDate>
			<dc:creator>Joe Henry</dc:creator>
			<guid isPermaLink="false">20927@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey people,</p>
<p>I am making a simple game and in my first scene (my main menu scene) I'm trying to fade my menu items in like so:</p>
<p><code>settings = [MenuItemImage itemFromNormalImage:@"settings.png" selectedImage:@"settings.png" target:self selector:@selector(settingsScene:)];<br />
settings.position = ccp(-130, 210);<br />
settings.rotation = 340;<br />
[settings runAction:[FadeIn actionWithDuration:1.0f]];</code></p>
<p>I later add the settings object to a menu object.</p>
<p>My problem with this is that when I first launch my app the settings icon displays at full opacity and then it gets to the fade code so the icon disappears and then fades back in.  I'd like it to just start with 0 opacity and fade in.</p>
<p>Any answers are welcome =]</p>
<p>- Joe
</p></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>Dynex on "How to retrieve which button was pressed?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22187#post-123210</link>
			<pubDate>Thu, 27 Oct 2011 02:24:42 +0000</pubDate>
			<dc:creator>Dynex</dc:creator>
			<guid isPermaLink="false">123210@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Say I have 2 buttons, and they both call highlightAmmo:<br />
How would I check to see which button was pressed?<br />
<pre><code>grapeDD = [CCMenuItemSprite
				 itemFromNormalSprite:[CCSprite spriteWithSpriteFrameName:@&#34;grapeDD.png&#34;]
				 selectedSprite:[CCSprite spriteWithSpriteFrameName:@&#34;grapeDD.png&#34;]
				 target:self
				 selector:@selector(highlightAmmo:)];

rockDD = [CCMenuItemSprite
				 itemFromNormalSprite:[CCSprite spriteWithSpriteFrameName:@&#34;rockDD.png&#34;]
				 selectedSprite:[CCSprite spriteWithSpriteFrameName:@&#34;rockDD.png&#34;]
				 target:self
				 selector:@selector(highlightAmmo:)];

- (void) highlightAmmo: (CCMenuItem  *) menuItem {
NSLog(@&#34;Ammo highlighted&#34;);
}</code></pre></description>
		</item>
		<item>
			<title>ManFromKemerovo on "Best way stop scene and show menu?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21989#post-122201</link>
			<pubDate>Thu, 20 Oct 2011 08:20:21 +0000</pubDate>
			<dc:creator>ManFromKemerovo</dc:creator>
			<guid isPermaLink="false">122201@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi.<br />
I have "game scene" with actions.<br />
I need stop "game scene" actions, and show menu.</p>
<p>Like on image:<br />
<img src="http://img28.imageshack.us/img28/4323/howdd.png" /><br />
What the best way to do this?<br />
Sorry, if question very stupid, I'm novice in cocos2d and gamedev.
</p></description>
		</item>
		<item>
			<title>darkhunter on "CCMenuItems not working!"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21924#post-121840</link>
			<pubDate>Tue, 18 Oct 2011 09:55:56 +0000</pubDate>
			<dc:creator>darkhunter</dc:creator>
			<guid isPermaLink="false">121840@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi to all!</p>
<p>After i establish a local peer to peer connection and then come back to the main menu, the CCMenuItems do not respond right how they did in the first launch after loading process! Even if I simply call replaceScene.</p>
<p> I point out that they still works in some ways, just changed touch region center positions, but in a random way, if the images are still in correct points.</p>
<p>-&#62; Strange fact is this happen only after a succeed local connection.</p>
<p>I tried purge memory, dealloc instances of items before pass to scenes, but same problem.</p>
<p>Hope you can help me, thanks in advance!
</p></description>
		</item>
		<item>
			<title>darkhunter on "Bad CCMenuItems behavior! replaceScene makes them to perform random selector"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21921#post-121820</link>
			<pubDate>Tue, 18 Oct 2011 08:55:43 +0000</pubDate>
			<dc:creator>darkhunter</dc:creator>
			<guid isPermaLink="false">121820@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi to all! i am in desperation on a thing i believe a bug, and hope you can help me!</p>
<p>FACTS: i never meet this before. after i establish a local peer to peer connection and then come back to the main menu, the CCMenuItems do not respond right how they did in the beginning! Even if I simply call replaceScene. I point out that there still works in some ways, just random touch effect positions in the screen even if the images are still in correct points.</p>
<p>-&#62; Strange fact is this happen only after a succeed local connection. </p>
<p>I tried purge memory, dealloc instances of items before pass to scenes, but same problem.</p>
<p>this is extract from iPad piece<br />
<pre><code>CCMenuItem *item1 = [CCMenuItemImage itemFromNormalImage:@&#34;menu_wifi_mod.png&#34; selectedImage:@&#34;menu_wifi_mod.png&#34; target:self selector:@selector(wifi:)];
            item1.position = ccp(420,610);
            item1.tag = kTagMenuButton1;

            CCMenuItem *item2 = [CCMenuItemImage itemFromNormalImage:@&#34;menu_singola_mod.png&#34; selectedImage:@&#34;menu_singola_mod.png&#34; target:self selector:@selector(singola:)];
            item2.position = ccp(420,520);
            item2.tag = kTagMenuButton2;

            CCMenuItem *item3 = [CCMenuItemImage itemFromNormalImage:@&#34;menu_online.png&#34; selectedImage:@&#34;menu_online.png&#34; target:self selector:@selector(goOnline:)];
            item3.position = ccp(420,280);
            item3.tag = kTagMenuButton3;

            CCMenuItem *item4 = [CCMenuItemImage itemFromNormalImage:@&#34;menu_credits_mod.png&#34; selectedImage:@&#34;menu_credits_mod.png&#34; target:self selector:@selector(credits:)];
            item4.position = ccp(780,610);
            item4.tag = kTagMenuButton4;

            CCMenuItem *item5 = [CCMenuItemImage itemFromNormalImage:@&#34;menu_regolamento_mod.png&#34; selectedImage:@&#34;menu_regolamento_mod.png&#34; target:self selector:@selector(regolamento:)];
            item5.position = ccp(780,520);
            item5.tag = kTagMenuButton5;

            CCMenuItem *item6 = [CCMenuItemImage itemFromNormalImage:@&#34;menu_istruzioni.png&#34; selectedImage:@&#34;menu_istruzioni.png&#34; target:self selector:@selector(istruzioni:)];
            item6.position = ccp(780,280);
            item6.tag = kTagMenuButton6;

            CCMenuItem *item7 = [CCMenuItemImage itemFromNormalImage:@&#34;opzioni_btn.png&#34; selectedImage:@&#34;opzioni_btn.png&#34; target:self selector:@selector(opzioni:)];
            item7.position = ccp(50,50);
            item7.tag = kTagMenuButton7;

            CCMenu *menu = [CCMenu menuWithItems:item1, item2, item3, item4, item5, item6, item7, nil];
            menu.position = CGPointZero;
            [self addChild:menu z:2 tag:kTagMainMenu];</code></pre>
<p>-----------------</p>
<p>And then i call from another view</p>
<pre><code>-(void)goBack {
    [lobbyScreen release];
    lobbyScreen=nil;
    [lobbyView removeFromSuperview];
    [lobbyView release];
    lobbyView = nil;

    [[CCDirector sharedDirector] replaceScene:[CCTransitionCrossFade transitionWithDuration:0.5 scene:[MenuLayer scene]]];
}</code></pre></description>
		</item>
		<item>
			<title>mserougi on "Vertical sliding/popping menu"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/16244#post-91592</link>
			<pubDate>Wed, 04 May 2011 21:31:37 +0000</pubDate>
			<dc:creator>mserougi</dc:creator>
			<guid isPermaLink="false">91592@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello,</p>
<p>I'm looking into doing a menu similar to the one from Angry Birds settings button on the main screen. Originally I wanted to do a popover but I wanted a sliding effect, instead of a fade in/out.</p>
<p>It seems some sort of transparent stretchable graphic is being used which doesn't distort if vertically stretched from an initial height less than that of the button hiding it.</p>
<p>Is that assumption correct? And if so then what about the menu items, they don't look like they are part of the graphic and are only added when there is enough space to hold any one item.</p>
<p>Thoughts?
</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>Krillere on "Clicking through HUD"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/20967#post-116484</link>
			<pubDate>Sat, 17 Sep 2011 14:42:33 +0000</pubDate>
			<dc:creator>Krillere</dc:creator>
			<guid isPermaLink="false">116484@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey guys :-)</p>
<p>I made a HUD layer for my game, and it's working just fine.<br />
I made a drag-button on my HUD, so you can drag some of the interface around. But when I let go of the touch, the game-layer catches the touch, and 'ccTouchesEnded' is called, moving my character.</p>
<p>I don't want the player to move, after moving the menu around, OFC.<br />
Any good ideas for a solution? :-)
</p></description>
		</item>
		<item>
			<title>Jamorn on "Sortable and Droppable Menu &amp; Menu Items"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/3009#post-18600</link>
			<pubDate>Sun, 15 Nov 2009 12:42:48 +0000</pubDate>
			<dc:creator>Jamorn</dc:creator>
			<guid isPermaLink="false">18600@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey guys, I'm currently toying with an idea of creating a class to handle a sortable menu something akin to the Mac OS X doc. This feature would make my game extremely user-friendly and add to the experience tremendously but right now I'm wondering if the current cocos classes can be extended to perform this function.</p>
<p>I am thinking of using the Menu and MenuItemAtlasSprite classes for this but not too sure if it'll be a problem later on. Anybody have any suggestions? In the mean time I'll go ahead and start writing it out and will probably share the finished code once it's done so other people who need this class can make use of it.
</p></description>
		</item>
		<item>
			<title>aeshverma on "menu like angry birds?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/12136#post-68399</link>
			<pubDate>Mon, 27 Dec 2010 06:09:53 +0000</pubDate>
			<dc:creator>aeshverma</dc:creator>
			<guid isPermaLink="false">68399@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have managed to do like this:(using uiscrollview)<br />
<img src="http://www.downloadatoz.com/resources/201012/pic/1291604242.jpg" alt="menu" /></p>
<p>But how to put many selectable sprites like this?<br />
<img src="http://www.androidpolice.com/wp-content/uploads/2010/10/snap20101020_085838_wm.png" alt="menu1" />
</p></description>
		</item>
		<item>
			<title>Daniel López on "PushScene, Then PopScene"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/20638#post-114699</link>
			<pubDate>Tue, 06 Sep 2011 23:05:00 +0000</pubDate>
			<dc:creator>Daniel López</dc:creator>
			<guid isPermaLink="false">114699@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi all. I'm having troubles... In game layer, I need to show up a configuration menu, so this is a new Scene which I call with PushScene. In the configuration Scene, I can comeback to the game (with pop scene works perfectly) or, exit to main menu...</p>
<p>I am having troubles, because if I do "replace scene: main menu" I am leaking the poped scene. If I do:</p>
<p>pop scene<br />
replace scene</p>
<p>It doesn't deallocate the poped scene, but this:</p>
<p>pop scene<br />
pop scene<br />
replace scene</p>
<p>Deallocate it, but it crashes somewhere...</p>
<p>How to achieve this effect?
</p></description>
		</item>
		<item>
			<title>bebroll on "glScissor coordinates"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/3993#post-23924</link>
			<pubDate>Thu, 21 Jan 2010 20:41:12 +0000</pubDate>
			<dc:creator>bebroll</dc:creator>
			<guid isPermaLink="false">23924@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi all!</p>
<p>As has been posted in a couple of other threads, glScissor is a great means to clip a screen region and only have the elements within the clip rectangle be rendered.</p>
<p>I've recently been struggling with the exact coordinate transformations to make glScissor clip the region I specify. I'm trying to create a Viewport class which takes a CGRect in current view coordinates which is supposed to represent the clipping rect. Now how exactly do I have to convert my rectangle's coordinates for glScissor to perform correctly - independent of device rotation.</p>
<p><code>glEnable(GL_SCISSOR_TEST);</code><br />
<code>CGRect clip = // ...</code><br />
<code>// how to transform clip ?</code><br />
<code>glScissor(clip.origin.x, clip.origin.y, clip.size.width, clip.size.height);</code><br />
<code>[super visit];</code><br />
<code>glDisable(GL_SCISSOR_TEST);</code></p>
<p>Thanks for your insights!</p>
<p>Cheers, Ben
</p></description>
		</item>
		<item>
			<title>CodeSlayer on "Menu Bar Sprite - Determining which button pressed"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/20473#post-113846</link>
			<pubDate>Thu, 01 Sep 2011 13:39:59 +0000</pubDate>
			<dc:creator>CodeSlayer</dc:creator>
			<guid isPermaLink="false">113846@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have an <code>AdornableMenuItemImage</code> (See CC3DemoMashUp) in my layer that I want to use for menu items. I can do this fine for simple buttons but I want to put a strip of buttons and detect when a particular button on the strip has been pressed. Is there a way to assign a selector to a specific <code>CGRect</code> on the menu bar sprite or detect in the <code>nodeSelected</code> selector ?
</p></description>
		</item>
		<item>
			<title>nospam4me on "SimpleAudioEngine playEffect: with a callback"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/13474#post-75662</link>
			<pubDate>Fri, 11 Feb 2011 12:46:41 +0000</pubDate>
			<dc:creator>nospam4me</dc:creator>
			<guid isPermaLink="false">75662@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi,<br />
I'm playing sounds using SimpleAudioEngine playEffect:.<br />
Everythings works fine, except that's I need to know when the sound is finished.<br />
Is there a simple way to be notified when the playing is finished ?<br />
Something like :<br />
SimpleAudioEngine playEffect:(NSString*)file withTarget:(id)target andCallback:(SEL)callback<br />
Thanks.
</p></description>
		</item>
		<item>
			<title>jackrabbit on "Creating a carousel type menu?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/19978#post-111506</link>
			<pubDate>Fri, 19 Aug 2011 21:49:34 +0000</pubDate>
			<dc:creator>jackrabbit</dc:creator>
			<guid isPermaLink="false">111506@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Does anyone have any tips on how to accomplish this? Something like : <a href="http://www.collegehumor.com/video/6585969/jake-and-amir-talent-show" rel="nofollow">http://www.collegehumor.com/video/6585969/jake-and-amir-talent-show</a></p>
<p>Do I need to wrap a menu around a box2d ball or something? I'm trying to think of a clever way to accomplish this..
</p></description>
		</item>
		<item>
			<title>Stepan Generalov on "CCMenuAdvanced - Alternative, compatible with original CCMenu"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/14095#post-79459</link>
			<pubDate>Tue, 01 Mar 2011 17:15:12 +0000</pubDate>
			<dc:creator>Stepan Generalov</dc:creator>
			<guid isPermaLink="false">79459@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi, Cocos Community!</p>
<p>Just want to share with you my CCMenu subclass that i use in iTraceur for all menus.<br />
It's pretty simple and can be easily merged into CCMenu, but it must be prepared for it, so i'll just leave it here and if you will improve it - send it me, make a pull request to cocos2d or just share with others.</p>
<p><a href="https://github.com/psineur/CCMenuAdvanced" rel="nofollow">https://github.com/psineur/CCMenuAdvanced</a></p>
<p>Cheers!
</p></description>
		</item>
		<item>
			<title>hamstachasa on "How to create a scrolling menu within a scene?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/19341#post-108378</link>
			<pubDate>Tue, 02 Aug 2011 04:56:56 +0000</pubDate>
			<dc:creator>hamstachasa</dc:creator>
			<guid isPermaLink="false">108378@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I am trying to create a menu that the user can scroll through like:</p>
<p><a href="http://www.cocos2d-iphone.org/forum/topic/9417" rel="nofollow">http://www.cocos2d-iphone.org/forum/topic/9417</a></p>
<p>I was able to recreate this, but I would like for it to be</p>
<p>1. Smaller than the whole layer that it is in<br />
2. Vertical scrolling</p>
<p>Does anyone have any advice on the first (embedding it in a layer but not having the whole layer scroll)? Thanks!
</p></description>
		</item>
		<item>
			<title>mkrn on "Menu events"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/1170#post-7067</link>
			<pubDate>Fri, 07 Aug 2009 01:33:25 +0000</pubDate>
			<dc:creator>mkrn</dc:creator>
			<guid isPermaLink="false">7067@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have a serious problem here, and I think it's Menu class's fault.</p>
<p>In my game on it's layer (which is touch-enabled) I have a couple of menu layers (for restart when you've won or lost) </p>
<p>These menus are getting touches even if they're zOrdered to -1 or set visible = NO  or set to some far position, no matter what.  </p>
<p>So when you play you could accidentally hit that invisible menu and it would work.</p>
<p>I even went to menu.m code and tried to set   if(self.visible) on all the events.<br />
I think the problem is with<br />
	[[TouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:INT_MIN+1 swallowsTouches:YES];<br />
 In menu.m:176 </p>
<p>Please give some advice as to how to disable them for when they're invisible (i.e. game is in progress) </p>
<p>Cocos2d 0.8
</p></description>
		</item>
		<item>
			<title>thechanger on "Sliding / pop-out style menu"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18722#post-105066</link>
			<pubDate>Fri, 15 Jul 2011 10:17:31 +0000</pubDate>
			<dc:creator>thechanger</dc:creator>
			<guid isPermaLink="false">105066@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I'm not yet familiar with all of Cocos2D functions, and I'm wondering if a certain effect is available or easily done.</p>
<p>The effect that I'm trying to recreate can best be seen in Air Penguin (Also a lite version). On the homescreen, tapping the settings button slides out a mini-panel.</p>
<p><img src="http://oi54.tinypic.com/2vxlvr7.jpg" alt="Air Penguin" /></p>
<p>If I was to animate a panel after tapping a button, what sort of container could I best use to hold the other buttons.</p>
<p>Thanks
</p></description>
		</item>
		<item>
			<title>petemyster on "[Tutorial] How to make a looping menu the noobish way (easy for new comers)"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/19043#post-106794</link>
			<pubDate>Sun, 24 Jul 2011 16:42:13 +0000</pubDate>
			<dc:creator>petemyster</dc:creator>
			<guid isPermaLink="false">106794@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>So, I have tried a lot of times to find good material about this. There are so many threads asking for help about this, and a lot of them have solutions but when you go to put it together or open their projects its all so outdated and filled with warnings and errors.</p>
<p> They are also really complicated, so someone who's new like me doesn't understand it at all and so it sort of becomes a black box. So I thought I'd come up with my own solution. All the code is fully commented and explained.</p>
<p>I'm new to cocos2d so i'm doing a blog about the common mistakes people new to cocos2d/xcode could make, and solutions to them to help save people some time. If anyone new is interested, they can follow me on twitter where I post links to new blog posts   <a href="http://twitter.com/#!/Ant_Run"></a>    <a href="http://tinyurl.com/4xvmojl" rel="nofollow">http://tinyurl.com/4xvmojl</a></p>
<pre><code>//
//  test
//
//  Created by petemyster on 21/07/2011.
//  Copyright petemyster. All rights reserved.
//

// Import the interfaces
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;easyLevelSelect.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;difficultySelectLayer.h&#34;

// easyLevelSelect implementation
@implementation easyLevelSelect

@synthesize beginTouchPoint, movingTouchPoint, originPoint;
@synthesize arrayOfLevels, numOfLevels, differencePoint, retardationNum, spacingBetweenLevels;

+(CCScene *) scene
{
	// &#39;scene&#39; is an autorelease object.
	CCScene *scene = [CCScene node];

	// &#39;layer&#39; is an autorelease object.
	easyLevelSelect *layer = [easyLevelSelect node];

	// add layer as a child to scene
	[scene addChild: layer];

	// return the scene
	return scene;
}

// on &#34;init&#34; you need to initialize your instance
-(id) init
{
    if( (self=[super init])) {
        self.isTouchEnabled = YES;

        //add the images for the looping menu

        //set the number of levels
        numOfLevels = 7;

        //the space between the images (image size + spacing you want)
        spacingBetweenLevels = 150;

        //allocate memory for the mutable array, do initwithcapacity because just init has problems sometimes
        arrayOfLevels = [[NSMutableArray alloc] initWithCapacity:1];

        for(int i = 0; i &#60; numOfLevels; i++)
        {
            //loop through all the levels, creating a sprite and the specified image
            //uses stringwithformat, the %d is replaced with the number of the loop +1, because my image numbers start at number 1
            CCSprite * item = [CCSprite spriteWithFile:[NSString stringWithFormat:@&#34;testPicPreview-%d.png&#34;, i+1] ];

            //set the position of the sprite. mine start off on the far right of the screen (320) then are spaced according to my spacing and the number of sprites that have appeared before it
            item.position = ccp(320 +((i-1)*spacingBetweenLevels), 150);

            //set a tag for the sprite so we can identify it later
            item.tag = i+1;

            //add the sprite to the view
            [self addChild:item];

            //add sprite to array so we can cycle through all sprites later
            [arrayOfLevels addObject:item];
        }
        //this is the slowing amount for when scrolling through the menu, see later
        retardationNum = 1.0;

        //this constantly checks for movement and moves the menu
        [self schedule:@selector(accelerateLabel) interval:0.05];

	}
	return self;
}

-(void) accelerateLabel{

    //if is it moving ridicously slowly, stop it
    if (fabs(differencePoint.x) &#60; 1) {

        differencePoint.x = 0;
    }

    //if the menu is moving
    if (differencePoint.x !=0) {

        //if its moving ridiclously fast, slow it down
        if (fabs(differencePoint.x) &#62; 30) {

            differencePoint.x = differencePoint.x * 0.75;
        }

        //if it is moving to the right, slow it down
        if (differencePoint.x &#62;0) differencePoint.x -=retardationNum;

        //if its moving to the left, slow it down
        if (differencePoint.x &#60;0) differencePoint.x +=retardationNum;

        //move the menu by the &#34;strength&#34; of the swipe
        [self moveMenuItem:differencePoint.x];

    }
    //reset variables
    else
    {
        differencePoint = ccp(0, 0);
    }

}

-(void) callMe:(CCSprite*) sender{
    //takes the tag of the sprite that was selected, and checks for an appropiate action
    switch (sender.tag) {
            case 1:NSLog(@&#34;lol&#34;);
            break;
            case 2: NSLog(@&#34;lol 2&#34;);
            break;
            case 3:[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:0.5 scene:[difficultySelectLayer scene]]];
            break;
//etc etc etc
    }
}

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

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

    //gets the touch location on the screen
    beginTouchPoint= [touch locationInView: [touch view]];
    beginTouchPoint = [[CCDirector sharedDirector] convertToGL:beginTouchPoint];
    beginTouchPoint = [self convertToNodeSpace:beginTouchPoint];

    //store the very first starting point, we will need this later as beginTouchPoint is changed throughout
    originPoint = beginTouchPoint;
    return true;
}

-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event{

    //get the point that the player is currently pressing as they move
    movingTouchPoint = [self convertTouchToNodeSpace:touch];

    //get the difference of positions between the last touch point, and the current move point
    differencePoint = ccpSub(beginTouchPoint, movingTouchPoint);

    //set the last touch point to equal the current, so the line of code above is always subtracting the latest points next time it is called
    beginTouchPoint = movingTouchPoint;
}

-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event{

    //get the position of the final touch
    CGPoint locationPressed = [touch locationInView: [touch view]];
    locationPressed = [[CCDirector sharedDirector] convertToGL:locationPressed];

    //subtract the final touch location from the very first touch location
    CGPoint difference = ccpSub(originPoint, locationPressed);

    //if the distance between the points was very small, the player is wanting to press the button instead of finishing their swipe
    if (fabs(difference.x) &#60;15) {

        //cycle through our array of sprites
        for (int i = 0; i &#60; numOfLevels; i++) {

            CCSprite * item = [arrayOfLevels objectAtIndex:i];

               // if the location that the player touched is within the sprites picture...
            if (CGRectContainsPoint(item.boundingBox, locationPressed)) {

              // call the function that will find the specific action for that sprite
                [self callMe:item];
            }
        }
    }
}

-(void) moveMenuItem:(float) velocity{
    //defining the first sprite in the array and the last sprite of the array
    CCSprite * testBoundItemMax = [arrayOfLevels objectAtIndex:numOfLevels-1];
    CCSprite * testBoundItemMin = [arrayOfLevels objectAtIndex:0];

     //allow movement of the sprites as long as they don&#39;t go off screen
    if (((velocity&#62;0) &#38;&#38; (testBoundItemMax.position.x&#62; 225)) &#124;&#124; ((velocity&#60;0) &#38;&#38; (testBoundItemMin.position.x&#60; 225))) {

        for(int i = 0; i &#60; numOfLevels; i++)
        {
            //move the sprites one by one
            CCSprite * item = [arrayOfLevels objectAtIndex:i];
            item.position = ccp(item.position.x + (-velocity), item.position.y);

        }
    }

}

// on &#34;dealloc&#34; you need to release all your retained objects
- (void) dealloc
{
	// in case you have something to dealloc, do it in this method
	// in this particular example nothing needs to be released.
	// cocos2d will automatically release all the children (Label)

	// don&#39;t forget to call &#34;super dealloc&#34;

    //loop menu

    [arrayOfLevels release];
	[super dealloc];
}
@end</code></pre>
<p>and....<br />
<pre><code>//  test
//
//  Created by petemyster on 21/07/2011.
//  Copyright petemyster. All rights reserved.
//

// When you import this file, you import all the cocos2d classes
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;cocos2d.h&#34;

@interface easyLevelSelect : CCLayer
{
    //set up the looping menu
    CGPoint beginTouchPoint;
    CGPoint movingTouchPoint;
    CGPoint originPoint;
    CGPoint differencePoint;
    NSMutableArray * arrayOfLevels;

}

// returns a CCScene that contains the HelloWorldLayer as the only child
+(CCScene *) scene;
-(void) callMe:(CCSprite*) sender;
-(void) moveMenuItem:(float) velocity;
-(void) accelerateLabel;

//set up looping menu
@property (nonatomic) CGPoint beginTouchPoint;
@property (nonatomic) CGPoint movingTouchPoint;
@property (nonatomic) CGPoint originPoint;
@property CGPoint differencePoint;
@property (nonatomic, retain) NSMutableArray * arrayOfLevels;
@property int numOfLevels;
@property int spacingBetweenLevels;
@property float retardationNum;

@end</code></pre></description>
		</item>
		<item>
			<title>Acceleroto on "Menu mouseOver/mouseEntered/mouseExited events"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/14314#post-81025</link>
			<pubDate>Wed, 09 Mar 2011 06:38:22 +0000</pubDate>
			<dc:creator>Acceleroto</dc:creator>
			<guid isPermaLink="false">81025@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I'd really like to add some animated menu buttons to my Mac games when the mouse goes over a menu item.  Has anyone toyed with this yet?</p>
<p>In it's simplest form, it'd be great to have something like this:<br />
<pre><code>//the overImage part of this isn&#39;t in Cocos2d...yet?
CCMenuItemImage *item1 = [CCMenuItemImage itemFromNormalImage:@&#34;btn-play-normal.png&#34; selectedImage:@&#34;btn-play-selected.png&#34; overImage:@&#34;btn-play-over.png&#34; target:self selector:@selector(menuCallback1:)];</code></pre>
<p>Even better would be an event that fires when the cursor enters a menu item &#38; another event when it exits.</p>
<p>Thoughts/brainstorms/examples?  Thanks!<br />
-Bryan
</p></description>
		</item>
		<item>
			<title>mrtechgu2y3 on "Sliding menu help!"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18832#post-105632</link>
			<pubDate>Mon, 18 Jul 2011 17:46:16 +0000</pubDate>
			<dc:creator>mrtechgu2y3</dc:creator>
			<guid isPermaLink="false">105632@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>In my game I want to have a sliding menu like the one in angry birds where the user can select their level. I am new to cocos2d so I'm not sure how to do this.</p>
<p>Please reply
</p></description>
		</item>
		<item>
			<title>mrcointreau on "Good game design with multiple levels advices"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/16434#post-92641</link>
			<pubDate>Tue, 10 May 2011 20:52:19 +0000</pubDate>
			<dc:creator>mrcointreau</dc:creator>
			<guid isPermaLink="false">92641@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi everybody,  it's been only a couple weeks that I'm entering the cocos2d world, so: I'm a nooooooooob!</p>
<p>I'm getting crazy about the game design pattern, I've never programmed a game before and i would need some advices.<br />
I'm trying to make a Super Mario like platform, so I came out with the following solution:</p>
<p>- a GameScene : CCScene , a singleton class for keeping my current level layer, my input layer and my default game player<br />
- a Level : CCLayer , a class which contains the generic instance variable of a level, such as an array of platforms, enemies, ground level, gravity etc.<br />
- some class such as Level1 - Level2 which inherits from Level and are used as specific layer, so that i can load them into my GameScene singleton class</p>
<p>My question is: could this be a good game pattern design or not?<br />
Thanks everybody.
</p></description>
		</item>

	</channel>
</rss>

