Problem with manual draw - CCSprite/CCTexture2D 2.x

Hi everyone,
I’m having a problem with overloading draw() method from CCLayer,
CCSprite and CCTexture2D. I hope someone could help me.

The main problem is that the Texture doesn’t move, it’s remain static in screen, at
point (0,0) but i don’t understand why.

some related code:

void LayerGame::onEnter()
{
    CCLayer::onEnter();
    //i'm caching the textures
    m_Tex1 = CCTextureCache::sharedTextureCache()->addImage("spr1.png");
    m_Tex2 = CCTextureCache::sharedTextureCache()->addImage("spr2.png");
    m_Tex3 = CCTextureCache::sharedTextureCache()->addImage("spr3.png");

    m_Tex1->retain();
    m_Tex2->retain();
    m_Tex3->retain();
}

void LayerGame::draw()
{
    CCLayer::draw();
    CCSprite* spr1 = CCSprite::createWithTexture(m_Tex1);

    //here i put static positions, but the sprites are moved constantly
    //by calculations
    spr1->setPosition( ccp(100, 200) );
    //but the texture(s) are in position (0,0).!! :(            
    //the spr1->getPosition().x reports moving.
    spr1->draw();
}

I missed some code for draw?.
what’s the problem with my code? :frowning:

thanks to everyone.

I’m not sure what you are trying to achieve, but shouldn’t you be creating your sprite in your onEnter and adding it to the layer “this->addChild(spr1, 0);”.

Why are you overriding draw for this?
Why are you creating your sprite in the draw(), do you realise you will be creating a new sprite every time draw() is called?

Gav, thanks for your response!.

Basically, I want to control every sprite in each frame.
but adding as a child is not what I want.

I add the following line and it worked.

spr1->getTexture()->drawAtPoint(ccp(100,200));

but I want to rotate, and scale texture (by sprite, not by texture) but it’s not working.
there’s an option for this?

thanks.

well…

if someone is facing the same problem.

the method for draw in/for sprite… is not draw(), is visit()
visit() method draw recursively, that’s why I cannot do draw.

thanks.