Cocos2d - Combine CCSequence and Bool! is it possible - cocos2d-iphone

I want to ask is it possible to combine ccsequence and a bool??
[self runAction:[CCSequence actions:
myAnimation,
(myBool = YES),
[CCDelayTime actionWithDuration:myTime],
[CCCallFunc actionWithTarget:self selector:#selector(otherAnimation)],
nil]];
But if i do it this way the program breaks down.
Does anybody know a solution??

you was on the right way, you can simply change your action like this
[self runAction:[CCSequence actions:
myAnimation,
//OLD_VERSION(myBool = YES),
[CCCallFunc actionWithTarget:self selector:#selector(yourBoolMethod)],
[CCDelayTime actionWithDuration:myTime],
[CCCallFunc actionWithTarget:self selector:#selector(otherAnimation)],
nil]];
and inside yourBoolMethod set the bool as true
-(void) yourBoolMethod {
myBool = YES:
}

Related

My App crashed at this line in Gaming program in iOS 9.2.1

[CCAnimation animationWithFrame:frame
frameCount:2
delay:0.5]
self.abc = [CCSequence actions:
[CCDelayTime actionWithDuration:1],
[CCSpawn actions:
[CCAnimate actionWithAnimation:[CCAnimation animationWithFrame:abc
frameCount:2
delay:0.5]
restoreOriginalFrame:YES],
[CCCallFunc actionWithTarget:self selector:#selector(abc)],
nil],
[CCDelayTime actionWithDuration:0.5],
[CCCallFunc actionWithTarget:self selector:#selector(abc)],
nil
];

famo.us: add an item to main context after an animation completes

I have an animation that takes 1 sec to complete, and then I want to show some text boxes for username/password and a login button. Is there some sort of "oncomplete" event for an animation?
Yes, there most certainly is..
It will be the third argument in your setTransform or equivalent animation function..
Check it out..
EDIT:
I did misunderstand your question. There is no event that is emitted, only the ability to set the completion handler.
var Engine = require("famous/core/Engine");
var Surface = require("famous/core/Surface");
var StateModifier = require("famous/modifiers/StateModifier");
var Transform = require("famous/core/Transform");
var Easing = require("famous/transitions/Easing");
var context = Engine.createContext();
var surface = new Surface({
size:[200,200],
properties: { backgroundColor: 'green' }
})
surface.state = new StateModifier({ origin:[0,0.5] });
var completionFunction = function(){ console.log("Complete!"); };
var xOffset = 0;
context.add(surface.state).add(surface);
surface.on('click', function(){
transition = { duration:1000, curve:Easing.inOutQuad };
xOffset += 100;
surface.state.setTransform(Transform.translate(xOffset,0,0),transition, completionFunction )
});
There is no built in 'oncomplete' event, but assuming that you're using some sort of Transitionable, you can do whatever you want via the the callback argument of Transitionable#set:
https://famo.us/docs/0.1.1/transitions/Transitionable/#set
If you prefer to work with events, you can use an EventEmitter to emit one via the callback yourself.

Save previous state URL when transition to another route

When I transition to a new route, is there any way to store previous state with all the parameters?
Browser back button kinda work so I guess window.history.back() instead of link-to helper would work for me, but I am curious is there any Ember way to save a state and transition to it later?
Thanks
Not sure, if this case works for you but I have saved the previous state and then make the transition to that state in a tab menu which needed to save the state for each specific menu.
App.MenuRoute = Em.Route.extend({
actions: {
willTransition: function(transition) {
var handlers = this.router.router.targetHandlerInfos;
var handler = handlers[handlers.length-1];
this.controller.set('lastHandler', handler);
},
selectMenu: function(value) {
var handler = this.controllerFor(value).get('lastHandler');
var routeName = (handler) ? handler.name : value;
var model;
if ( handler && handler.isDynamic ) {
model = handler.context;
}
if ( model ) {
this.transitionTo(routeName, model);
} else {
this.transitionTo(routeName);
}
}
}
}
});

How can I set a controller's model without triggering an observer?

Given I have this:
App.SomeController = Ember.ObjectController.extend({
autosave: function(){
//stuff
}.observes('content.text', 'content.colour', 'content.webfont')
});
How can I set SomeController's model in a route WITHOUT triggering autosave?
Emberjs doesn't have suport to suspend observers at least in public api.
My approach to that problems is to create a flag:
App.SomeController = Ember.ObjectController.extend({
_suspendAutosave: false,
suspendAutosave: function(fn) {
this.set('_suspendAutosave', true);
fn();
this.set('_suspendAutosave', false);
},
autosave: function(){
if (this.get('_suspendAutosave')) { return; }
// some code ...
}.observes('content.text', 'content.colour', 'content.webfont')
});
At some place:
controller.suspendAutosave(function() {
controller.set('content.text', 'foo');
});
This isn't cool, but is the only way that I know. I hope it helps.
Alternatively you can use: Ember.removeObserver() and Ember.addObserver() methods.

how to change a sprite's Image during a sequence of actions

In my code (sample) below I would like to change the sprite's image during the sequence of actions.
spriteActions = [CCRepeatForever actionWithAction:
[CCSequence actions:
[CCShow action],
[CCDelayTime actionWithDuration:1.5],
[CCHide action],
[CCDelayTime actionWithDuration:5.0],
[CCShow action],
[CCDelayTime actionWithDuration:3.0],
// I would like to change the sprite image here before completing the remaining actions.
//I want this line here: sprite = [CCSprite SpriteWithFile:#"newSpriteImage.png"];
[CCMoveTo actionWithDuration:2.0 position:newSpritePos],
[CCHide action],
[CCDelayTime actionWithDuration:2.0],
nil]];
[sprite runAction:spriteActions];
Thanks for the assistance.
You do like this:
[CCRepeatForever actionWithAction:
[CCSequence actions:
[CCShow action],
[CCDelayTime actionWithDuration:1.5],
[CCHide action],
[CCDelayTime actionWithDuration:5.0],
[CCShow action],
[CCDelayTime actionWithDuration:3.0],
// I would like to change the sprite image here before completing the remaining actions.
[CCCallBlockN actionWithBlock:^(CCNode*node){
CCSprite *spritN = (CCSprite*)node;
//[spritN setDisplayFrame:[cache spriteFrameByName:#"newSpriteImage.png"]]
CCTexture2D* tex = [[CCTextureCache sharedTextureCache] addImage:#"newSpriteImage.png"];
CGSize texSize = tex.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:tex rect:texRect];
[spritN setDisplayFrame:frame];
}],
[CCMoveTo actionWithDuration:2.0 position:newSpritePos],
[CCHide action],
[CCDelayTime actionWithDuration:2.0],
nil]];