Search code examples
androidsizespritecocos2d-android

Cocos2d-Android - What is the difference between Sprite.getcontentsize , Sprite.getscale , Sprite.gettexture


The Title says it all. I want to know what is the difference between Sprite.getcontentsize, Sprite.gettexture , Sprite.getscale. and How are they used. I couldn't find any resources following this question.


Solution

  • We have for example image with name "test.png" with width 100px and height 200px. Then:

    CCSprite testImage = CCSprite.sprite("test.png");
    
    // print original image size
    System.out.println("" + testImage.getContentSize().width + ", " + testImage.getContentSize().height); // print: 100, 200
    
    // print actual image size
    System.out.println("" + testImage.getBoundingBox().size.width + ", " + testImage.getBoundingBox().size.height); // print: 100, 200
    
    // this will change resolution of image to half, so it will be drawn 2x smaller then original size
    testImage.setScale(0.5f); 
    
    // print how many is image scaled
    System.out.println("" + testImage.getScale()); // print: O.5
    
    // print original image size
    System.out.println("" + testImage.getContentSize().width + ", " + testImage.getContentSize().height); // print: 100, 200
    // print actual image size
    System.out.println("" + testImage.getBoundingBox().size.width + ", " + testImage.getBoundingBox().size.height); // print: 50, 100
    

    testImage.gettexture()will probably return loaded texture/image, but I don't know, I have never needed to use this function.