Reuse FadeOut Sprite

  • MoseHas
    Likes 1

    Problem Description

    Hi there.

    I want to create an effect like halo. My problem is that I will create a halo sprite everytime I click. I think it is not good.

    Do I have better way to implement it?

    Thanks.

     

    	...
    
    	EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
    	listener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);
    	Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
    
    	return true;
    }
    
    bool HelloWorld::onTouchBegan(Touch* touch, Event* event)
    {
    	Size visibleSize = Director::getInstance()->getVisibleSize();
    	//halo->setOpacity(128);
    	halo = Sprite::create("halo.png");
    	Point p = touch->getLocationInView();
    	p = Director::getInstance()->convertToGL(p);
    	halo->setPosition(p.x, p.y);
    	this->addChild(halo, 2);
    
    	auto enlarger = ScaleBy::create(1.0f, 5.0f, 5.0f);
    	//halo->runAction(enlarger);
    	auto fadeout = FadeOut::create(1.0f);
    	//halo->runAction(fadeout);
    
    	halo->runAction(Spawn::create(enlarger, fadeout,NULL));
    	
    
    	return true;
    }

     


  • Sonar Systems admin
    Likes 0

    No it should be fine.

  • MoseHas
    Likes 2

    Does cocos2d-x release the unused objects automatically?

    I thought keep creating sprites will consume resource.


    This reply has been verified.
  • Sonar Systems admin
    Likes 0

    Cocos2d-x will release it’s own objects such as sprites and particles.


    This reply has been verified.

Login to reply