Home Game Development How to cease an replace methodology when one thing occurs? – cocos2d-x

How to cease an replace methodology when one thing occurs? – cocos2d-x

0
How to cease an replace methodology when one thing occurs? – cocos2d-x

[ad_1]

Hi,
up to now I’ve utilized in my sport scheduleUpdate(), schedule() and scheduleOnce(). But I believe they approach I’m utilizing a few of these strategies is just not optimum. For intance, within the sport scene replace() methodology 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. Basically I need to unschedule the replace of someClass if someSprite doesn’t exist anymore.
I regarded into the overload of the schedule strategies, however I’m not positive if any does what I’m asking.

There is that this one

void schedule(const std::perform<void(float)>& callback, const std::string &key);

it says: @param key The key of the lambda perform. To be used if you wish to unschedule it.
But I not fairly positive the way it works.

In different phrases, I’ve an merchandise that the participant can decide. The merchandise has an replace methodology that checks every body for an intersection with the participant. When it intersects, the merchandise disappears. Hence the if (someSprite) do one thing. But this pressure my code to maintain checking if someSprite exists.
Any extra optimum options or is that this fantastic?

thanks,
R

Thats why it’s best to use customized replace methodology, not regular replace.

// Define any methodology 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. Instead of SEL_SCHEDULE I exploit CC_SCHEDULE_SELECTOR. According to the definition it does a solid as SEL_SCHEDULE.

#outline CC_SCHEDULE_SELECTOR(_SELECTOR) static_cast<cocos2d::SEL_SCHEDULE>(&_SELECTOR)

Is there any choice making selected one over the opposite?

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here