楼主,这个在eoe 上面有个拼图软件的源码。我进去过现在没找到楼主你可以去找找,也是把一张图片切成很多张小的然后开始拼图

解决方案 »

  1.   


    我找了那个资源,可是bitmap却没有像ImageView.duration()的函数,不知道怎么设置每副分动画的显示时间
      

  2.   

    这是android拼图游戏的部分代码
    package org.loon.game.simple.test; 
    import java.awt.Graphics; 
    import java.awt.Graphics2D; 
    import java.awt.Image; 
    import java.awt.event.KeyEvent; 
    import java.awt.event.MouseEvent; 
    import org.loon.framework.game.simple.GameScene; 
    import org.loon.framework.game.simple.core.Deploy; 
    import org.loon.framework.game.simple.core.Screen; 
    import org.loon.framework.game.simple.utils.GraphicsUtils; public class ScreenTest1 extends Screen {
     private Image imageBack, tmp_imageBack, imageForward;
     private Graphics tmp_graphics; private int blocks[]; 
     private boolean isEvent;
     private int count, rs, cs, row, col, width, height; 
     public ScreenTest1(String file1, String file2, int row, int col) { 
      this.col = col;
      this.row = row; 
      this.imageBack = GraphicsUtils.loadImage(file1); 
      this.width = imageBack.getWidth(null);
      this.height = imageBack.getHeight(null);
      this.rs = width / row; 
      this.cs = height / col; 
      this.tmp_imageBack = GraphicsUtils .createImage(width, height + cs, true); 
      this.tmp_graphics = tmp_imageBack.getGraphics(); 
      this.count = col * row; 
      this.blocks = new int[count];
      this.imageForward = GraphicsUtils.loadImage(file2); 
      for (int i = 0; i < count; i++) { 
      blocks[i] = i; 
      } 
      rndBlocks(); 
      } 
     
      private void copy(int x1, int y1, int x2, int y2) { 
      tmp_graphics.copyArea(x1 * rs, y1 * cs, rs, cs, (x2 - x1) * rs, (y2 - y1) * cs); } 

       private void rndBlocks() { 
        tmp_graphics.drawImage(imageBack, 0, 0, null); 
        for (int i = 0; i < (count * row); i++) { 
        int x1 = (int) ((double) row * Math.random()); 
        int y1 = (int) ((double) col * Math.random()); 
        int x2 = (int) ((double) row * Math.random()); 
        int y2 = (int) ((double) col * Math.random()); 
        copy(x1, y1, 0, col); 
        copy(x2, y2, x1, y1); 
        copy(0, col, x2, y2); 
        int j1 = blocks[y1 * row + x1]; 
        blocks[y1 * row + x1] = blocks[y2 * row + x2]; 
        blocks[y2 * row + x2] = j1; } } 
       
        public void leftClick(MouseEvent e) { 
        if (isEvent) { return; } 
        int x = e.getX() / rs; 
        int y = e.getY() / cs; 
        copy(0, 0, 0, col); 
        copy(x, y, 0, 0); 
        copy(0, col, x, y); 
        int no = blocks[0]; 
        blocks[0] = blocks[y * row + x]; 
        blocks[y * row + x] = no; 
        int index; 
        for (index = 0; index < count; index++) { 
        if (blocks[index] != index) { break; } 
        } if (index == count) { 
        isEvent = true; 
        } return; 
        } 
        public void draw(Graphics2D g) { 
        if (!isEvent) { 
        g.drawImage(tmp_imageBack, 0, 0, null); 
        for (int i = 0; i < row; i++) { 
        for (int j = 0; j < col; j++) 
        g.drawRect(i * rs, j * cs, rs, cs); 
        } 
        } 
        if (isEvent && imageForward != null) { 
        g.drawImage(imageBack, 0, 0, null); 
        g.drawImage(imageForward, 0, 0, null); 
        tmp_graphics.dispose(); 
        } 
        } 
        public boolean isEvent() {
        return isEvent; 
        } 
        public void setEvent(boolean isEvent) { 
        this.isEvent = isEvent; 
        } 
        public void middleClick(MouseEvent e) { } 
        public void onKey(KeyEvent e) { } 
        public void onKeyUp(KeyEvent e) { } 
        public void rightClick(MouseEvent e) { } 
        public static void main(String[] args) { 
        GameScene frame = new GameScene("??", 320, 480); 
        Deploy deploy = frame.getDeploy(); 
        deploy.setScreen(new ScreenTest1("images/backimage1.jpg", "images/over.png", 4, 4)); 
        deploy.setShowFPS(true); 
        deploy.setLogo(false); 
        deploy.setFPS(100); 
        deploy.mainLoop(); 
        frame.showFrame(); 
        } 
       }