×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    37

    different layers

    hi
    some question to you:
    1) I want to display a background graphics and a sprite image over it using MIDP 1.0. which method have I to use?
    2) I lernt how to animate the sprite image. it simple can be moved over the screen, but how can I put a limit to the sprite position so it can't go in a nondisplayable area?
    I tried to use getWidth and getHight with bad resoult.
    is there a standard procedure to do that?
    3) in gaming is very important the joypad.I used getKeyCode() to know if a key is pressed (left,fire,up etc...).but there is a frustrating limitation in that: I need 2 instance from a key:when it is pressed(and still pressed "ON"), and when it become not pressed"OFF".
    somenthing like the midi message: when I press a key on the keyboard the generated midi message will be :note on,note off.
    why I need this? if a player want to move the sprite to the left he press the left button on the device, that move the sprite one unit to the left. but if the player keep the left button pressed the sprite move again one unit to the left instead of more unit to the left basing on the pressing time.am I wrong?


    (sorry for my english)hope someone can help me.
    eml

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    1. You can use a simple drawImage, just make sure your sprite is a png with transparent background. Also you will have to clear the area the sprite is leaving (repaint the background on it), again using drawImage and also setClip. These are all methods of the Graphics class of course.
    2. Are you making sure to subtract the size of the sprite. If a sprite can't leave the screen then it's top left coordinate should be smaller than (getWidth - sprite.width) and (getHeight - sprite.height).
    3. There are exactly the methods you need. They are called keyPressed and keyReleased (in the Canvas class). Set up a boolean flag on keyPressed and reset it on keyReleased:
    Code:
    private boolean goingLeft;
    
    protected void keyPressed(int keyCode) {
        if (getGameAction(keyCode) == Canvas.LEFT) 
            goingLeft = true;
    }
    
    protected void keyReleased(int keyCode) {
        if (getGameAction(keyCode) == Canvas.LEFT) 
            goingLeft = false;
    }
    
    // and use some timed method where you check the flag and
    // move the sprite according:
    private void someTimedMethod() {
        if (goingLeft)
            sprite.left--;
    }

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    37
    thanks shmoove
    your answer is really usefull
    eml

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •