#include "Touch_and_Move.h"
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();
auto openGl_location = touch-> getLocation();
auto move_action = MoveTo::create(1.f, openGl_location);
cloud-> runAction(move_action);
CCLOG("%.1f %.1f", cloud-> getPositionX(), cloud-> getPositionY());
};
this-> getEventDispatcher()-> addEventListenerWithSceneGraphPriority(event_listener, cloud);
return true;
}