Hello,
to this point I’ve utilized in my sport scheduleUpdate(), schedule() and scheduleOnce(). However I feel they method I’m utilizing a few of these strategies isn’t optimum. For intance, within the sport scene replace() technique I’ve somethinglike this:
void GameScene::replace(float dt)
{
// is that this overkill ??
if (someSprite)
someClass->replace(dt);
//...extra code
This works fines in my sport, however checking each body for one thing that won’t exist anymore at somepoint like someSprite appears an overkill. Mainly I wish to unschedule the replace of someClass if someSprite doesn’t exist anymore.
I appeared into the overload of the schedule strategies, however I’m not certain if any does what I’m asking.
There may be this one
void schedule(const std::operate<void(float)>& callback, const std::string &key);
it says: @param key The important thing of the lambda operate. For use if you wish to unschedule it.
However I not fairly certain the way it works.
In different phrases, I’ve an merchandise that the participant can decide. The merchandise has an replace technique that checks every body for an intersection with the participant. When it intersects, the merchandise disappears. Therefore the if (someSprite) do one thing. However this power my code to maintain checking if someSprite exists.
Any extra optimum ideas or is that this effective?
thanks,
R
Thats why it is best to use customized replace technique, not regular replace
.
// Outline any technique with `float dt` param
void GameScene::updateSprite(float dt) {
// logic
}
// To register
this->schedule(SEL_SCHEDULE(&GameScene::updateSprite));
// To unregister
this->unschedule(SEL_SCHEDULE(&GameScene::updateSprite));
Cool.
I do use customized replace although. As a substitute of SEL_SCHEDULE I exploit CC_SCHEDULE_SELECTOR. In line with the definition it does a solid as SEL_SCHEDULE.
#outline CC_SCHEDULE_SELECTOR(_SELECTOR) static_cast<cocos2d::SEL_SCHEDULE>(&_SELECTOR)
Is there any desire making selected one over the opposite?