Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17112

Sprite position to placed

$
0
0

@NEOISBACK wrote:

I am working on a game in which sprite is rotated using action .If user tap on the screen then rotating sprite stops.A new sprite is created and placed on the first sprite.But I am not able to get proper position.
It will be very kind if someone provide help;
thanx in advance
smile

create First sprite which is rotating.....

auto platform = Sprite::create( "_Nut.png");
platformList.push_back(platform);
platformList.at(0)->setPosition(Vec2(RandomHelper::random_int(platform_WIDTH, size.width - platform_WIDTH), i * (gap_platform + platform_HEIGHT) + platform_HEIGHT / 2 + lowerSpace));
platformList.at(i)->setScale(0.3f);
addChild(platformList.at0i), 1);
platformList.at(0)->runAction(RepeatForever::create(RotateBy::create(2, 360.0f)));
now when user tap on device....
//stop the action
platformList.at(0)->stopAllActions();
//get the angle
auto rotar = platformList.at(0)->getRotation();
movementAngle = (platformList.at(0)->getRotation());
//create another sprite
dummyPlayer = Sprite::create( "sprite3.png", Rect(0, 0, 200, 200));
dummyPlayer->setScale(0.3f);
addChild(dummyPlayer,2);
//get postion on first sprite
auto dacoit = (dummyPlayer->getContentSize().height*dummyPlayer->getScale()) /2+(platformList.at(0)->getContentSize().height*platformList.at(0)->getScale()) / 2;
dummyPlayer->setRotation(movementAngle);
//find the rcos(theta),rsin(theta)
Vec2 v = Vec2(dacoit*cos(CC_DEGREES_TO_RADIANS(movementAngle)), dacoit * sin(CC_DEGREES_TO_RADIANS(movementAngle)));
//set the position of second sprite
dummyPlayer->setPosition(platformList.at(0)->getPosition() +v);

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 17112

Trending Articles