2

I'm trying to make my sprite have a shake effect. However, while the sprite does shake, the entire background turns black. Can anybody help me with this?

Here's the code that I've written to add the sprite to my layer along with the action that I run right after.

CCSprite * picture = [CCSprite spriteWithFile:@"picture.png"];
picture.position = ccp(winsize.width/4,
                       picture.contentSize.height * 0.8);
[self addChild:picture];
CCShaky3D * shake = [CCShaky3D actionWithRange:4
                                        shakeZ:NO
                                          grid:ccg(12, 12)
                                      duration:0.5];
[picture runAction:shake];

Can anybody help me?

bendu
  • 391
  • 4
  • 15

1 Answers1

2

Have you enabled depth buffering of the EAGLView? Most 3D actions require depth buffering (GL_DEPTH_COMPONENT16_OES or GL_DEPTH_COMPONENT24_OES) to avoid visual artifacts. You may also have to use a 32-Bit frame buffer with alpha channels by using the kEAGLColorFormatRGBA8 instead of kEAGLColorFormatRGB565.

EAGLView is initialized in the app delegate class:

EAGLView* glView = [EAGLView viewWithFrame:[window bounds]
                               pixelFormat:kEAGLColorFormatRGBA8
                               depthFormat:GL_DEPTH_COMPONENT24_OES
                        preserveBackbuffer:NO
                                sharegroup:nil
                             multiSampling:0
                           numberOfSamples:0];
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • It works, but it seems that it messes up the scene transitions. There are white blocks everywhere during the transitions. – bendu Nov 19 '11 at 15:15
  • @LearnCocos2D I have followed your advice and this works fine. I have some other problems which are related and I posted in http://stackoverflow.com/questions/10617219/cocos2d-effects-slow-down-fps-drammatically-and-how-to-initialize-eaglview-prope Could you have a look at this question? – mm24 May 16 '12 at 11:06