2

I have an image I'm trying to use as a background in Android. The image is tablet sized, but I'd like it to scale down when there is a smaller screen. I know the aspect ratio might be off. In any case, here is my code:

CGSize winSize = CCDirector.sharedDirector().displaySize();
    Log.v("MP", "Width: " + winSize.width + " Height: " + winSize.height);
    CCSprite backGround = CCSprite.sprite("background1.png");
    this.setIsTouchEnabled(true);
    //backGround.setContentSize(winSize);
    backGround.setScale(.5f);
    backGround.setPosition(CGPoint.ccp(winSize.width/2.0f,winSize.height/2.0f));
    addChild(backGround);

What is happening is my image is not being scaled down automatically. So you'll notice here i'm setting down the scale. .5 is an arbitrary value for testing. I've noticed that the graphic does scale down when I do that, but my image is cut off. It only shows the top left corner of the image.

Perhaps someone can help me with this problem and also give me some general advice on supporting multiple screen resolutions on Android with Cocos2D. I know how to handle this problem without using Cocos2D, but am still learning Cocos2D and am unsure of what to do.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
spentak
  • 4,627
  • 15
  • 62
  • 90

1 Answers1

4

that is a hard issue; we usually use this method:

background.setScaleX(winSize .width/background.getTexture().getWidth());

background.setScaleY(size.height/background.getTexture().getHeight());

background.setPosition(CGPoint.make(size.width/2, size.height/2));

addChild(backGround);
Jeetu
  • 686
  • 2
  • 10
  • 20
evan
  • 318
  • 3
  • 14