What is the best way to create custom actions in coco2d?
I would like to create a custom action that will create a cartoony squash animations on my game objects. Do I just subclass the CCFiniteTimeAction class and override the update method?
Any examples or links would be appreciated.
Also, within my custom action, I would like to use the CCScale action. Is that possible?
Yes that is pretty much all the magic. An example can be found at http://getsetgames.com/2009/09/23/custom-cocos2d-action-for-animating-an-atlassprites-texturerect/
It is possible to use CCScale action. I think if you import and use it it'll work just fine.
just write a custom method that returns a CCSequence
something like:
-(CCSequence)squash{
id action1=....//define action
id action2=...2nd action
...
return [CCSequence actions: action1, action2,..., nil];
}
and you just call [mySprite runAction:[self squash]];
with this solution you can change absolutely everything about the sprite (even call function inside the sequence (using CCCallFunc)
here is the link i use for documentation regarding what i can do (yes..it's written in java but there are the same methods in iphone cocos2d)
if you run into any problem..post you code and i'll look through it
Related
What's happening to controller when we're quitting the appropriate route? Is that correct that observers set up there keep doing their job? And if so, what is the proper way to avoiding that? Some method opposite to setupController?
yes, observers are still present, what I normally do with observers observing another property that could change in another screen, is that I set them/remove them manually in the activate/deactivate route's hooks, something like this:
var controllerWhereThePropertyToObserveIs = this.controllerFor('fancyController');
controllerWhereThePropertyToObserveIs.addObserver('propertyToObserveForChanges', this.controllerFor('controllerWhereTheObserverWouldBe'), 'functionToFire');
then, to remove it:
var controllerWhereThePropertyToObserveIs = this.controllerFor('fancyController');
controllerWhereThePropertyToObserveIs.removeObserver('propertyToObserveForChanges', this.controllerFor('controllerWhereTheObserverWouldBe'), 'functionToFire');
I'm hoping to stub/spy on a route's event handler in ember.js using my testing framework of choice, jasmine. Usually this involves overwriting the function of interest with a spy, which requires access to the object on which the method is defined:
spy = spyOn(someObject, "methodOnThatObject")
But in Ember, my event handlers for my routes are defined as follows:
App.ActivityRoute = Ember.Route.extend({
events: {
show: function(context) {
}
}
});
I would like to stub the function show, but I don't know how to get the object on which it is eventually defined? Or is it ever defined on an object? Perhaps it's invoked with #call or #apply? If so, how does one stub this?
I've tried digging around the source, but didn't manage to figure out how this is handled. Any pointers to where I should look in the source would also be helpful.
Cheers,
Kevin
You can use send('eventName', [optional record]):
If you're calling from a controller under the same route do:
this.get('target').send('show', this.get('content'))
Silly me. I can just do the following:
route = App.__container__.lookup('route:myRoute')
spy = spyOn(route.get('events'), 'show')
controller.send('show')
expect(spy).toHaveBeenCalled()
And that works.
I'm trying to figure out Ember.js and keep hitting what seems like basic problems that are not documented in a way I understand.
I want a object to manage a list of stuff. ArrayController seems to make sense. I assume having that controller load the data from the 3rd party server (youtube) makes the most sense. So My plan is to write some custom functions in the controller to load the data.
App.videoController = Ember.ArrayController.extend({
loadSomeVideos() {
console.log("I have run");
}
});
after I run the above code App.testController.someFunction() does not exist. Why not? I feel like I am missing some basic concept.
When you call Ember.ArrayController.extend, you're actually just extending the class not creating a concrete instance, therefore you can't call loadSomeVideos.
There are a few conventions in Ember that can get you stumped if you're unaware of them. As commented by "Unspecified", you should use the following convention to extend the class.
Please note the upper case VideoController and also the way in which I'm defining the loadSomeVideos method:
App.VideoController = Ember.ArrayController.extend({
loadSomeVideos: function() {
console.log("I have run");
}
});
Now, if you want to run this, you need to create an instance of the App.VideoController class. Once again notice the capitalisation:
App.videoController = App.VideoController.create();
So, I use a lower case v for the instance, and an upper case V for the class. I've just created an instance (App.videoController) of the class (App.VideoController).
To call your method, you need to call it from the instance, like this:
App.videController.loadSomeVideos();
Check out the following two pages in the documentation.
This first page gives you some info about extending classes and then instantiating them so you can call their methods:
http://emberjs.com/guides/object-model/classes-and-instances/
The second page goes into a bit of depth about more advanced methods reopen and reopenClass.
http://emberjs.com/guides/object-model/reopening-classes-and-instances/
I'm trying to override the +initialize method of a class using ASOC, but I cannot find a way to override a class method. Is it even possible?
Not to let any confusion possible about the language I'm talking about, here's some code:
script FLAppDelegate
property parent: class "NSObject"
-- -- Class Methods -- --
-- Insert code here
end script
I've done some tests, and as far as I can tell, weird as it is, methods defined using AppleScriptObjC are both class and instance methods.
Let's say I have an AppleScriptObjC file:
script iTunesController
property parent: class "NSObject"
on playpause()
tell application id "com.apple.iTunes" to playpause
end playpause
end script
In an Objective-C method, both:
- (void)callASOC
{
iTunesControllerInstance = [NSClassFromString(#"iTunesController") new];
[iTunesControllerInstance playpause];
[iTunesControllerInstance release];
}
and
- (void)callASOC
{
[NSClassFromString(#"iTunesController") playpause];
}
will call the playpause handler in the AppleScriptObjC file. The latter formulation will generate a warning a compile time, but works.
I was not able to find any documentation confirming or refuting this.
Thanks to #Friziab who reminded me of the NSClassFromString
So I could call a AppleScriptObjC method in my AppDelegate.applescript from another class (script) (NSView subclass)
I don't use AppleScriptObjC so there may be a proper way of doing it but this worked
current application's NSClassFromString("AppDelegate")'s popWindow()
Is this a problem? I believe that the warning:
[Action update]. override me
comes from directly calling [myAction update] on my own action. Which I'm not doing.
Can I just comment out the log warning? This gives me a dirty feeling. But everything seems to work fine...
This was in Cocos2D 1.1 and also in 2.0rc2.
You probably created a class that inherits from CCAction. Some code in CCAction will call the 'update' method. So 1) either you did not provide an 'update' method in your class, or 2) in your classe's update method your are invoking [super update]. If you really have nothing to do in the update cycle, just put an empty procedure in your class.
-(void) update:(ccTime) dt{
}
Try using [CCEaseOut actionWithDuration:xxx]