Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include "Touch_and_Move.h"
  2.  
  3. Scene* TouchMove::createScene()
  4. {
  5.     auto scene = Scene::create();
  6.     auto layer = TouchMove::create();
  7.     scene->addChild(layer);
  8.     return scene;
  9. }
  10.  
  11. bool TouchMove::init()
  12. {
  13.     if(!Layer::init())
  14.     {
  15.         return false;
  16.     }
  17.  
  18.     this-> background = Sprite::create("BG-HD.png");
  19.     this-> background-> setPosition(TouchMove::screen().width/2, TouchMove::screen().height/2);
  20.     this-> addChild(background, -1);
  21.  
  22.     this-> cloud = Sprite::create("cloud-HD.png");
  23.     this->cloud->setPosition(100, 600);
  24.     this-> addChild(cloud, 10);
  25.  
  26.     auto event_listener = EventListenerTouchAllAtOnce::create();
  27.     event_listener -> onTouchesEnded = [=](const std::vector<Touch*>& pTouches, Event* event){
  28.         auto touch = *pTouches.begin();
  29.         auto openGl_location = touch-> getLocation();
  30.  
  31.         auto move_action = MoveTo::create(1.f, openGl_location);
  32.         cloud-> runAction(move_action);
  33.         CCLOG("%.1f %.1f", cloud-> getPositionX(), cloud-> getPositionY());
  34.     };
  35.  
  36.     this-> getEventDispatcher()-> addEventListenerWithSceneGraphPriority(event_listener, cloud);
  37.  
  38.     return true;
  39. }