1

I'm new to Cocos2dx and I'm trying to create a planet animation rotate itself by using a 3:1 rectangle texture, which contains 3 squares are two faces (map) of sphere (the third square is a clone of the first one). I create a frames array by cropping the texture and add them to CCAnimation. Then I test this animation with two effects to make square frame become a 3D circle: CCLens and CCTurnOffTiles (I will modify it in the future to turn off only grids outside the circle).

But there is a problems: two effects don't stack. If CCTurnOffTiles is added after CCLens, CCLens will not work; if CCLens is added after CCTurnOffTiles, CCDirector will throw reading violation exception at runtime.

Is there any solution to run many effects simultaneously or implement planet animation in other way? Thanks.

eee
  • 280
  • 4
  • 15
  • While Creating two different Animations make sure you use different Arrays and CCAnimation. I am pretty sure you can use two different animations on same sprite simultaneously using seperate runAction – Ganesh Somani Jun 13 '13 at 10:48
  • @GaneshSomani Normally it should work. But in this case it seems that CCLens and CCTurnOffTiles won't work together. – eee Jun 14 '13 at 02:11

2 Answers2

3

Try using CCSpawn.

// Create the effects
CCLens3D * lensEffect; // Your CCLens3D create()
CCTurnOffTiles * turnOff; // Your CCTurnOfftiles create()

// Create a spawn to run them simultaneously
CCSpawn * sphereEffect = CCSpawn::createWithTwoActions( lensEffect, turnOff );

// Run the spawn
myObject -> runAction( sphereEffect );
alxcyl
  • 2,722
  • 7
  • 31
  • 47
  • I've tried using CCSpawn but got the same error with using runAction separately. – eee Jun 13 '13 at 07:42
1

Both CCTurnOffTiles and CCLens3D inherits of CCGridAction.

But one cancels the other: CCTurnOffTiles will turn off grid tiles, and CCLens3d need these grid tiles.

I recommend you to draw all planet sprites, already circled and using a SpriteSheet, and animate then with CCAnimation, without using CCTurnOffTiles or CCLens3D. It is easiest and will consume less cpu.

Bivis
  • 1,320
  • 1
  • 10
  • 24
  • In my project, there are many planet objects using different textures. Drawing all planet sprites means a lot of artworks must be done. Therefore, I'm looking for another solution instead of this one. Is there any way to directly modify the CCFrame at the load time or create a mask to make only points inside the circle become visible during animate action? – eee Jun 14 '13 at 02:02
  • You can mask sprites using shaders, GlScissor or CCClippingNode. Take a look at this links: http://www.raywenderlich.com/4428/how-to-mask-a-sprite-with-cocos2d-2-0 , http://www.cocos2d-iphone.org/forums/topic/how-to-set-a-mask-on-a-spriteatlassprite-object/ , http://stackoverflow.com/questions/3177751/cocos2d-iphone-sprite-cliping-mask-frame – Bivis Jun 15 '13 at 03:08