An easy question :)

Im a fresh in cocos2d-x
Today i try to write first cocos2d-x project of my
I wana draw a Sprite on it while i touch the screen

i do it like this

Add these in HelloWorldScense.h

    //Touch
    virtual void registerWithTouchDispatcher(void);
    virtual void ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);
    virtual void ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);
    virtual void ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);

then add these in HelloWorldScense.cpp

    void HelloWorld::registerWithTouchDispatcher(void)
    {
        CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this, 0);
    }

    void HelloWorld::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
    {
        CCSetIterator iter = pTouches->begin();
        for (; iter != pTouches->end(); iter++)
        {
            CCTouch* pTouch = (CCTouch*)(*iter);
            CCPoint location = pTouch->getLocation();

            CCSprite* pSprite = CCSprite::create("HelloWorld.png");
            CC_BREAK_IF(! pSprite);

            pSprite->setPosition(location);

            addChild(pSprite, 0);

        }
    }

    void HelloWorld::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
    {
        CCSetIterator iter = pTouches->begin();
        for (; iter != pTouches->end(); iter++)
        {
            CCTouch* pTouch = (CCTouch*)(*iter);
            CCPoint location = pTouch->getLocation();

        }
    }

    void HelloWorld::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
    {
        CCSetIterator iter = pTouches->begin();
        for (; iter != pTouches->end(); iter++)
        {
            CCTouch* pTouch = (CCTouch*)(*iter);
        }
    }

But nothing work
I event dong know how to “debug or print anything” to confirm the funtion is run?

I event dong know how to “debug or print anything” to confirm the funtion is run?

Use CCLOG() to output anything to console

Sergey Neskin wrote:

> I event dong know how to “debug or print anything” to confirm the funtion is run?
>
Use CCLOG () to output anything to console

Yes I know about that and add it in the init()
but I don’t konw why it doesn’t work
Look the image i pos

I slove it
Add this line in the end of init()+ instead of+ the head of

this->setTouchEnable(true);