TOUCH VERRY LAGGGGGGGGGGGGGGGGG.......................

I use ccTouches_xxx method to notify touch event. But, when player touch to scene (normal or fast), game seem to be lag: action and node pause. Sorry I use English not well. This is my code:

void HelloWorld::ccTouchesBegan(CCSet *touches, CCEvent *event)
{

    CCTouch *touch = (CCTouch*) (touches->anyObject());

    CCPoint point = touch->locationInView(touch->view());

    point = CCDirector::sharedDirector()->convertToGL(point);

    createAndAnimateFlower(point);

}

Did you touch many times?
If so, HelloWorld::ccTouchesBegan() will be called many times, and will cal createAndAnimateFlower() many times.
I don’t if it is the problem.

Yes. When player touch, it add a sprite (flower) and animate the flower. I test automatic call createAndAnimateFlower() (use schedule), so it is work well, not lag.

I don’t understand what’s the problem.
>> game seem to be lag
What’s the meaning?

when player touch many times (fast) to scene, the game pause about some seconds, after when stop touch, game resume and new node (was added by touch) animate.

Post your code for createAndAnimateFlower(), it is probably the way you are creating your sprites or textures. At a guess you need to use a sprite sheet (CCSpriteBatchNode).

Here is all code:

#include "HelloWorldScene.h"

USING_NS_CC;

CCScene* HelloWorld::scene()
{
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::node();

    // 'layer' is an autorelease object
    HelloWorld *layer = HelloWorld::node();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object

    this->setIsTouchEnabled(true);

    CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(
                                        "CloseNormal.png",
                                        "CloseSelected.png",
                                        this,
                                        menu_selector(HelloWorld::menuCloseCallback) );
    pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );

    // create menu, it's an autorelease object
    CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL);
    pMenu->setPosition( CCPointZero );
    this->addChild(pMenu, 1);


    CCSize size = CCDirector::sharedDirector()->getWinSize();



    // add "HelloWorld" splash screen"
    CCSprite* pSprite = CCSprite::spriteWithFile("background1.png");

    // position the sprite on the center of the screen
    pSprite->setPosition( ccp(size.width/2, size.height/2) );

    // add the sprite as a child to this layer
    this->addChild(pSprite, 0);





    //enable touch
    this->schedule(schedule_selector(HelloWorld::update));

    srand(20);

    elapsed = 0;

    return true;
}

void HelloWorld::menuCloseCallback(CCObject* pSender)
{
    CCDirector::sharedDirector()->end();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    exit(0);
#endif
}

CCAnimation* HelloWorld::makeAnimation(const char *filename, int rowCount, int colCount)
{
    CCImage *image = new CCImage();
    image->initWithImageFile(filename, CCImage::kFmtPng);

    float tileWidth = image->getWidth() / colCount;
    float tileHeight = image->getHeight() / rowCount;

    CCTexture2D *texture = new CCTexture2D();
    texture->initWithImage(image);



    delete image;

    CCAnimation *animation = CCAnimation::animation();



    for (int row = 0; row < rowCount; row++)
        for (int col = 0; col < colCount; col++)
        {
            CCRect rect(col * tileWidth, row * tileHeight,  tileWidth, tileHeight);

            animation->addFrameWithTexture(texture, rect);
        }

    return animation;
}

void HelloWorld::animateFinish(CCNode *pTarget)
{
    this->removeChild(pTarget, true);

}

void HelloWorld::ccTouchesEnded(CCSet *touches, CCEvent *event)
{


    CCTouch *touch = (CCTouch*) (touches->anyObject());


    CCPoint point = touch->locationInView(touch->view());

    point = CCDirector::sharedDirector()->convertToGL(point);

    createAndAnimateFlower(point);

    return;
}




void HelloWorld::createAndAnimateFlower(CCPoint point)
{
    firework1_animation = makeAnimation("firework1.png", 3, 5);

    CCActionInterval* action = CCAnimate::actionWithDuration(2, firework1_animation, false);

    CCFiniteTimeAction *sequence = CCSequence::actions(
        action,
        CCCallFuncN::actionWithTarget(this, callfuncN_selector(HelloWorld::animateFinish)),
        NULL
        );


    CCSprite *sprite = CCSprite::spriteWithFile("CloseNormal.png");

    sprite->runAction(sequence);

    sprite->setPosition(point);


    this->addChild(sprite);
}

void HelloWorld::update(ccTime dt)
{


    elapsed += dt;

    if (elapsed >= 1)
    {
        float f = rand() % 100;

        //createAndAnimateFlower(ccp(100 + f, 100 + f));
        elapsed = 0;
    }

}

You could look at optimizing things a bit, might be part of the problem. You seem to be calling “firework1_animation = makeAnimation(”firework1.png“, 3, 5);” each time you create a flower, why not call this once in your init and just reuse “firework1_animation”.

I tried it but got a runtime error. :frowning: crazy!

Try calling retain on it so it will be kept in memory.
When done with it dont forget to release it.

Ok. AWSOME, SO AWSOME. THANKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK