Foros > Java: J2ME Teclas Error

  1. other2008

    Mensajes [2] - Enviado el Domingo 15 de Junio de 2008 a las 22:58hs

    Hola estoy desarrollando un juego en J2me para celular, y quisiera que este funcione con las teclas 4 8 6 2 5(fire) y las direccionales como cualquier otro juego pero me sale error o cuando lo implemento se mueve de form etraña, espero me puedan ayudar.


    El codigo que funciona pero con error en el movimiento e :


    "//------------------------------------------------------------------------------
    private void calculateCoupleX(int keyState) {

    // determines which way to move and changes the
    // x coordinate accordingly
    if ((keyState & LEFT_PRESSED) != 0) {
    setCoupleX(Math.max(getGAME_ORIGIN_X() + getCoupleSprite().getWidth(), getCoupleX() - getDx()));
    // getGAME_ORIGIN_X() + getCoupleSprite().getWidth() - getCoupleSprite().getWidth() /32 , getCoupleX() - getDx()));
    } else if ((keyState & RIGHT_PRESSED) != 0) {
    setCoupleX(Math.min(getGAME_ORIGIN_X() + getGAME_WIDTH() ,
    getCoupleX() + getDx()));
    }
    if ((keyPressed & KEY_NUM4) != 0) {
    setCoupleX(Math.max(getGAME_ORIGIN_X() + getCoupleSprite().getWidth(), getCoupleX() - getDx()));
    // getGAME_ORIGIN_X() + getCoupleSprite().getWidth() - getCoupleSprite().getWidth() /32 , getCoupleX() - getDx()));
    } else if ((keyPressed & KEY_NUM6) != 0) {
    setCoupleX(Math.min(getGAME_ORIGIN_X() + getGAME_WIDTH() ,
    getCoupleX() + getDx()));
    }
    /*if ((keyState & Canvas.KEY_NUM4)!=0){
    setCoupleX(Math.max(getGAME_ORIGIN_X() + getCoupleSprite().getWidth(), getCoupleX() - getDx()));
    } else if ((keyState & Canvas.KEY_NUM6)!=0){
    setCoupleX(Math.min(getGAME_ORIGIN_X() + getGAME_WIDTH() ,
    getCoupleX() + getDx()));
    }
    */

    }

    private void calculateCoupleY(int keyState) {

    // determines which way to move and changes the
    // Y coordinate accordingly

    if ((keyState & DOWN_PRESSED) != 0) {
    setCoupleY(Math.min(getGAME_ORIGIN_Y() + getGAME_HEIGHT(), getCoupleY()+getDy()));
    } else if ((keyState & UP_PRESSED) != 0) {

    setCoupleY(Math.max(getGAME_ORIGIN_Y() + getCoupleSprite().getHeight() , getCoupleY() - getDy()));
    }

    }*/"


    //-------------------------------------------------------------------------------------------------


    QUIERO UTILIZAR ESTA FORMA:


    public void keyPressed(int keyCode) {
    int action=getGameAction(keyCode);
    switch (action) {
    case FIRE:
    // Disparar
    break;
    case LEFT:
    // Mover a la izquierda
    break;
    case RIGHT:
    // Mover a la derecha
    break;
    case UP:
    // Mover hacia arriba
    break;
    case DOWN:
    // Mover hacia abajo
    break;
    }
    }


     


    PERO ME DA ERROR EN EL "KeyCode" no se que hacer alguien que me pueda dar un ejemplo o ayudar a solucionar esto se lo agradecere.

  2. TXRX

    Mensajes [2] - Enviado el Domingo 15 de Junio de 2008 a las 23:03hs

    teneis que revisar lo del canvas ya que algunos comandos no se pueden utilizar en ambos, y creo que ese error es porque posiblemente haigas importado ambas librerias. espero haya sido util

  3. TXRX

    Mensajes [2] - Enviado el Domingo 15 de Junio de 2008 a las 23:05hs

    ojo me olvid erevisa la opcion que tienes para la recepcion de GameAction y como llamas a tus clasese para que hagas el movimiento, tambien echale un ojo a lo de KeyState getKey y KeyPressed que creo que te seria de ayuda.


responder

Para poder responder a este tema tenes que ingresar. Si no tenes una cuenta podes registrarse gratis..

publicidad