我正在开发一个使用cocos2d-x v3.3的游戏。
在我的游戏中,我有一个直线的精灵图像,它以360度连续旋转。在线的边缘有另一个球精灵。
所以在我的游戏中,我想要的是每当我触摸屏幕时,它应该开始旋转,在触摸结束时,线边缘的球应该沿着线指向的方向移动。
发布于 2015-04-20 13:31:53
谢谢。。我的代码在这里。
Circle1 = Sprite::create("circleT.png");
Circle1->setPosition(winSize.width/2,winSize.height/3.8);
this->addChild(Circle1,1);
line = Sprite::create("line.png");
line->setAnchorPoint(Vec2(0.5, 1.0));
line->setPosition(Circle1->getBoundingBox().size.width/2,0);
Circle1->addChild(line,1);
bullet = Sprite::create("bullet.png");
bullet->setPosition(Vec2 (winSize.width/2,winSize.height/4));
this->addChild(bullet);
Point offset = ccpSub(touchLocation, bullet->getPosition());
float ratio = offset.x/offset.y;
int targetY = winSize.height - bullet->getContentSize().height;
float disY = -(bullet->getPositionY() - targetY);
int targetX = (disY * ratio) + bullet->getPositionX();
CCPoint touchPoint = ccp(targetX*20,targetY*20);
MoveTo *bulletmove = MoveTo::create(1, Vec2(touchPoint));
bullet->runAction(bulletmove);在TouchBegin上,我调用了旋转圆的方法,现在在代码中,我的项目符号位于触摸位置。所以想要子弹应该朝直线的方向。
https://stackoverflow.com/questions/29643229
复制相似问题