c++ - How to get position of CCSprite added to CCParallaxNode? -


i have ccparallaxnodeextras scrolls infinite (following space game tutorial). added child ccsprite made of other ccsprite, this:

_backgroundnode = ccparallaxnodeextras::node(); this->addchild(_backgroundnode,-2);      float acum = 0.0;     back1 = ccsprite::create();     for(int = 0; < num_repeats; ++i) {         ccsprite *back = ccsprite::createwithspriteframename("rock.png");         back->setposition(ccp(acum, 0));         back1->addchild(back);         acum+= back->getcontentsize().width+150.0;     }      _backgroundnode->addchild(back1,  1 , ccp(0.1,0.1), ccp(0, winsize.height * 0.64)); 

now in update have this:

ccpoint backgroundscrollvert = ccp(-1024, 0); _backgroundnode->setposition(ccpadd(_backgroundnode->getposition(), ccpmult(backgroundscrollvert, dt))); 

perfect, background moves , disappears (that want now) need collision between sprites on background , fixed sprite child of main node.

the problem whenever try collision simple way (intersecting bounding boxes) doesn't work, tried position of sprites , position fixed in ccsprite (back1) composed sprites (back).

now, there possible way position of individual sprite located in parallax node? if try like:

ccsprite *tempsprite = (ccsprite*)_backgroundnode->getchildren()->objectatindex(0); printf("%f\n", tempsprite->getchildren()->objectatindex(0)->getpositionx()); 

it prints same value, position not being affected transformation of parent in background node... so, how correctly? how position relative screen , not parent?

use converttoworldspace function position in parent. if nodes nested need query 1 one.

    cgpoint pos1 = [back1 converttoworldspace: back.position];         cgpoint pos2 = [_backgroundnode converttoworldspace: pos1]; 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -