Return to Cocos2dx Playback Library

cocos2dx-js getPosition...

Questions related to Cocos2dx playback library should be asked here.

cocos2dx-js getPosition...

Postby 주환 김 » July 19th, 2016, 5:24 pm

cocos2dx-js

i use getPositon, return value is x: 0, y: 0, help...
User avatar
주환 김
 
Posts: 3
Joined: April 5th, 2016, 7:11 pm

Re: cocos2dx-js getPosition...

Postby Dmitry Bushtets » July 19th, 2016, 11:39 pm

Hi!

Please note, that you can't ask
Code: Select all
getPosition
for subObjects of animation
User avatar
Dmitry Bushtets
 
Posts: 86
Joined: August 11th, 2014, 1:31 am

Re: cocos2dx-js getPosition...

Postby Jonathan Reis » November 17th, 2016, 8:53 am

This really happens, I solved this way using cocos2d-x.
Now I have the exact position of a certain inner element.

Code: Select all
auto pos = getPositionGAF("AnchorPoint", _gaf_Anima);

Vec2 Tela_Inicial::getPositionGAF(std::string name, GAFObject * gaf)
{
    auto subobject = gaf->getObjectByName(name);

    const AnimationFrames_t& animationFrames = gaf->getTimeLine()->getAnimationFrames();
    GAFAnimationFrame *currentFrame = animationFrames[ gaf->getCurrentFrameIndex() ];
    currentFrame->getObjectStates();
    for (const GAFSubobjectState* state : currentFrame->getObjectStates())
    {
        if (subobject->objectIdRef == state->objectIdRef)
        {
            cocos2d::AffineTransform stateTransform = state->affineTransform;
            float csf = gaf->getTimeLine()->usedAtlasScale();
            stateTransform.tx *= csf;
            stateTransform.ty *= csf;
           
            return Vec2(stateTransform.tx, stateTransform.ty);
        }
    }
    return Vec2::ZERO;
}
User avatar
Jonathan Reis
 
Posts: 14
Joined: July 14th, 2014, 11:32 am

Return to Cocos2dx Playback Library

Who is online

Users browsing this forum: No registered users and 1 guest