I am working in an android game using cocos2d. I want to dim the background screen when I click the pause button.
How can I do this ?
I achieved this effect by using a specified pixel from a texture I was already using in this way:
CCSprite *layer = [CCSprite spriteWithTexture:TEX_INTERFACE.textureAtlas.texture rect:CGRectMake(87, 143, 1, 1)]; CGSize size = [[CCDirector sharedDirector] winSize]; layer.scaleX = size.width; layer.scaleY = size.height; layer.position = ccp(size.width/2, size.height/2); layer.opacity = 0; [game addChild:layer z:100 tag:TAG_PAUSE_OVERLAY]; id action = [CCEaseOut actionWithAction:[CCActionTween actionWithDuration:0.1 key:@"opacity" from:0 to:220] rate:2]; [layer runAction:action];
Mind: this is Cocos2D for Objective-C, not for Android but translating it is straightforward
I would need a bit of code to give a more detailed answer, but you probably want to use glClearColor when you "click the pause button".