Vector Sprites Count Function (not working)

  • koko82
    Likes 0

    Problem Description

    Hi All,

    I am trying to create a vector of the same graphic, it creates the graphic but not matching the if statement, I have noticed in log that it doesnt seem to increment size of the vector and looks like its creating a new vector for the sprite each time when I want it to use the exisiting one. Please could someone point me inright direction..

     

    bool HelloWorld::init()
    {
     std::vector<Sprite*> _vMySprites;
    
     HelloWorld::referenceVector(_vMySprites);
     HelloWorld::referenceVector(_vMySprites);
     HelloWorld::referenceVector(_vMySprites);
     HelloWorld::referenceVector(_vMySprites);
    
    }
    
    void HelloWorld::referenceVector(std::vector<Sprite*> random )                       
    {
    
        if ( (_vMySprites.size()) < 5 ){
            
            log("Size of sprites: %lu", _vMySprites.size() );
            
            cocos2d::Sprite* foo = cocos2d::Sprite::create("closed.png");
            
            foo->setPosition( Point( 60, 100 ) );
            foo->setTag(2);
            random.push_back(foo); // add our sprite to vector for storage.
            
            addChild(foo, 1);
        }
    }

     

  • Sonar Systems admin
    Likes 0

    Try calling

    HelloWorld::referenceVector(_vMySprites);
    

    as

    referenceVector(_vMySprites);

     

Login to reply