Nhyn / loon-simple

Automatically exported from code.google.com/p/loon-simple
0 stars 0 forks source link

图片质量下降很厉害 #16

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?

Please provide any additional information below.

Original issue reported on code.google.com by zhangyan...@gmail.com on 8 Oct 2010 at 2:19

GoogleCodeExporter commented 9 years ago
不好意思,上面没写就提交了。

Original comment by zhangyan...@gmail.com on 8 Oct 2010 at 2:46

Attachments:

GoogleCodeExporter commented 9 years ago
package cn.zyj.Pintu;

import org.loon.framework.android.game.core.graphics.LColor;
import org.loon.framework.android.game.core.graphics.LImage;
import org.loon.framework.android.game.core.graphics.Screen;
import org.loon.framework.android.game.core.graphics.device.LGraphics;

import android.view.KeyEvent;
import android.view.MotionEvent;

public class GameScreen extends Screen  {

    private static final int STATE_RUNNING  = 1;
    private static final int STATE_FINISH   = 2;
    private static final int STATE_SHOWPIC  = 3;

    private int blocks[];
    LImage backImg, temImg, koImage;
    private LGraphics tmp_graphics;
    private int count, rs, cs, row, col, width, height;
    int state;

    public GameScreen (String file1, String file2, int row, int col){
        backImg = LImage.createImage("cn/zyj/Pintu/Image/backimage1.jpg");
        koImage = LImage.createImage("cn/zyj/Pintu/Image/over.png");
        this.width = backImg.getWidth(); 
        this.height = backImg.getHeight();
        temImg  = LImage.createImage(width, height);        
        tmp_graphics = temImg.getLGraphics();

        this.state = STATE_RUNNING;
        this.col = col;
        this.row = row;
        this.rs = width / row;
        this.cs = height / col;
        this.count = col * row;
        this.blocks = new int[count];
        initBlocks();
    }

    private void initBlocks() {
        for (int i = 0; i < count; i++) {
            blocks[i] = i;
        }

        int tem,r1,r2;
        for(int i = 0; i < 100; i++){
            r1 = (int)(count*Math.random());
            r2 = (int)(count*Math.random());

            tem = blocks[r1];
            blocks[r1] = blocks[r2];
            blocks[r2] = tem;
        }
    }

    @Override
    public void draw(LGraphics g) {
        // TODO Auto-generated method stub
        int ci,sx,sy,dx,dy;
        if(state == STATE_RUNNING){
            for(int i = 0; i < count; i++){
                ci = blocks[i];
                sx = blocks[i] % row * rs;
                sy = blocks[i] / row * cs;
                dx = i % row * rs;
                dy = i / row * cs;
                tmp_graphics.drawImage(backImg.getSubImage(sx, sy, rs, cs), dx, dy);
            }
            g.drawImage(temImg, 0, 0);
        }
        if(state == STATE_FINISH){
            g.drawImage(backImg, 0, 0);
            g.drawImage(koImage, 0, 0);
        }
        if(state == STATE_SHOWPIC){
            g.drawImage(backImg, 0, 0);
        }       
    }   

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent arg1) {
        // TODO Auto-generated method stub
        if(state == STATE_RUNNING){     
                state = STATE_SHOWPIC;
        }
        return true;
    }

    @Override
    public boolean onKeyUp(int arg0, KeyEvent arg1) {
        // TODO Auto-generated method stub
        if(state == STATE_SHOWPIC){
            state = STATE_RUNNING;
        }
        return true;
    }

    @Override
    public boolean onTouchDown(MotionEvent e) {
        // TODO Auto-generated method stub
        if(state == STATE_RUNNING){
            int tem,x,y;
            x = (int) (e.getX() / rs);
            y = (int) (e.getY() / cs);
            tem = blocks[0];
            blocks[0] = blocks[y*row+x];
            blocks[y*row+x] = tem;          
        }

        for(int i = 0; i < count; i++){
            if(blocks[i] != i){
                break;
            }
            if(i == count-1){
                state = STATE_FINISH;
            }
        }

        return true;
    }

    @Override
    public void onTouch(float arg0, float arg1, MotionEvent arg2, int arg3,
            int arg4) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onTouchMove(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onTouchUp(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return false;
    }

}

Original comment by zhangyan...@gmail.com on 8 Oct 2010 at 2:47

GoogleCodeExporter commented 9 years ago
zhangyangjing兄您好:

出于效率考虑,LImage默认的图片加载方式按照RGB565进行,这��
�一种仅仅适合低彩画面(比如蜡笔游戏或早期游戏机那样的1
6色游戏)的色彩模式。如果您想提高画质,可以使用LImage.cre
ateImage("",true)或GraphicsUtils.load8888Image方式加载图片,前者色彩
模式为ARGB4444,后者为ARGB8888,具体细节文档中有提及,总之�
��式越高显示速度越慢……

Original comment by loontest@gmail.com on 8 Oct 2010 at 3:35