| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 465 人关注过本帖
标题:手机小游戏,地图可以显示,但是精灵无法显示,请大家帮忙改一下吧,
只看楼主 加入收藏
落叶深蓝色
Rank: 8Rank: 8
来 自:山东
等 级:蝙蝠侠
帖 子:319
专家分:807
注 册:2010-12-8
结帖率:100%
收藏
 问题点数:0 回复次数:1 
手机小游戏,地图可以显示,但是精灵无法显示,请大家帮忙改一下吧,
程序代码:
import javax.microedition.import javax.microedition.import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class GameTest extends MIDlet implements CommandListener{
    Display dis;
    GameTestDome gtd;
    Command cmdOK,cmdPAU,cmdExit;
    public GameTest() {
        // TODO Auto-generated constructor stub
        cmdOK=new Command("开始",Command.SCREEN,1);
        cmdPAU=new Command("暂停",Command.SCREEN,1);
        cmdExit=new Command("退出",Command.EXIT,1);
    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
        // TODO Auto-generated method stub

    }

    protected void pauseApp() {
        // TODO Auto-generated method stub

    }

    protected void startApp() throws MIDletStateChangeException {
        // TODO Auto-generated method stub
        dis=Display.getDisplay(this);
        gtd=new GameTestDome();
        gtd.addCommand(cmdOK);
        gtd.addCommand(cmdExit);
        gtd.setCommandListener(this);
        dis.setCurrent(gtd);

    }

    public void commandAction(Command cmd, Displayable displayable) {
        // TODO Auto-generated method stub
        if(cmd==cmdOK){
            gtd.removeCommand(cmdOK);
            gtd.addCommand(cmdPAU);
            gtd.th=new Thread(gtd);
            gtd.th.start();
            gtd.RUN=true;
           
        }
        if(cmd==cmdPAU){
            gtd.removeCommand(cmdPAU);
            gtd.addCommand(cmdOK);
            gtd.RUN=false;
            gtd.th=null;
        }
        if(cmd==cmdExit){
            try {
                destroyApp(false);
                notifyDestroyed();
            } catch (MIDletStateChangeException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
           
        }
       
    }

}import import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.lcdui.game.TiledLayer;

class GameTestDome extends GameCanvas implements Runnable{
    boolean RUN=true;
    Thread th;
    Graphics gra;
    Sprite sp1,sp2;
    Image img1,img2,img3;
    boolean TE;
    TiledLayer Road,Wall;
    int position[][];
    int y=10;
    protected GameTestDome() {
        super(false);
        // TODO Auto-generated constructor stub
        try {
            img1=Image.createImage("/Person2.png");
            img2=Image.createImage("/map.png");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //sp1=new Sprite(img1);
        //sp1.setPosition(this.getWidth(), this.getHeight());
        sp1=new Sprite(img1,img1.getWidth()/10,img1.getHeight()/7);
        sp1.setPosition(this.getWidth(), this.getHeight());
        sp1.defineReferencePixel(sp1.getWidth()/2, sp1.getHeight()/2);
        Wall=new TiledLayer(8,8,img2,img2.getWidth()/2,img2.getHeight());
        Road=new TiledLayer(8,8,img2,img2.getWidth()/2,img2.getHeight());
        position=new int[][]{
                {1,2,1,2,1,2,1,2},
                {1,1,1,1,1,2,1,2},
                {1,2,1,2,1,2,1,2},
                {2,2,2,2,1,2,1,2},
                {1,2,2,2,1,2,1,2},
                {2,2,2,2,1,2,1,2},
                {1,2,1,2,1,2,1,2},
                {1,2,1,2,1,2,1,2}
        };
        for(int i=0;i<8;i++){
            for(int j=0;j<8;j++){
                if(position[i][j]==1)Road.setCell(j, i, position[i][j]);
                else Wall.setCell(j, i, position[i][j]);
            }
        }
        gra=this.getGraphics();
        th=new Thread(this);
        th.start();
    }

    public void run() {
        // TODO Auto-generated method stub
        while(RUN){
            gra.setColor(255, 255, 255);
            gra.fillRect(0, 0, this.getWidth(), this.getHeight());
            String str="top"+y;
            if(sp1.collidesWith(Wall, true)){
                TE=false;
                y--;
                gra.drawString(str, 0, 0, Graphics.TOP|Graphics.LEFT);
                }
            sp1.nextFrame();
            int state=this.getKeyStates();
            switch(state){
                case GameCanvas.LEFT_PRESSED: sp1.move(-5, 0);break;
                case GameCanvas.RIGHT_PRESSED:sp1.move(5, 0); break;
                case GameCanvas.UP_PRESSED:   sp1.move(0, -5);break;
                case GameCanvas.DOWN_PRESSED: sp1.move(0, 5); break;
            }
            sp1.paint(gra);
            Road.paint(gra);
            Wall.paint(gra);
            this.flushGraphics();
            try {
                Thread.currentThread().sleep(100);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
       
    }

}

搜索更多相关主题的帖子: 手机小游戏 地图 
2012-05-10 12:02
Sunpeng_Bccn
Rank: 2
等 级:论坛游民
威 望:2
帖 子:19
专家分:34
注 册:2012-8-4
收藏
得分:0 
你把那个sp1.paint(gra);放到Wall.paint(gra);后面看下,是不是被Wall覆盖了!
2012-08-04 21:15
快速回复:手机小游戏,地图可以显示,但是精灵无法显示,请大家帮忙改一下吧,
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021576 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved