What is the issue you have there? As long as Car inherits from Node it should work from a brief look at the code you provided.
Make sure you call super init. Maybe that is what is missing.
ie: in your init()… call a Sprite::init()… I would have set that up a little differently but make sure super inits are done.
Also… as an added tip… If your timing doesn’t HAVE to be 100% frame rate, it is recommended to run it at the maximum acceptable time.
Ex: this->schedule(schedule_selector(SomeSpriteSubclass::update), 0.1f);
This will run the update at 10 times per second.
Sometimes skipping a few frames is unnoticeable depending on your required update logic and can make a difference in overall optimization of the application.
In this way, your custom node can even break up update logic at different intervals…
Ex:
An example would be a custom label that displays the current elapsed time in seconds. It does not have to update at 60fps, it could update on a different scheduled time. Doing that in scheduleUpdate() would make 60x unnecessary executions at 60fps.
Hello,
I’ve tried a lot of things, the only thing that works is:
Director::getInstance()->getScheduler()->schedule(schedule_selector(Car::update), this, 1.0f, false);
I have no idea why this:
this->schedule( schedule_selector( Car::update ), 1.0f );
is not work.
Are you sure your Car class is correctly inheriting from a cocos Node and being initialized via cocos initializations. Try and Copy/Paste the example class I provided above, you can rename it Car
I have successfully solved the problem.
The problem with me was that I missed adding the main subject to the scene, for example
scene-> addChild (sprite);
But from your answers, I definitely learned new things about update methods.
Thank you all.
awesome, yea, dont forget all cocos node inherit from Ref class with auto release management. If you do not add it to a parent node, it will be cleaned up immediately (unless you retain it, but not recommended unless you want to manage memory on top)