1
\$\begingroup\$

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 ?

\$\endgroup\$
2
  • 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, 2011 at 12:18
  • 2
    \$\begingroup\$ Maybe start drawing a rectangular over the surface that get's darker over time... \$\endgroup\$
    – jcora
    Nov 25, 2011 at 9:28

2 Answers 2

1
\$\begingroup\$

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

\$\endgroup\$
3
  • \$\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, 2011 at 13:06
  • \$\begingroup\$ you have to remove the sprite you added with [parent removeChildByTag:TAG_PAUSE_OVERLAY] \$\endgroup\$
    – Jack
    Nov 28, 2011 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, 2011 at 4:02
-1
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ glClearColor affects the entire framebuffer and doesn't do any blending. \$\endgroup\$
    – Beefster
    Jul 21, 2019 at 15:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .