Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool HelloWorld::init()
- {
- //////////////////////////////
- // 1. super init first
- if ( !Layer::init() )
- {
- return false;
- }
- Size visibleSize = Director::getInstance()->getVisibleSize();
- Vec2 origin = Director::getInstance()->getVisibleOrigin();
- auto mySprite = Sprite::create("First.png");
- mySprite->setPosition(Point((visibleSize.width / 2) + origin.x, (visibleSize.height / 2) + origin.y));
- this->addChild(mySprite);
- auto listener = EventListenerTouchOneByOne::create();
- listener->setSwallowTouches(true);
- listener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);
- _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
- return true;
- }
- bool HelloWorld::onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event)
- {
- CCLOG("onTouchBegan x = %f, y = %f", touch->getLocation().x, touch->getLocation().y);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement