Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include "Touch_and_Move.h"
  2. static bool screen_paused = false;
  3.  
  4. Scene* TouchMove::createScene()
  5. {
  6.     auto scene = Scene::create();
  7.     auto layer = TouchMove::create();
  8.     scene->addChild(layer);
  9.     return scene;
  10. }
  11.  
  12. bool TouchMove::init()
  13. {
  14.     if(!Layer::init())
  15.     {
  16.         return false;
  17.     }
  18.  
  19.     this-> background = Sprite::create("BG-HD.png");
  20.     this-> background-> setPosition(TouchMove::screen().width/2, TouchMove::screen().height/2);
  21.     this-> addChild(background, -1);
  22.  
  23.     this-> cloud = Sprite::create("Cloud-HD.png");
  24.     this-> cloud->setPosition(100, 600);
  25.     this-> addChild(cloud, 10);
  26.  
  27.     auto event_listener = EventListenerTouchAllAtOnce::create();
  28.     event_listener -> onTouchesEnded = [=](const std::vector<Touch*>& ptouches, Event* event){
  29.         auto touch = *ptouches.begin();
  30.         if (!screen_paused){
  31.             screen_paused = true;
  32.             //this->pauseSchedulerAndActions();
  33.             Director::getInstance()->pause();
  34.         }
  35.         else
  36.         {
  37.             screen_paused = false;
  38.             //this->resumeSchedulerAndActions();
  39.             Director::getInstance()->resume();
  40.         }
  41.     };
  42.  
  43.     this-> getEventDispatcher()-> addEventListenerWithSceneGraphPriority(event_listener, cloud);
  44.     //this->schedule(schedule_selector(TouchMove::update),.01);
  45.     this-> scheduleUpdate();
  46.     return true;
  47. }
  48.  
  49. void TouchMove::update(float dt)
  50. {
  51.     auto scroll = Point(-1,0);
  52.     CCLOG("%f", cloud-> getPositionX());
  53.     if (cloud-> getPositionX() < 0){
  54.         cloud-> setPositionX(TouchMove::screen().width);
  55.     }
  56.     cloud-> setPositionX(cloud-> getPositionX()+scroll.x);
  57.  
  58. }