Skip to content

Instantly share code, notes, and snippets.

View sdabet's full-sized avatar

Sébastien Dabet sdabet

  • Grenoble, France
View GitHub Profile
CCSprite *texture = [CCSprite spriteWithFile:@"texture.png"];
texture.blendFunc = (ccBlendFunc) { GL_ZERO, GL_ONE_MINUS_SRC_ALPHA };
[scene addChild: texture];
CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:@"mysprite.png"];
sprite.blendFunc = (ccBlendFunc){GL_ONE, GL_ONE_MINUS_SRC_ALPHA};
// or
[sprite setBlendFunc:(ccBlendFunc){GL_ONE, GL_ONE_MINUS_SRC_ALPHA}];
CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
pixelFormat:kEAGLColorFormatRGBA8 // not kEAGLColorFormatRGB565 !
depthFormat:0 //GL_DEPTH_COMPONENT24_OES
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];
CCMenuItemImage *menuItem = [CCMenuItemImage ...];
// Make touch area centered and 4 times smaller than bounding box
menuItem.touchArea = CGRectMake(
menuItem.contentSize.width/4,
menuItem.contentSize.height/4,
menuItem.contentSize.width/2,
menuItem.contentSize.height/2);
@synthesize touchArea=_touchArea;
// ...
// Initialize the touchArea to the outside box
-(void) setContentSize:(CGSize)contentSize {
[super setContentSize:contentSize];
_touchArea = CGRectMake(0, 0, contentSize_.width, contentSize_.height);
}
/** the touch area (relative to the current position) */
@property (nonatomic,assign) CGRect touchArea;
// and remove the 'rect' method
-(CCMenuItem *) itemForTouch: (UITouch *) touch
{
CGPoint touchLocation = [touch locationInView: [touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];
CCMenuItem* item;
CCARRAY_FOREACH(children_, item){
// ignore invisible and disabled items: issue #779, #866
if ( [item visible] && [item isEnabled] ) {
-(CCMenuItem *) itemForTouch: (UITouch *) touch
{
CGPoint touchLocation = [touch locationInView: [touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];
CCMenuItem* item;
CCARRAY_FOREACH(children_, item){
// ignore invisible and disabled items: issue #779, #866
if ( [item visible] && [item isEnabled] ) {
CCNode *background = ...; // your complex hierarchy of nodes
// Create the NodeRenderer
NodeRenderer *renderer = [NodeRenderer renderTextureWithNode:background width:winSize.width height:winSize.height];
// Add it to your scene
renderer.position = ccp(winSize.width/2, winSize.height/2);
[scene addChild:renderer];
// Fading out
@interface NodeRenderer : CCRenderTexture
+(id)renderTextureWithNode:(CCNode*)node width:(int)w height:(int)h;
-(id) initWithNode:(CCNode*)n width:(int)w height:(int)h pixelFormat:(CCTexture2DPixelFormat)format depthStencilFormat:(GLuint)depthStencilFormat;
@end