Hy, I made a game and I have some problems: when my resources are loading (images *.png) it’s taking too long then usual because in my console appeared new lines and I don’t know what’s mean:
RX=32K,RF=107.2K,FF=139.7M,OF=560.8K,OS=54.5M,ON=128.1K,OR=0,FR=10K,TR=6.1M,RR=0,IS=13.8K
RA=48.5M,RS=44.7M,RN=61K
TA=11.8M,TS=9M,TN=31.5K
PA=832K,PS=832K,PN=6.2K
R0=207M,1=800.2K,2=24K,3=82.3K,4=2.1M,7=210.7K,8=3K,9=46.5M,10=19.8K,11=42.3K,12=303.2K,13=85.4K,15=338.7K,20=3.9K,21=524,22=61.2K,23=87.3K,24=16.5K
VM:-RR
and the code above it’s repeating several times.
Does anybody know what it’s mean. I mention that I loading, resizing, and drawing a lot of pictures (like 100) to anime some animals and shot them. And sometimes my screen is freezing because of this:
JPGENC 78 ms
JPGENC 7 ms
JPGENC 0 ms
JPGENC 70 ms
JPGENC 0 ms
JPGENC 0 ms
JPGENC 70 ms
JPGENC 0 ms
JPGENC 7 ms
JPGENC 54 ms
JPGENC 7 ms
JPGENC 0 ms
I used this method to resize:
public static Bitmap resize(Bitmap png, float scaleX, float scaleY){
Bitmap testBitmap = new Bitmap((int)(png.getWidth()*scaleX), (int)(png.getHeight()*scaleY));
int[] argb = new int[testBitmap.getWidth() * testBitmap.getHeight()];
testBitmap.getARGB(argb, 0, testBitmap.getWidth(), 0, 0, testBitmap.getWidth(), testBitmap.getHeight());
for (int index = 0; index < argb.length; index++) {
argb[index] = 0x00000000;
}
testBitmap.setARGB(argb, 0, (int)(png.getWidth()*scaleX), 0, 0,(int)(png.getWidth()*scaleX), (int)(png.getHeight()*scaleY));
png.scaleInto(testBitmap, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FIT);
return testBitmap;
}
and this to drawing:
Graphics graphics;
graphics.drawBitmap(int x,int y,int width,int height,Bitmap bitmap,int left,int top);
So, if anyone understood what I said, please help me. Thanks a lot
I suspect your screen is freezing, because you are doing too many heavy lifting on the UI thread.
If you need to start a game, then it would be better to create (read, resize) all images before the game starts. You should try to avoid loading/resizing during the gameplay. For this you could create some game-initializing task that runs on a background thread under a popup saying smth like “Please wait, initializing…”. So the user is blocked with the popup and just sits and waits when you load/resize all your images. Then you hide the popup and actually start the gameplay.
Another point is how you resize. There is a more efficient way to resize an image – it is possible to resize an image without the need to create a Bitmap object (which is large and slow in processing). Use
EncodedImageinstead. The BB API allows to load an image resource asEncodedImage. ThenEncodedImageprovides the API to resize itself. And finallyGraphicshas the API to draw anEncodedImageon itself.I hope my answer is helpful. Thanks.