This discussion is archived
7 Replies Latest reply: Aug 6, 2010 2:22 AM by 843853 RSS

Exchanged J2ME game3D

843853 Newbie
Currently Being Moderated
Hi, lucky day, I leaning about programming game 3D with J2ME, by load file m3g (export by blender). I look JRS and API Graphics3D, but when I try write code of example and build then don't run. I don't understand, too. I think I don't understand algorithms of it. Hope will be exchanged with others.
  • 1. Re: Exchanged J2ME game3D
    843853 Newbie
    Currently Being Moderated
    Ngoc_miao wrote:
    Hi, lucky day,
    Doesn't sound like it.
    I leaning about programming game 3D with J2ME, by load file m3g (export by blender). I look JRS and API Graphics3D, but when I try write code of example and build then don't run.
    ".. then don't run." What does this mean to you? It means nothing to me. It could mean anything from I put a pair of Adidas on my computer and it still doesn't follow me down the track to my machine spontaniously broke into flames when ever I try to run my code--which by the way would be really kewl, I'd be sitting there saying: "Do it again, do it again!"
    I don't understand, too. I think I don't understand algorithms of it.
    Then you need to be more expressive in what it is that you do not understand: I don't quite understand the algorith to make electricity jump out into space in the form of a radio wave, but I can use it and make it work--I don't have any idea why it does, but I have the basic "howtos" down enough to get my antennas to resonate and pump out those electrons.
    Hope will be exchanged with others.
    You know I've been sitting here with these sheep entrails for the last half hour and my crystal ball has not cleared up much, so I guess we're going to have to try perosnal communication before anyone can tell you much of anything: like what error messages do you get and etc.
  • 2. Re: Exchanged J2ME game3D
    843853 Newbie
    Currently Being Moderated
    Thank you!
    I know my English is awful (bad), I will try, this is the first for me in the forum of international. You looking my code:
    package Skywar.m3g;

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.lang.Object;
    import javax.microedition.m3g.*;
    import java.util.Timer;
    import java.util.TimerTask;
    import javax.microedition.lcdui.game.*;

    /**
    * @author BDPL
    */
    public class SkywarCanvas extends Canvas implements Runnable {
    private static final String sk = "/sk.m3g";
    // public static final int mb_ID = 2;
    public SkywarCanvas mCanvas;
    public Camera mCamera;
    public World mWorld;
    public Graphics3D g3d;
    public Group root;
    public boolean isRunning = true; //truy van canvas
    //private TimerTask mRefreshTask = null;
    //private Timer mRefreshTimer = new Timer();//thoi gian lam tuoi
    private static final float g3dx = 15.f;//toa do truc x cua doi tuong tren man hinh 2D
    private static final float g3dy = 0.25f;//toa do truc y cua doi tuong tren man hinh 2D
    //private AnimationController animSky = null;
    private int oldg3dX = 1; //toa do cu theo truc X
    private int oldg3dY = 1; //toa do cu theo truc Y
    private int width = getWidth();//chieu cao cua canvas
    private int height = getHeight();//chieu rong cua canvas
    //private boolean isplay;//kiem tra vong lap sprite
    //private long delay;
    // private int sprx, spry;//toa do hien tai cua sprite


    //bat dau canva

    public void showNotify(int sleeptime){
    init();
    //tao ra mot luong chay game
    Thread thr = new Thread();
    isRunning = true;
    thr.start();
    }
    //dung canvas
    public void hideNotify(){
    isRunning = false;
    }
    //khoi tao doi tuong vaf load doi tuong
    protected void init(){
    g3d = Graphics3D.getInstance();
    try{
    Object3D[] object = Loader.load("/sk.m3g");
    mWorld = (World) object[0];
    Camera mC = mWorld.getActiveCamera();
    float aspect = (float) getWidth()/(float) getHeight();
    mC.setPerspective(60.f, aspect, 1.0f, 1000.0f);
    } catch (Exception e){
    e.printStackTrace();
    }
    }
    /* public void getObject(){
    root = (Group)mWorld.find(mb_ID);
    //bao gom cac hoat canh va mot so doi tuong khac ve thoi gian
    }*/
    public void run(){
    while (isRunning){
    if ((mWorld != null)&& (g3d != null)){
    int sleep = (int)System.currentTimeMillis();
    showNotify(sleep);
    }
    //co the goi boi canh ra roi moi den doi tuong
    repaint();
    }
    try {
    Thread.sleep(1000);
    } catch (Exception e){}
    }

    protected void paint(Graphics g){
    //cat 1 hinh chu nhat de hien thi
    if ((g.getClipWidth() != width) || (g.getClipHeight() != height) ||
    (g.getClipX() != oldg3dX) || (g.getClipY() != oldg3dY)) {
    g.setColor(0x00);
    g.fillRect(0, 0, mCanvas.getWidth(), mCanvas.getHeight());
    }

    // render the 3D scene
    if ((g3d != null) && (mWorld != null)) {
    g3d.bindTarget(g);
    g3d.setViewport(oldg3dX, oldg3dY, width, height);
    g3d.render(mWorld);
    g3d.releaseTarget();
    }
    }
    public Displayable getD() {
    return(this);
    }
    //thu tuc dieu khien doi tuong
    public void keyPressd(int keyCode){
    int gameAction = getGameAction(keyCode);
    if(gameAction == Canvas.FIRE){
    Transform transform = new Transform();
    mCamera.getCompositeTransform(transform);
    float[] direction = {0.0f, 0.0f, g3dy, 0.0f};
    transform.transform(direction);
    mWorld.translate(direction[0], direction[1], direction[2]);
    } else {
    switch(gameAction){
    case Canvas.LEFT:
    mCamera.postRotate(g3dx, 0.0f, 1.0f, 0.0f);
    break;
    case Canvas.RIGHT:
    mCamera.postRotate(g3dx, 0.0f, -1.0f, 0.0f);
    break;
    case Canvas.UP:
    mCamera.postRotate(g3dx, 1.0f, 0.0f, 0.0f);
    break;
    case Canvas.DOWN:
    mCamera.postRotate(g3dx, -1.0f, 0.0f, 0.0f);
    break;
    default:
    break;
    }
    }
    repaint();
    }
    public SkywarCanvas(){
    //
    }
    /*
    * duoc su dung nham lam tuoi che do cho canvas moi khi chay
    private class RefreshTask extends TimerTask{
    public void run(){
    mCanvas.repaint();
    }
    }
    /* public String name() {
    return("Binary World");
    }*/
    }

    package Skywar.m3g;

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.game.*;
    import javax.microedition.lcdui.*;
    import java.lang.Object;
    import javax.microedition.m3g.*;
    import javax.microedition.io.file.*;
    import javax.microedition.io.*;
    import javax.microedition.midlet.MIDletStateChangeException;
    import javax.microedition.m3g.*;
    import javax.microedition.m3g.Object3D;
    import java.util.*;
    /**
    * @author BDPL
    */
    public class SkyMain extends MIDlet implements CommandListener{
    private Command mExit = new Command("Exit", Command.EXIT, 1);
    private Command mGo = new Command("Go", Command.SCREEN, 1);
    private Command mPause = new Command("Pause", Command.SCREEN, 2);
    private SkywarCanvas mCanvas;
    private SkyMain mSky;
    private Display mDisplay;
    private boolean gameOver = false;

    private Graphics3D g3d;
    private World mWorld;
    public SkyMain(){
    super();
    mDisplay = Display.getDisplay(this);
    }

    public void startApp() throws MIDletStateChangeException {
    mDisplay.setCurrent(mCanvas);
    mCanvas.addCommand(mExit);
    mCanvas.addCommand(mGo);
    mCanvas.addCommand(mPause);
    mCanvas.setCommandListener(this);
    mCanvas.repaint();
    }
    public void pauseApp() {
    mWorld = null;
    }

    public void destroyApp(boolean unconditional) {
    }
    public void commandAction(Command c, Displayable s){
    if(c == mExit){
    try{
    destroyApp(false);
    notifyDestroyed();
    }catch (Exception e){
    e.printStackTrace();
    }
    }
    }
    //an go
    private void setGoCommand() {
    mCanvas.removeCommand(mPause);
    mCanvas.addCommand(mGo);
    }

    //an pause
    private void setPauseCommand() {
    mCanvas.removeCommand(mGo);
    mCanvas.addCommand(mPause);
    }
    }

    Reality, when I build, error code " can not found MIDletM3G". I thing I write algorithms is wrong.
  • 3. Re: Exchanged J2ME game3D
    843853 Newbie
    Currently Being Moderated
    You didn't use code tags, as such, the forum software has interpreted some of your program as formatting codes for the display. I didn't respond to your code post so you can insert code tags.

    You'll need to use code tags before most of the forum patrons will look at your code.
  • 4. Re: Exchanged J2ME game3D
    843853 Newbie
    Currently Being Moderated
    Hi. Just paste your code between two { code } tags (delete the two espacements between the curly brackets). Or click on the button code, in plain text mode of the text editor for publishing a response, and paste your code beetween the 2 { code } tags premade.

    Then you should receive a response by a professional. ?
    I am very interested in your way exporting Blender Game Engine (BGE) into Java. I will make my researches on it.

    Thanks, good luck. Here is a template I made with YOUR code. I guess it's what expected. But I am surprised, if it is the right solution, how some people can not understand copy/paste functionality in their IDE or here with code tags. I do not understand how people can help sometimes. Well... I understand myself. Be aware that here is very different from Blender community. Well I hope there are exceptions.

    Sincerely
    package Skywar.m3g;
    
    import javax.microedition.midlet.;
    import javax.microedition.lcdui.;
    import java.lang.Object;
    import javax.microedition.m3g.;
    import java.util.Timer;
    import java.util.TimerTask;
    import javax.microedition.lcdui.game.;
    
    /
    @author BDPL
    /
    public class SkywarCanvas extends Canvas implements Runnable {
    private static final String sk = "/sk.m3g";
    // public static final int mb_ID = 2;
    public SkywarCanvas mCanvas;
    public Camera mCamera;
    public World mWorld;
    public Graphics3D g3d;
    public Group root;
    public boolean isRunning = true; //truy van canvas
    //private TimerTask mRefreshTask = null;
    //private Timer mRefreshTimer = new Timer();//thoi gian lam tuoi
    private static final float g3dx = 15.f;//toa do truc x cua doi tuong tren man hinh 2D
    private static final float g3dy = 0.25f;//toa do truc y cua doi tuong tren man hinh 2D
    //private AnimationController animSky = null;
    private int oldg3dX = 1; //toa do cu theo truc X
    private int oldg3dY = 1; //toa do cu theo truc Y
    private int width = getWidth();//chieu cao cua canvas
    private int height = getHeight();//chieu rong cua canvas
    //private boolean isplay;//kiem tra vong lap sprite
    //private long delay;
    // private int sprx, spry;//toa do hien tai cua sprite
    
    
    //bat dau canva
    
    public void showNotify(int sleeptime){
    init();
    //tao ra mot luong chay game
    Thread thr = new Thread();
    isRunning = true;
    thr.start();
    }
    //dung canvas
    public void hideNotify(){
    isRunning = false;
    }
    //khoi tao doi tuong vaf load doi tuong
    protected void init(){
    g3d = Graphics3D.getInstance();
    try{
    Object3D[] object = Loader.load("/sk.m3g");
    mWorld = (World) object[0];
    Camera mC = mWorld.getActiveCamera();
    float aspect = (float) getWidth()/(float) getHeight();
    mC.setPerspective(60.f, aspect, 1.0f, 1000.0f);
    } catch (Exception e){
    e.printStackTrace();
    }
    }
    / public void getObject(){
    root = (Group)mWorld.find(mb_ID);
    //bao gom cac hoat canh va mot so doi tuong khac ve thoi gian
    }/
    public void run(){
    while (isRunning){
    if ((mWorld != null)&& (g3d != null)){
    int sleep = (int)System.currentTimeMillis();
    showNotify(sleep);
    }
    //co the goi boi canh ra roi moi den doi tuong
    repaint();
    }
    try {
    Thread.sleep(1000);
    } catch (Exception e){}
    }
    
    protected void paint(Graphics g){
    //cat 1 hinh chu nhat de hien thi
    if ((g.getClipWidth() != width) || (g.getClipHeight() != height) ||
    (g.getClipX() != oldg3dX) || (g.getClipY() != oldg3dY)) {
    g.setColor(0x00);
    g.fillRect(0, 0, mCanvas.getWidth(), mCanvas.getHeight());
    }
    
    // render the 3D scene
    if ((g3d != null) && (mWorld != null)) {
    g3d.bindTarget(g);
    g3d.setViewport(oldg3dX, oldg3dY, width, height);
    g3d.render(mWorld);
    g3d.releaseTarget();
    }
    }
    public Displayable getD() {
    return(this);
    }
    //thu tuc dieu khien doi tuong
    public void keyPressd(int keyCode){
    int gameAction = getGameAction(keyCode);
    if(gameAction == Canvas.FIRE){
    Transform transform = new Transform();
    mCamera.getCompositeTransform(transform);
    float[] direction = {0.0f, 0.0f, g3dy, 0.0f};
    transform.transform(direction);
    mWorld.translate(direction[0], direction[1], direction[2]);
    } else {
    switch(gameAction){
    case Canvas.LEFT:
    mCamera.postRotate(g3dx, 0.0f, 1.0f, 0.0f);
    break;
    case Canvas.RIGHT:
    mCamera.postRotate(g3dx, 0.0f, -1.0f, 0.0f);
    break;
    case Canvas.UP:
    mCamera.postRotate(g3dx, 1.0f, 0.0f, 0.0f);
    break;
    case Canvas.DOWN:
    mCamera.postRotate(g3dx, -1.0f, 0.0f, 0.0f);
    break;
    default:
    break;
    }
    }
    repaint();
    }
    public SkywarCanvas(){
    //
    }
    /
    duoc su dung nham lam tuoi che do cho canvas moi khi chay
    private class RefreshTask extends TimerTask{
    public void run(){
    mCanvas.repaint();
    }
    }
    / public String name() {
    return("Binary World");
    }/
    }
    
    package Skywar.m3g;
    
    import javax.microedition.midlet.;
    import javax.microedition.lcdui.game.;
    import javax.microedition.lcdui.;
    import java.lang.Object;
    import javax.microedition.m3g.;
    import javax.microedition.io.file.;
    import javax.microedition.io.;
    import javax.microedition.midlet.MIDletStateChangeException;
    import javax.microedition.m3g.;
    import javax.microedition.m3g.Object3D;
    import java.util.;
    /
    @author BDPL
    /
    public class SkyMain extends MIDlet implements CommandListener{
    private Command mExit = new Command("Exit", Command.EXIT, 1);
    private Command mGo = new Command("Go", Command.SCREEN, 1);
    private Command mPause = new Command("Pause", Command.SCREEN, 2);
    private SkywarCanvas mCanvas;
    private SkyMain mSky;
    private Display mDisplay;
    private boolean gameOver = false;
    
    private Graphics3D g3d;
    private World mWorld;
    public SkyMain(){
    super();
    mDisplay = Display.getDisplay(this);
    }
    
    public void startApp() throws MIDletStateChangeException {
    mDisplay.setCurrent(mCanvas);
    mCanvas.addCommand(mExit);
    mCanvas.addCommand(mGo);
    mCanvas.addCommand(mPause);
    mCanvas.setCommandListener(this);
    mCanvas.repaint();
    }
    public void pauseApp() {
    mWorld = null;
    }
    
    public void destroyApp(boolean unconditional) {
    }
    public void commandAction(Command c, Displayable s){
    if(c == mExit){
    try{
    destroyApp(false);
    notifyDestroyed();
    }catch (Exception e){
    e.printStackTrace();
    }
    }
    }
    //an go
    private void setGoCommand() {
    mCanvas.removeCommand(mPause);
    mCanvas.addCommand(mGo);
    }
    
    //an pause
    private void setPauseCommand() {
    mCanvas.removeCommand(mGo);
    mCanvas.addCommand(mPause);
    }
    }
  • 5. Re: Exchanged J2ME game3D
    794069 Newbie
    Currently Being Moderated
    elfesiilvain wrote:
    Here is a template I made with YOUR code
    There isn't much point just taking his unformatted code and pasting it directly into code tags. The problem is that the forum software interprets lots of the characters as markup and either strips them out, or formats the following text.

    Also, the code tags don't magically indent the code, so it's only slightingly more legible. The best solution is for the OP to get the code from his/her IDE and paste it between the code tags.
  • 6. Re: Exchanged J2ME game3D
    843853 Newbie
    Currently Being Moderated
    It's okay I'm waiting for him and his response.
    Sylvain
  • 7. Re: Exchanged J2ME game3D
    843853 Newbie
    Currently Being Moderated
    Who that have experiences work with sprite 3d? please, help me, I need build a sprite and appear on the screen with image grow up, but I don't know how do it, and frames needs how create, when working with sprite2D, I don't processed frames, and it not present on the screen.