Tuesday, August 30, 2022
HomeGame DevelopmentThe way to cease an replace technique when one thing occurs? -...

The way to cease an replace technique when one thing occurs? – cocos2d-x


Hello,
up to now I’ve utilized in my sport scheduleUpdate(), schedule() and scheduleOnce(). However I believe they method I’m utilizing a few of these strategies is just not 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 regarded into the overload of the schedule strategies, however I’m not positive if any does what I’m asking.

There’s this one

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

it says: @param key The important thing of the lambda perform. For use if you wish to unschedule it.
However 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 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 drive my code to maintain checking if someSprite exists.
Any extra optimum strategies or is that this high-quality?

thanks,
R


Thats why it’s 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));

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments