MacdroidNilesh / cocos2d-android-1

Automatically exported from code.google.com/p/cocos2d-android-1
0 stars 0 forks source link

texture size #108

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
i set a background sprite ,
background = CCSprite.sprite("game_bg.png");
    background.setScaleX(size.width/background.getTexture().getWidth(   background.setScaleY(size.height/background.getTexture().getHeight());

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

then  i load a bitmap from internet.
CCTexture2D texNew = new CCTexture2D();
texNew.initWithImage(bitmap, CGSize.make(size.width, 
size.height),CGSize.make(size.width/2,size.height/2)); //set the texture with 
the bitmap

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

The Problem :  i see the background full with the bitmap ,but the bitmap is 
scaled and showed partial.so how could i set the texture size correctly (by 
using the bitmap)  so that i can set the texture to the sprite of background 
properly?  

Original issue reported on code.google.com by yeshengw...@gmail.com on 1 Dec 2011 at 10:04

GoogleCodeExporter commented 8 years ago
how could i set the texture size correctly (by using the bitmap)  so that i can 
set the texture to the sprite of background properly?  that is to say that i 
can see the bitmap as a original or that is not out of shape. 

use bitmap  to fill a texture ,then use the texture to fill the sprite of the 
background.Anyone have the good method? please help.

Original comment by yeshengw...@gmail.com on 1 Dec 2011 at 10:10

GoogleCodeExporter commented 8 years ago
Hello,

We have the same problem, and we have solved it using the bitmap options. This 
Our code. 

Options opts = new Options();
opts.inDensity = context.getResources().getDisplayMetrics().densityDpi;
Bitmap bm = BitmapFactory.decodeResource(context.getResources(), identifier, 
opts);

I hope that help you :).

Original comment by alvaro...@gmail.com on 28 May 2012 at 7:39