how to obtain a CCSprite's width and height in cocos2d for iphone

前端 未结 5 1097
离开以前
离开以前 2021-02-02 09:04

That\'s the question xD

Given an instance of a CCSprite in cocos2d in iphone, what method can I use to obtain the image width and height?

5条回答
  •  北海茫月
    2021-02-02 09:32

    In cocos2d-x v3.x, boundingBox is deprecated in the Node class (i.e. the super class of Sprite). Use the following code instead:

    auto spriteWidth = sprite->getTextureRect().size.width;
    auto spriteHeight = sprite->getTextureRect().size.height;
    

    or

    auto spriteWidth = sprite->getContentSize().width;
    auto spriteHeight = sprite->getContentSize().height;
    

提交回复
热议问题