Cocos2D 3.3中的注意事项
如果你在使用Cocos2D 3.3+(是SpriteBuilder 1.3+的一部分)你将不得不替分别的换所有存在的UITouch和UITouchEvent为CCTouch和CCTouchEvent。
你可以在SpriteBuilder的升级手册中找到更多信息。
再见 CCMenu!Hello CCLayout!
在过去CCMenu是创建菜单最简单的方法。因为CCMenu是提供布局处理方法的仅有的类(alignItemsVertically,等等).该类过去被用来布局大量其它的东西,不仅仅是菜单。
Cocos2d 3.0提供一个CCLayout类来解决该问题。该类可以布局任何种类的CCNode对象,使得布局你的场景显得更有吸引力。如果你要在Cocos2d 3.0中创建一个菜单,你可以将CCButtons简单的添加到CCLayout容器中去。
下面是一个简单布局的例子:
// create first button self.calculationStepButton = [CCButton buttonWithTitle:LABEL_STEP]; [self.calculationStepButton setTarget:self selector:@selector(calculationStepButtonTouched:)]; // create second button self.animationButton = [CCButton buttonWithTitle:LABEL_ANIMATE]; [self.animationButton setTarget:self selector:@selector(animateButtonTouched:)]; // setup layoutbox and add items CCLayoutBox *layoutBox = [[CCLayoutBox alloc] init]; layoutBox.anchorPoint = ccp(0.5, 0.5); [layoutBox addChild:self.calculationStepButton]; [layoutBox addChild:self.animationButton]; layoutBox.spacing = 10.f; layoutBox.direction = CCLayoutBoxDirectionVertical; [layoutBox layout]; layoutBox.position = ccp(CANVAS_SIZE.width + (self.contentSize.width - CANVAS_SIZE.width)/2, self.contentSize.height/2); [self addChild:layoutBox];