Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Touch_and_Move.h"
- static bool screen_paused = false;
- Scene* TouchMove::createScene()
- {
- auto scene = Scene::create();
- auto layer = TouchMove::create();
- scene->addChild(layer);
- return scene;
- }
- bool TouchMove::init()
- {
- if(!Layer::init())
- {
- return false;
- }
- this-> background = Sprite::create("BG-HD.png");
- this-> background-> setPosition(TouchMove::screen().width/2, TouchMove::screen().height/2);
- this-> addChild(background, -1);
- this-> cloud = Sprite::create("Cloud-HD.png");
- this-> cloud->setPosition(100, 600);
- this-> addChild(cloud, 10);
- auto event_listener = EventListenerTouchAllAtOnce::create();
- event_listener -> onTouchesEnded = [=](const std::vector<Touch*>& ptouches, Event* event){
- auto touch = *ptouches.begin();
- if (!screen_paused){
- screen_paused = true;
- //this->pauseSchedulerAndActions();
- Director::getInstance()->pause();
- }
- else
- {
- screen_paused = false;
- //this->resumeSchedulerAndActions();
- Director::getInstance()->resume();
- }
- };
- this-> getEventDispatcher()-> addEventListenerWithSceneGraphPriority(event_listener, cloud);
- //this->schedule(schedule_selector(TouchMove::update),.01);
- this-> scheduleUpdate();
- return true;
- }
- void TouchMove::update(float dt)
- {
- auto scroll = Point(-1,0);
- CCLOG("%f", cloud-> getPositionX());
- if (cloud-> getPositionX() < 0){
- cloud-> setPositionX(TouchMove::screen().width);
- }
- cloud-> setPositionX(cloud-> getPositionX()+scroll.x);
- }
Advertisement
Add Comment
Please, Sign In to add comment