Zoom in zoom out into the complete scene?

Hi,

I’m using cocos2dx 3.3.

Please tell me how to zoom in zoom out into the complete scene?(Not on single sprite)

Thanks

Not really clear what exactly you want - but to zoom you can use Node->setScale()

Hi Maxxx, thanks for reply.

I want to zoom entire scene containing many sprites.

All your sprites will be children of one Node (layer) - so just set scale on that node.

Easy as that!

I’m not sure of how this framework works, but on a 2D game, if it uses an ortographic projection on openGL, you could be able to zoom using the size of the projection. Not sure if this can be done, or how.

Hi,

Please tell me how to do that?

I tried

this->setScale(2.0f);

did not worked.

   bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    auto size = Director::getInstance()->getVisibleSize();

    auto s1 = Sprite::create("CloseNormal.png");
    s1->setPosition(Vec2(size.width/2, size.height/2));
    auto s2 = Sprite::create("CloseNormal.png");
    s2->setPosition(Vec2(size.width/3, size.height/2));
    
    
    
    this->addChild(s1);
    this->addChild(s2);
    
    
    
    this->setScale(2.0);
    
    return true;

If you create a cocos2d-x project, replace the init() function with the one above, you will see that setScale of the parent (in this case, ‘this’) does scale the children.

so you are doing something else.

Just saying it didn’t work doesn’t help anyone to help you. In what way didn’t it work? Did the sprites not scale at all? What is ‘this’ in the context you are talking? Is it the parent node for your sprites?

Hi, Maxx

I did exactly the same as you posted.

But there is no scaling.

Hi maxx,

When I tried it on my another project scaling is working fine.

Thanks for your answer.

But I don’t know why in my another project it is not working.

Thanks

Hi Max - Curious Question !

I have “this->setScale(1.0f)” which is it’s usual default scale, and tell a object move 1 per update frame.

Then I set scale to 2, and tell move 1 per update frame !

Will the distance it covers per frame increase now ?

Like when we play strategy games and we zoom in and out, we still require objects to move a certain amount across the map per frame. This is what i am wanting to achieve

Thanks

It depends what you mean by ‘tell a object to move 1 per update frame’ really - but in principal if you scale a parent then all you are scaling is the appearance - so you can leave your code without worrying about the scaling of parents.