Cocos2D : Stop/Resume CCAction on CCSprite - cocos2d-iphone

I have two CCAnimations running on a CCSprite. How do I check if the specific action is running on a sprite? And how do I pause/resume them as needed?
I have checked the numberOfRunningAction in the actionManager, but it doesn't equal the number I expect.

Make sure to set the tag property of your two actions. Then call getActionByTag, specifying the tag of your desired action. If your result is not nil, the action is running.
Unfortunately, you can't pause any particular action. You can only pause ALL actions (pauseSchedulerAndActions) or stop an individual action (stopActionByTag: or stopAction:), which removes it from the action list. Not what you want.

Related

Ember 2.10, updating component on array pushObject

I have two components that should both reflect the same data (testing d3 in ember)
One of the components adds a node to my state and also lists those nodes. The state is an array and I believe I am correctly calling pushObject in order to notify everything that there are updates.
The other is going to be a d3 thing so nothing is being rendered by the hbs file and I need to be notified when the array is modified so I can call the appropriate d3 functions and rerender my force graph.
I setup a minimal twiddle here: https://ember-twiddle.com/d4aae25e4a63636a97ed78b0b0081227
Basically, when you press add node: it adds a node to the list so I know some event is being fired however, my draw function in the "twiglet-graph" component is not being called.
To see this in action, goto the fiddle and press "Add". When you add another node, it will correctly list two nodes on the top part but it never changes the length in the bottom component to 2. I setup a click event that will alert you of the length of that component's this.nodes and clicking after adding shows a length of 2. How do I hook into the update so I can redraw my force graph?
Thanks.
By design, adding or removing objects from an array does not trigger the didUpdateAttrs hook. Instead you need to use notifyPropetyChange method.
See link for more details:
http://discuss.emberjs.com/t/didupdateattrs-not-called-on-array-modifications/10046

Windows UI execute detect is possible?

start menu's item can be executed single-click,
explorer's item can be executed double-click or right-click and (O)pen.
like this, Windows UI is many execution method.
I want to know execution through UI(like item double-click).
How to know that?
I try to use UI Automation. but focus change is Too late and sometimes executed without focus change.
so I want certain method.
The assumption.
UI to kernel execution message.
Can I get it?
And other method is exist?

cocos2d disable touches to all other views

Below is what I came up with. Wonder if there's easier way to do it.
Suppose I want only menu layer to be touchable while it's up.
I put invisible layer that will swallow touches.
bool tNoTouchLayer::init()
{
if(!CCLayer::init()) {
return false;
}
setIsTouchEnabled(true);
return true;
}
void tNoTouchLayer::registerWithTouchDispatcher()
{
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
}
bool tNoTouchLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
return true;
}
Now I can add the noTouchLayer before adding menu layer, and all touches would be stolen by noTouchLayer.
Lastly, i did find more info on this:
http://code.google.com/p/cocos2d-iphone/issues/detail?id=1033
the reason that menu items are stealing touches is because menu items have their touch priority set to the highest (lowest char value) possible...
you can change kCCMenutouchPriority to be 0 instead.
That's how you do it as far as I can tell. Note however that your code will not disable any menues added to the scene. To do that you have to remove the menu from the touch dispatcher when adding the popup and add it back again when removing the popup.
To remove a menu from the touch dispatcher you can do the following:
CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(menu);
and to add it back you can do this:
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(menu, kCCMenuHandlerPriority, true);
where menu is your CCMenu node.
As a tip, I created a class like the one above but I also added the popup menu to it, creating one touch blocking menu in one node. :)
this isn't exactly the answer you are looking for, but here's something up for thought:
if you're trying to do this for a pop-up, would it be possible to try to pop up a subclass of UIAlertView (one that looks the way you want it to)?
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-uialertview-custom-graphics/
Here's another approach:
keep state of the app and which layer is "on top".
in each of your menu listeners, have them all do a check to see if the state of your current layer should allow for that menu button to be pressed.
also, you can override "addchild" to see if it's a MenuItem, and if it is a MenuItem, then have it check to see if it should be enabled. if not, return immediately instead of executing the rest of the code
If I understand your question correctly, I guess you try to do something like "pause screen" to pop up and disable all other layers.
Well, you said in your comment that you won't like to enable touch event in other areas but not your pop-up's area. Basically, I would think we should think in term of layer for easier understanding, and easier to implement.
Let's see if we have "main layer" which holds other game objects to show as its childs (assume that they also are running animation). Now you touch a button and want to pop up "pause layer". You have to do the following in order to disable all touch event from others layer + objects.
Pause layers' schedule and actions [via pauseSchedulerAndActions()]
Pause all of its game objects inside the layer (ie. enemies) [via pauseSchedulerAndActions()]
Disable CCMenu object (if any), this will ignore touch event on CCMenu related object ie.CCMenuItemImage [via setEnabled(false)]
Disable touch event for layer itself [via setTouchEnabled(false)]
The first 2 points are about stop running any schedule method, and animation.
The latter 2 points are about stop accepting touch event. You can see that CCMenu* related class maintains its own touch event separately from CCLayer, thus we need to do additional effort by set to both CCMenu* object and the layer itself.
I tried this and it works well for me. Also it's better as we don't have to involve setting dispatcher directly in my opinion.

Handling callbacks or checking if an action is complete

How does one find out when an action is complete or when a sequence of actions is complete?
I have a bunch of sprites with different actions depending on the state of them, and when e.g. the sprite is pressed and the state is e.g. state1, then some code should execute. if the sprite is pressed during the execution of cocos2d behind the scenes, then the next state is triggered.
I need to know when the first actions are complete so that I can then "unlock" the sprite and allow for further touch detection.
How do I check if the sequence is done?
Thanks
If you're using CCActions, which it seems like you are, then you can just use CCCallFuncN. It looks something like this:
id doneAction = [CCCallFuncN actionWithTarget:self selector:#selector(yourMethod)];
Just add that to the sequence of actions you're running and it will call 'yourMethod' when they get done.

CToolTipCtrl question

I use CToolTipCtrl component in my application and it works fine. But also I need in additional setting: tooltips should appear only after 10 seconds from moment when mouse are on button.
Does this component have any property like setShowTime() or some function can be called to setup waiting period?
You can set the delay time just calling SetDelayTime. You just need to check msdn it's not that hard.