实现物体的方向跟着拖拽的方向
来源:互联网 发布:中国联通4g网络设置 编辑:程序博客网 时间:2024/06/06 15:45
实现物体的方向跟着拖拽的方向
bool Hero::touchBegin(Touch* touch,Event* event){auto target = static_cast<Sprite*>(event->getCurrentTarget());//得到对象if (target->getBoundingBox().containsPoint(touch->getLocation())){target->setOpacity(200);return true;}return false;}void Hero::touchMoved(Touch* touch,Event* event){auto target = static_cast<Sprite*>(event->getCurrentTarget());static Point oldPosition = Point(-1,-1);static Point newPosition = Point(-1,-1);if (oldPosition.x ==-1){oldPosition = target->getPosition();}else{oldPosition = newPosition;newPosition = target->getPosition();float width = newPosition.x - oldPosition.x;float height = newPosition.y - oldPosition.y;if (isActionDone){float radian;float angle;if (height>0&&width<0){radian=atan(width/ height);//h弧度angle = (radian*360)/(2*3.141592);//化成角度了}if (height>0&&width==0){angle = 0;}if (height>0&& width>0){radian=atan(width/ height);//h弧度angle = (radian*360)/(2*3.141592);//化成角度了}if (height==0&&width >0){angle = 90;}if (height<0&&width>0){radian=atan( height/width);//h弧度angle = (radian*360)/(2*3.141592);//化成角度了angle =90- angle;}if (height<0&&width==0){angle = 180;}if (height<0&&width<0){radian=atan(width/ height);//h弧度angle = (radian*360)/(2*3.141592);//化成角度了angle+=180;}if (height==0&&width<0){angle = 270;}CallFunc * funcall= CallFunc::create(this, callfunc_selector(Hero::actionDone));FiniteTimeAction* actionRotateBy= RotateTo::create(0.1,angle);FiniteTimeAction* task = Sequence::create(actionRotateBy,funcall, NULL);runAction(task);isActionDone = false;}}target->setPosition(target->getPosition() + touch->getDelta());//防出界if (target->getPositionX()<0){target->setPositionX(0);}if (target->getPositionX()>Director::getInstance()->getWinSize().width){target->setPositionX(Director::getInstance()->getWinSize().width);}if (target->getPositionY()<0){target->setPositionY(0);}if (target->getPositionY()>Director::getInstance()->getWinSize().height){target->setPositionY(Director::getInstance()->getWinSize().height);}}void Hero::touchEnded(Touch* touch,Event* event){auto target = static_cast<Sprite*>(event->getCurrentTarget());target->setOpacity(255);}
0 0
- 实现物体的方向跟着拖拽的方向
- 物体运动的切线方向
- unity3d游戏物体跟着鼠标方向移动
- unity3d游戏物体跟着鼠标方向移动
- unity3d游戏物体跟着鼠标方向移动
- unity3d游戏物体跟着鼠标方向移动
- 没有方向的方向
- 答大二学生:跟着自己的兴趣定方向
- Unity获取物体自身坐标轴的方向以及沿着该方向运动的方法
- 操作物体任意方向旋转的三种方法
- 基础代码--物体向手指滑向的方向移动
- Shape Faces and Winding(物体的方向和环绕)
- unity3d 判断目标物体对于我的方向
- U3D实现键盘控制物体方向
- 竖直方向的ViewPager的实现方式
- 心的方向就是幸福的方向
- jquery实现可控方向图片的滚动
- 使用CSS实现各个方向的三角形
- FZU - 2038 Another Postman Problem
- 判断二叉树是否为二叉搜索树BST
- jbpm4.4集成入SSH项目中
- poj 1276 Cash Machine
- Finagle:一个支持多协议的RPC系统
- 实现物体的方向跟着拖拽的方向
- yum 命令
- Launcher2<一>
- Hadoop、HBase配置Ganglia指南(metrics1)
- Ant 构建Solr过程中checksum出错的问题
- Daily article(4)
- 如何利用Javap工具对.class文件进行查看
- 十六周项目二----指来指去2
- android 消失软件盘