I need to kill running actions for various sprites.
Does cocos2d provide a way of calling a sprite and killing its actions?
You mean something like this?
[someSprite stopAllActions];
Related
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.
I'm developing a Block Breaker clone using c++ and Qt and I would like to know how to create infinite(or unbounded) animation for the movement of the ball.
Should i stick to the animation framework (by sub-classing QAbstractAnimation), or consider creating and managing new threads for handling animations?
Some experienced guidance would be very helpful, thank you.
So finally I figure it out: using the QPropertyAnimation::setLoopCount(-1) member function makes the animation run forever until stopped with the QPropertyAnimation::stop() signal...
I move an instance of CCSprite in my Cocos2D-based iPhone game like this:
[mySprite runAction:[CCMoveBy actionWithDuration:1.0
position:ccp(10, 10)]];
How can I get a callback everytime the sprite moves?
I'd like to do something like this:
[self registerForCallbacksFrom:mySprite
selector:#selector(spriteMovedOneStep)];
So spriteMovedOneStep would be called everytime mySprite moves. Would be nice to specify the frequency of the callback too so minimize CPU usage.
One possible solution is to subclass CCMoveBy and call your callback from it's update method. You also can setup frequency and everything you want with this approach.
If I get your question right you would like to have a method called at times when the Sprite is moving, correct ?
How about scheduling an update method that performs what you want if a SpriteIsMoving BOOL is set to YES, I'm not sure on what your trying to achieve but this is my take on it.
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.
I am developing an iOS game using Cocos2D. I would like to show a popup, something like UIAlertView, but completely custom. What is the best way to achieve this?
Thanks a lot!
Benza
I would suggest to use a layer for this and to pause the scene. Here are a couple forum posts from the Cocos2d site that go over this a bit:
http://www.cocos2d-iphone.org/forum/topic/6511
http://www.cocos2d-iphone.org/forum/topic/1954
Unfortunately pausing the scene means you will also pause whatever you have in your popup.
Maybe it's not your case, but I quite often have scrolling lists in my popups. If I pause the scene it will not work.
I've added a method to CCNode which goes through all children and stops their activity rather than pausing the scene.
If you open the popup as a child of your scene then first you deactivate all children of the scene and then open the popup. This means that you can still do whatever you want in your popup and everything else is paused or does not respond to touch [like menus].