Hi,
I'm kinda new here, and to cocos, so please don't be too rough.
I'm trying to use the Liquid action in my layer, so I created a sprite and used runAction with the Liquid.
The action works just fine but the moment it starts my background turns black, I made it so the action will trigger from a button and the moment I pressed the action starts and the background goes black.
Any ideas?
Thanks in advance!
~Natan.
Liquid Action problem.
(10 posts) (5 voices)-
Posted 2 years ago #
-
It's hard to say without seeing some code. Post some code or have a look at EffectsTest.m for some examples.
Posted 2 years ago # -
here's some code:
- (id)init {
if(self = [super init]) {
Sprite *spr = [Sprite spriteWithFile:@"menu.png"];
[spr setPosition:ccp(240, 160)];
[self addChild:spr z:0];[MenuItemFont setFontName:@"Marker Felt"];
[MenuItemFont setFontSize:20];
MenuItem *start = [MenuItemFont itemFromString:@"Start" target:self selector:@selector(startGame:)];
Menu *ms = [Menu menuWithItems:start, nil];
[self addChild:ms z:1];Sprite *bg2 = [Sprite spriteWithFile:@"grossini.png"];
[bg2 setPosition:ccp(bg2.contentSize.width /2 , 50)];
[self addChild:bg2 z:2 tag:1];/* CGSize size = [[Director sharedDirector] winSize];
id rotate = [RotateBy actionWithDuration:4 angle:180*4];
id jump = [JumpBy actionWithDuration:4 position:ccp(size.width, 0) height:100 jumps:4];
id forward = [Spawn actions:rotate, jump, nil];
id back = [forward reverse];id seq = [Sequence actions: forward, back, nil];
id repeat = [Repeat actionWithAction:seq times:10];*/}
return self;
}- (void)startGame:(id)sender {
id spr2 = [self getChildByTag:1];
[spr2 runAction:[Liquid actionWithWaves:5 amplitude:20 grid:ccg(10, 10) duration:3]];
}That's basically it, before I press start everything looks fine with the background and the sprite in the right place. The moment I press the start button The background turns black and the action runs.
Did anyone see this before?
Thanks.BTW: I think it has to do something with the grid... as other actions that do not involve grid work just fine (e.g. jump, move, rotate) can anyone explain what does the grid mean really?
Posted 2 years ago # -
Found the solution on tips and tricks, The director doesn't support transparency as default and so you need to set the pixel format as follows in order for actions such as those to work well:
[[Director sharedDirector] setPixelFormat:kRGBA8];This works!
Edit: Sorry for double post, I didn't notice.
Posted 2 years ago # -
Sorry to resurrect a dead thread but I have this exact same problem as well and changing the pixel format doesn't work to fix mine. When I run the liquid action on a node full of some sprites all sprites above and below those sprites dissapear and never reappear even once the action is done.
Any tips on getting it to work right or what could be going wrong?
Posted 2 years ago # -
Thanks riq I checked that out and it looks like I'm doing everything right. So I went further and dug through my code to try and figure this out and what I found is that it seems that the problem stems from this
[[Director sharedDirector] set2Dprojection];
which I'm using to make the tiles I created in my game world line up correctly as the world scrolls around. So I wonder is this a bug or is this just a limitation that I can't use those sorts of actions (liquids and waves and such) when using 2dprojection mode?
Here's some code to reproduce it just put that bit into the init of game layer of a new project. You'll notice without setting the 2d projection it looks fine and grossini shows up but with it grossini dissapears. Also I'm using 0.8.1-rc so if this is something that's fixed in a later version let me know. (Just tested it in 0.8.1 and it still happens there as well)
[[Director sharedDirector] set2Dprojection]; CGSize size = [[Director sharedDirector] winSize]; // background Sprite * bg = [Sprite spriteWithFile:@"background.png"]; [bg setPosition:ccp(size.width/2, size.height/2)]; [self addChild:bg z:1 tag:1]; Sprite * dude = [Sprite spriteWithFile:@"grossini.png"]; [dude setPosition:ccp(size.width/2, size.height/2)]; [self addChild:dude z:2 tag:2]; id liquid = [Liquid actionWithWaves:60 amplitude:2 grid:ccg(16,12) duration:60]; [bg runAction:[RepeatForever actionWithAction:liquid]];Posted 2 years ago # -
2d projectionmeans: orthogonal projection
3d projectionmeans: 3D projectionSome effects use the openGL Z vertex. Basically all the effects that ends with "3d", like
Lens3D,Ripple3Duse the openGL z vertex.
Liquiddoesn't use the Z vertex so it should work OK.What should not work OK is the z-order of the nodes.
For example, if you add:
[[Director sharedDirector] set2Dprojection];to the EffectsAdvancedTest.m, you'll see the the effects work OK, but the Z is broken.
Posted 2 years ago # -
I've just discovered this issue myself and came across this thread.
So that I can have menu buttons that aren't blurry or distorted I added:
[[Director sharedDirector] set2Dprojection];But then a wave action on a sprite causes that image to become opaque and render on top of everything else
Is there a way to use an effect that doesn't use Z vertex and have it stack in between other sprites with transparency when using set2Dprojection?
Posted 1 year ago # -
I worked with this a bit more. I noticed that in [CCGridBase afterDraw] there is a call to [self set3DProjection]. If I comment that out, then the sprite with the Liquid effect renders with the correct Z order and alpha but is not rotated to landscape orientation. This makes me suspect it could be made work if I could just decipher the code that is responsible for doing the projection changes and transforms.
Posted 1 year ago #
Reply
You must log in to post.