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 ?

  • 1
    \$\begingroup\$ Do you mean dim the screen? The definitions I found of deem don't seem to fit your question unless I'm completely wrong. \$\endgroup\$ – Milkboat Nov 22 '11 at 12:18
  • 2
    \$\begingroup\$ Maybe start drawing a rectangular over the surface that get's darker over time... \$\endgroup\$ – jcora Nov 25 '11 at 9:28

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

| improve this answer | |
  • \$\begingroup\$ I have added one sprite to make the background color gray. But when i click resume button still the background is remain gray color. How can i remove the sprite when i click resume button. \$\endgroup\$ – Laxmipriya Nov 28 '11 at 13:06
  • \$\begingroup\$ you have to remove the sprite you added with [parent removeChildByTag:TAG_PAUSE_OVERLAY] \$\endgroup\$ – Jack Nov 28 '11 at 17:35
  • \$\begingroup\$ Thanks Jack . Really u r great !Its very helpful to me . Thanks so much for your help.please continue it in future... \$\endgroup\$ – Laxmipriya Nov 29 '11 at 4:02

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".

| improve this answer | |
  • \$\begingroup\$ glClearColor affects the entire framebuffer and doesn't do any blending. \$\endgroup\$ – Beefster Jul 21 '19 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.