如何給spine骨骼動畫掛載粒子特效


目的是要把粒子掛載到骨骼動畫的某個一個部件上,其實最主要是找對位置。

預覽效果,左手紅火,右手藍火,很炫吧:)

//init

bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    CCSkeletonAnimation* skeletonNode = CCSkeletonAnimation::createWithFile("spineboy.json", "spineboy.atlas");
    skeletonNode->setAnimation("walk", true);
    skeletonNode->setPosition(ccp(300,0));
    //skeletonNode->debugSlots = true;
    skeletonNode->debugBones = true;
    skeletonNode->timeScale = 0.5f;
    addChild(skeletonNode,0,1);
    
    ParticleSun* _emitter1 = ParticleSun::create();
    _emitter1->setTexture( TextureCache::getInstance()->addImage("fire.png") );
    addChild(_emitter1, 10, 2);

    ParticleGalaxy* _emitter2 = ParticleGalaxy::create();
    _emitter2->setTexture( TextureCache::getInstance()->addImage("fire.png") );
    skeletonNode->addChild(_emitter2, 10, 20);

    scheduleUpdate();

    return true;
}

 

//update

void HelloWorld::update (float deltaTime) 
{
    CCSkeletonAnimation* skeletonNode = (CCSkeletonAnimation*)getChildByTag(1);
    
    Bone* pBone = skeletonNode->findBone("left hand");
    CCPoint pt = skeletonNode->convertToWorldSpace(ccp(pBone->worldX,pBone->worldY));//粒子1是添加在Scene上的 所以需要坐標轉換一下
    ParticleSun* _emitter1 = (ParticleSun*)getChildByTag(2);
    _emitter1->setPosition(pt);

    pBone = skeletonNode->findBone("right hand");
    pt = ccp(pBone->worldX,pBone->worldY);//粒子2直接掛到骨骼動畫上,所以不需要轉換坐標
    ParticleGalaxy* _emitter2 = (ParticleGalaxy*)skeletonNode->getChildByTag(20);
    _emitter2->setPosition(pt);
}

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM