API Games C65 - SIEMENS

Galera,

alguém aqui já desenvolveu algum Game ou App utilizando a GameCanvas do C65??

Estou com um problema que não acontece no emulador da SUN, mas acontece no meu aparelho…(C65)

Valeu!

Que problema? Fica difícil alguém te ajudar se você não disser o que está acontecendo :wink:

É pq eu já postei minha dúvida tem um tempinho, e ninguém respondeu… :cry:

A questão é que a tela de um exemplo de Game que eu fiz não esta atualizando corretamente qnd eu verifico a tecla pressionada…

O tal problema não acontece no emuldar da Sun… Só no emulador do C65 e também no aparelho…

Ai vai o canvas para vcs analizarem(Lembrando que isso é só um TESTE)…:


/*
 * Created on 28/01/2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package br.com.renan;

import java.io.IOException;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.Layer;
import javax.microedition.lcdui.game.LayerManager;

/**
 * @author renanfurtado
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class CanvasJogo extends GameCanvas implements CommandListener, Runnable{
	private boolean executando = true;
	private boolean redesenha;
	private final LayerManager layerManager;
	private Cowboy cowboy;
	private Command voltarMenu;
	private Display tela;
	private Form apresentacao;
	private Moita moita;
	private Aviao aviao;
	private Fundo fundo;
	private Layer camada;
	private boolean auxVibre = false;
	private Thread canvas;
	
	/**
	 * @param apresentacao
	 * @param tela
	 * @param arg0
	 * @throws IOException
	 */
	protected CanvasJogo(Display tela, Form apresentacao) throws IOException {
		super(true);
		this.tela = tela;
		this.apresentacao = apresentacao;
		this.voltarMenu = new Command("Voltar",Command.BACK,0);
		this.fundo = new Fundo();
		this.cowboy = new Cowboy();
		this.moita = new Moita();
		this.aviao = new Aviao();
		this.layerManager = new LayerManager();
		this.layerManager.append(moita);
		this.layerManager.append(aviao);
		this.layerManager.append(cowboy);
		this.layerManager.append(fundo);
		this.addCommand(voltarMenu);
		this.setCommandListener(this);
		
		this.iniciar();
	}
	
	private final void movimenta() {
		int keyStates = this.getKeyStates();
		
		System.out.println("this.getKeyStates(): "+this.getKeyStates());
		System.out.println("LEFT_PRESSED: "+LEFT_PRESSED);
		

		
		if ((keyStates & LEFT_PRESSED) != 0) {
			cowboy.setDirecao('e');
			cowboy.mover(0,this);
			moveCenario(5);
			
		} else if ((keyStates & RIGHT_PRESSED) != 0) {
			cowboy.setDirecao('d');
			cowboy.mover(0,this);
			moveCenario(-5);
		} else if ((keyStates & UP_PRESSED) != 0) {
			if(verificaColisaoParede()){
				boolean pulando = true;
				cowboy.setDirecao('c');
				int timeSalto = 0;
				while(pulando){
					timeSalto++;
					cowboy.mover(1,this);
					if(timeSalto > 50){
						pulando = false;
						this.auxVibre = false;
					}
				}
				moveCenario(0);
			}
		} else if ((keyStates & DOWN_PRESSED) != 0) {
		}
		
	}
	
	public final void iniciar() {
		executando = true;
		canvas = new Thread(this);
		canvas.setPriority(Thread.MAX_PRIORITY);
		canvas.start();
	}
	
	public final void stop() {
		executando = false;
	}
	
	public void jogar(){
	}

	private final void renderiza(Graphics g) {
		if(redesenha){
			g.setClip(0,0,160,160);
			redesenha=false;
		}

		//Limpa a área do retangulo para a tela não ficar com sujeiras...
		g.fillRect(0, 0, 160, 160);
		//Renderiza o genciador de camadas(layerManager) na tela na coordenada indicada
		layerManager.paint(g, 0,0);
		this.flushGraphics();
	}
	
	
	private final boolean verificaColisaoParede() {
		if(!cowboy.collidesWith(fundo,false)){
			cowboy.setDirecao('b');
			cowboy.mover(7,this);
			return false;
		}
		else{
			return true;
		}
	}

	/* (non-Javadoc)
	 * @see javax.microedition.lcdui.CommandListener#commandAction(javax.microedition.lcdui.Command, javax.microedition.lcdui.Displayable)
	 */
	public void commandAction(Command c, Displayable arg1) {
		if(c == this.voltarMenu){
			executando = false;
			this.tela.setCurrent(apresentacao);
		}
		
		
		
	}

	/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
	public void run() {
		Graphics g = getGraphics();
		g.setColor(0xffffff);
		//g.drawString("Renan",0,0,0);
		redesenha = true;
		while(executando){
			moita.balanca();
			aviao.mover(5);
			movimenta();
			renderiza(g);
			if(verificaColisaoParede()){
				if(!auxVibre){
					tela.vibrate(250);
					this.auxVibre = true;
				}
			}
			long inicio = System.currentTimeMillis();
			long fim = System.currentTimeMillis();
			long tempo = fim - inicio;
			if (tempo<100){
				try {
					Thread.sleep(100-tempo);
				} catch (Exception ie) {}
			}			
		}
	}
	
	public void moveCenario(int i){
		//int refPixelX = cowboy.getRefPixelX();
		//int refPixelY = cowboy.getRefPixelY();
		
		fundo.move(i,0);
		moita.move(i,0);
		//if(true){
			
		//}
		
		
		
	}


}

Minha App está disponível em http://www.guj.com.br/posts/downloadAttach/45.java (JAR)
http://www.guj.com.br/posts/downloadAttach/46.java (JAD)

Testem em seus telefones e veja se ocorre o mesmo problma…

Valeu!

Não está atualizando corretamente quer dizer que a interface não está respondendo corretamente aos inputs do usuário? Vou tentar dar uma testada hoje de noite, se a minha memória não atrapalhar :roll:

Tipo assim:

No emulador da Sun, basta manter pressionado os botões 4 ou 6 para que o Sprite(Personagem) ande para esquerda ou direita respectivamente. Com isso a tela do jogo é atualizada perfeitamente.

No emulador e no aparelho C65 (da SIEMENS) se eu manter pressionado o botão que faz o Sprite andar(para esquerda ou direita) o Personagem fica andando em “camera lenta” e o chão tb fica passando em “camera lenta”, mas os outros Sprites NÃO ficam em “camera lenta” (isso me faz pensar que a atualização da tela esta correta).
Caso eu fique apertando e soltando velozmente as teclas que fazem o Personagem andar, ele NÃO fica em camera lenta…

Testa no seu celular(fazendo o favor), pois quero saber se isso é uma falha de implementação ou do meu celular(já que no emulador da Sun tudo funcionou corretamente).

Desde já gradeço!

Cara, infelizmente não consigo testar aqui… Meu celular (Motorola C650) não aceita jars com mais de 100kb. Eu tentei mesmo assim e deu arquivo inválido :frowning: