c++ - How to change the direction of a moving sprite at screen edges? -
c++ - How to change the direction of a moving sprite at screen edges? -
i using code in cocos2d-x shooting in specific directions @ border of screen sprite(i.e. shooting bubbles) used lost. need help in making alter angle when collides @ screen edges , alter direction go up.
code in c++ using cocos2dx:-
ccsize winsize = ccdirector::shareddirector()->getvisiblesize(); ccpoint origin = ccdirector::shareddirector()->getvisibleorigin(); // determinie offset of location projectile float offx = flocationx - m_powner->getposition().x; float offy = flocationy - m_powner->getposition().y; // bail out if shooting downwards or backwards if (offy <= 0) return; // ok add together - we've double checked position // determine wish shoot projectile //float realx = origin.x + winsize.width + (m_powner->getposition().x); float realy = origin.y + winsize.height + (m_powner->getposition().y); // float ratio = offy / offx; float ratio = offx / offy; //float realy = (realx * ratio) + m_powner->getposition().y; float realx = (realy * ratio) + m_powner->getposition().x; ccpoint realdest = ccp(realx, realy); // determine length of how far we're shooting float offrealx = realx - m_powner->getposition().x; float offrealy = realy - m_powner->getposition().y; float length = sqrtf((offrealx * offrealx) + (offrealy*offrealy)); float velocity = 480/1; // 480pixels/1sec float realmoveduration = length/velocity; // move projectile actual endpoint m_powner->runaction( ccsequence::create( ccmoveto::create(realmoveduration, realdest), cccallfuncn::create(getowner()->getparent()->getcomponent("scenecontroller"), callfuncn_selector(scenecontroller::spritemovefinished)), null) );
c++ cocos2d-x
Comments
Post a Comment