Code have this->setTouchEnabled(true); but not work touch
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
#include <Box2D/Box2D.h>
#include "GLES-Render.h"
USING_NS_CC;
class HelloWorld : public cocos2d::CCLayer
{
public:
~HelloWorld();
HelloWorld();
void initPhysics();
virtual void draw();
void update(float dt);
virtual bool init();
static cocos2d::CCScene* scene();
void menuCloseCallback(CCObject* pSender);
CREATE_FUNC(HelloWorld);
virtual void ccTouchesEnded(CCSet* touches, CCEvent* event);
virtual void ccTouchesBegan(CCSet* touches, CCEvent* event);
virtual void ccTouchesMoved(CCSet* touches, CCEvent* event);
private:
void createBallon();
};
#endif // __HELLOWORLD_SCENE_H__
#include “HelloWorldScene.h”
//#include <Box2D/Box2D.h>
//#include “GLES-Render.h”
USING_NS_CC;
#define PTM_RATIO 32
USING_NS_CC;
CCSprite *ball1;
HelloWorld::HelloWorld(){
this->setTouchEnabled(true);
scheduleUpdate();
}
HelloWorld::~HelloWorld(){
}
void HelloWorld::initPhysics() {
//CCSprite* paddle = CCSprite::create("HelloWorld.png");
}
void HelloWorld::draw()
{
CCLayer::draw();
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
kmGLPushMatrix();
kmGLPopMatrix();
}
void HelloWorld::update(float dt)
{
}
CCScene* HelloWorld::scene()
{
//paddle
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
void HelloWorld::createBallon(){
double ballPosit=50;
CCSprite *ball=CCSprite::create("textures/balloon.png");
ball->setPosition(ccp(370, 340+ballPosit));
this->addChild(ball);
CCSprite *basket=CCSprite::create("textures/basket.png");
basket->setPosition(ccp(370, 275+ballPosit));
this->addChild(basket);
}
// on “init” you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);
// position the label on the center of the screen
pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - pLabel->getContentSize().height));
// add the label as a child to this layer
this->addChild(pLabel, 1);
// add "HelloWorld" splash screen"
// CCSprite* pSprite = CCSprite::create(“HelloWorld.png”);
ball1=CCSprite::create("HelloWorld.png");
ball1->setPosition(ccp(300, 500));
ball1->setTag(1);
this->addChild(ball1,0);
createBallon();
return true;
}
void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event)
{
CCSetIterator i;
CCTouch* touch;
CCLOG("touch");
for( i = touches->begin(); i != touches->end(); i++) {
touch = (CCTouch*) (*i);
}
}
void HelloWorld::ccTouchesBegan(CCSet* touches, CCEvent* event)
{
CCSetIterator i;
CCTouch* touch;
ball1->setVisible(false);
for( i = touches->begin(); i != touches->end(); i++) {
touch = (CCTouch*) (*i);
CCLOG(“touch”);
}
}
void HelloWorld::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
CCSetIterator i;
CCTouch* touch;
for( i = touches->begin(); i != touches->end(); i++) {
touch = (CCTouch*) (*i);
CCLOG("touch");
}
}
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
CCMessageBox(“You pressed the close button. Windows Store Apps do not implement a close button.”,“Alert”);
#else
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
#endif
}