zoukankan      html  css  js  c++  java
  • cocos2dx 3.x(移动修改精灵坐标MoveTo与MoveBy)

     1 //
     2 //  MainScene.cpp
     3 //  helloworld
     4 //
     5 //  Created by apple on 16/11/8.
     6 //
     7 //
     8 
     9 #include "MainScene.hpp"
    10 Scene * MainScene::createScene()
    11 {
    12      auto scene = Scene::create();    //创建层
    13     MainScene *layer = MainScene::create();
    14     scene->addChild(layer);
    15     return scene;
    16 }
    17 bool MainScene::init(){
    18     if (!Layer::init()) {
    19         return false;
    20     }
    21     
    22     
    23 //    MoveTo:把某一Sprite移动到某个位置
    24 //    MoveBy:把某一Sprite移动一段距离,它有一个方法reverse,它让对象按原路径返回
    25     
    26     
    27     /*
    28      *@MoveTo,移动到某个Point
    29      */
    30     Size size = Director::getInstance()->getWinSize();
    31     Sprite *spriteMoveTo = Sprite::create("snow.png");
    32     spriteMoveTo->setPosition(Vec2(size.width / 2.0f, size.height / 2.0f));
    33     this->addChild(spriteMoveTo, 1);
    34     
    35     ActionInterval *forward = MoveTo::create(4, Vec2(300, 300));
    36     spriteMoveTo->runAction(forward);
    37     
    38     
    39     /*
    40      *MoveBy,移动一段距离
    41      */
    42     Sprite *spriteMoveBy = Sprite::create("snow.png");
    43     spriteMoveBy->setPosition(Vec2(size.width / 4.0f, size.height / 4.0f));
    44     this->addChild(spriteMoveBy, 1);
    45     
    46     ActionInterval *forwardBy = MoveBy::create(2, Vec2(200, 300));
    47     ActionInterval *backBy = forwardBy->reverse();
    48     Action *action = Repeat::create(dynamic_cast<FiniteTimeAction *>(Sequence::create(forwardBy, backBy, NULL)), 4);
    49     spriteMoveBy->runAction(action);
    50     
    51     
    52     
    53     return true;
    54 }
  • 相关阅读:
    2013-9-29 通信原理学习笔记
    《大数据时代》阅读笔记
    《人人都是产品经理》阅读笔记一
    2013-8-13 信道接入技术研究学习
    2013-8-6 ubuntu基本操作
    2013-7-30 802.1X企业级加密
    2013-7-29 杂记
    2013-7-28 802.11n帧聚合
    2013-7-27 802.1X学习
    vue+node+mongoDB前后端分离个人博客(入门向)
  • 原文地址:https://www.cnblogs.com/luorende/p/6045424.html
Copyright © 2011-2022 走看看