Lynton
Lynton

Reputation: 287

How to set CCLayer size in Cocos2d-x?

I used setContentSize but it doesn't work. And I don't want to scale stuff in the layer so I won't use setScale.

What should I do?

Upvotes: 1

Views: 5001

Answers (3)

Dmitrii Cooler
Dmitrii Cooler

Reputation: 4132

Maybe?

auto layerInstance = LayerColor::create();
auto layerInstanceSize = layerInstance->getContentSize();
float layerInstanceSizeWidth = layerInstanceSize.width;
float layerInstanceSizeHeight = layerInstanceSize.height;

Upvotes: 0

Kazuki Sakamoto
Kazuki Sakamoto

Reputation: 14009

setContentSize should work as the following. How did you do that?

https://github.com/cocos2d/cocos2d-x/blob/master/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.cpp#L841

CCLayerGradient* layer1 = CCLayerGradient::create(ccc4(255, 0, 0, 255), ccc4(255, 0, 255, 255));
layer1->setContentSize(CCSizeMake(80, 80));

EDITED

So you mean you want to clip the image by the content size of the layer? Try to use CCClippingNode or this glScissor node example.

Upvotes: 2

Sumit Kandoi
Sumit Kandoi

Reputation: 427

   Try! this it works for me.


CCSize screenSize   = CCDirector::sharedDirector()->getVisibleSize();
    float x = screenSize.width;
    float y = screenSize.height;
    CCLayer* layer = new MyLayer();

    float layerX = layer->getContentSize().width;
    float layerY= layer->getContentSize().height;

    float scaleX   = x/layerX;
    float scaleY   = y/layerY;
    layer->setScaleX(scaleX*1.2f);
    layer->setScaleY(scaleY*1.2f);

Upvotes: 0

Related Questions