Recently,I have to implement paging functions with cocos2d using transition of CCTransitionSlideInL.But there is no effect.I tried some effects,and surprised to find that only transitions of CCTransitionSplitCols and CCTransitionSplitRows effect,others not.Followed is my code.
[[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInL transitionWithDuration:1.2f scene:scene]];
I would be very grateful if someone can help me solve this problem.
What does "does not work" mean in your case?
The code you have written works perfectly. If "does not work" means nothing happens then the issue is likely in how your layer is created. I suspect the layer variable is invalid. If you want help on that, post your layer creation code.
So,finally I solved it myself.That is because the transition of CCTransitionSlideInL must collide with the method of draw that CCLayer supports.More specifically,it collides with CCRenderTexture I used in the method.
Related
How can I override the setDisplayFrame method and check which sprite frame was set, in order to send a message if it matches a particular frame in an animation.
You don't need to override the method to do that, cocos2d 2.x already has this functionality. Look at the code in the CCAnimation and CCAnimationFrame classes. You can observe for the CCAnimationFrameDisplayedNotification in your objects. For an example of this look for ActionsTest.m in the cocos2d examples.
Additionally, I strongly suggest that you carefully read Programming with Objective-C before trying to dig deeper into cocos2d. I think it will clear a lot of your questions. ;-)
I'm having major issues trying to resize/scale/reshape a b2body's fixture... I've read so many tutorials and since I'm a n3wb at box2d most of it doesn't make sense.
What I'm trying to do exactly is make the collision box of a b2body scale to a CCSprite in cocos2d as the sprite moves dynamically through the application.
Any reference code would be greatly appreciated, I know you have to destroy and recreate the fixture but I have no idea how to do it correctly! I've been at this for hours now with no success. Thanks!
I think you need to create new fixture with new body. Please check out tutorial, it solve another problem, but you will learn many useful things (e.g. how to recreate body with new fixture):
http://www.raywenderlich.com/14302/how-to-make-a-game-like-fruit-ninja-with-box2d-and-cocos2d-part-1
http://www.raywenderlich.com/14393/how-to-make-a-game-like-fruit-ninja-with-box2d-and-cocos2d-part-2
I have a CCSprite that I'm using in a scene and have created multiple CCAnimation actions to apply to it all using a single CCSpriteFrameCache sharedSpriteFrameCache. While everything is working and I'm able to switch between animations, I feel like I'm doing poorly and would like to simplify my code by retrieving the running action(s) on the CCSprite to stop them individually before running the next action on it.
To help create some context, lets assume the following situation:
We have a CCSprite called mySprite
We have 3 separate CCAnimation actions defined for walking to the right, walking to the left, and sitting looking forward called: actionAnimWalkRight, actionAnimWalkLeft, and actionAnimSitForward respectively.
We want to have the sprite walk to the right when someone touches the screen right of mySprite, walk left when someone touches the screen left of mySprite and sit when someone touches mySprite.
The approach I'm using to accomplish this is as follows:
Place CCSprite as a child in the scene.
Tell the sprite to run an action using: [self runAction:actionWalkRight];
When I want to change the action after someone touches, I have a method called stopAllAnimationActions which I call before I apply a new action that stops any animation action no matter what's running. Basically lists ALL the CCAnimation/CCActions I have defined and stops each one individually since I don't want to use stopAllActions. as follows: [self stopAction:actionWalkRight]; [self stopAction:actionWalkLeft]; [self stopAction:actionSitForward];
Then I apply the new animation after the above method fires using: [self runAction:actionWalkLeft];
While this works, it just seems like a poor design to stop items that I know aren't running just because I don't know exactly what is running. So just looking for advice and the best recommended practice to do something like this within very complex situations so tracking every possible situation is difficult. Any feedback would be appreciated.
When creating the actions set the tag of that action with a constant:
actionWalkRight.tag= kCurrentAction;
[self runAction:actionWalkRight];
Then, retrieve the running action by that tag and stop it.
[self stopActionByTag:kCurrentAction];
I recommend you simplify your process and take advantage of the native Cocos features, including stopAllActions. Don't re-use actions, always create them from scratch as it has been well discussed among Cocos developers that re-using actions can be buggy.
Cocos is well optimized and features like stopAllActions are not performance hogs. It would probably be faster than your approach, actually.
Is it possible to make a CCSprite switch between two different animations? (both are CCRepeatForever)
I try to use stopAction: and runAction: but it crashes the app.
I can only use pauseSchedulerAndActions: and resumeSchedulerAndActions: with one animation.
To answer your question: Yes. If switching animations troubles you, use one sprite for each animation and keep them all updated to the same position, and only set the one to visible whose animation should be played.
The crash is certainly unrelated.
I am working on a game which would take touch gestures as inputs. Now, i would like to display the path/gesture as the user draws it. Can someone please tell me how to do this in cocos2d?
I tried to override the draw method and used ccDrawPoint(). But the point just keeps following the touch. I guess this is because the previous drawing is getting overwritten.
Can you tell me where i am going wrong here or suggest a better way to implement this?
i found a solution with CCRenderTexture sample test in cocos2d. Though i could not find enough documentation on it, but the sample code is enough for a start.