This site requires JavaScript, please enable it in your browser!
Greenfoot back
Validated
Validated wrote ...

2017/3/1

how to make a GIF image displacement when leaping?

Validated Validated

2017/3/1

#
this
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Sonic here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Sonic extends Actor
{
    private GifImage myGif = new GifImage("sonicdiam.gif");
    private GifImage myGif2 = new GifImage("sonicjump.gif");
    private int ySpeed;
    private int apexTimer;
 
    public void act() 
    {
        cekkeyboard();
        cekJump();
        cekMoveJump();
    }
     public void cekkeyboard()
    {
        int X=getX();
        int Y=getY();
    
        if(Greenfoot.isKeyDown("Left"))     X-=2;
        if(Greenfoot.isKeyDown("Right"))    X+=2;
        setLocation(X,Y);
    }
    public void cekJump()
    {
        int groundLevel = getWorld().getHeight() - getImage().getHeight()/1; //Letak dimana jatuh Si aktor
        boolean onGround = (getY() == groundLevel);
        if (!onGround) // di tengah si aktor melompat
        {
            if (ySpeed == 0 && apexTimer > 0) apexTimer--; // menjalankan waktu melompat
            if (ySpeed == 0 && apexTimer > 0) return; // waktu melompat masih berjalan
            ySpeed++; // adds gravity effect
            setLocation(getX(), getY()+ySpeed); // membuat jatuh (naik lebih lambat atau jatuh lebih cepat)
            if (getY()>=groundLevel) // telah mendarat (permukaan tanah mencapai)
            {
                setLocation(getX(), groundLevel); // set dibawah
                Greenfoot.getKey(); // menghapus semua key ketika loncat(pas loncat ga bisa di apapain pas pencet key yang lain)
           }
        }
        else 
        {
            if(Greenfoot.isKeyDown("Up")) // key yang ingin di setting
             
            {
                ySpeed = -15; // kecepatan melompat
                setLocation(getX(), getY()+ySpeed); // loncat
                apexTimer = 1;  //  jeda waktu ketika di atas
            } 
        }
    }
    public void cekMoveJump()
    {
        GifImage currentGif = myGif;
        if (Greenfoot.isKeyDown("Up")) currentGif = myGif2;
        setImage(currentGif.getCurrentImage());
    }
    
    
  }
danpost danpost

2017/3/1

#
I am not sure what you mean by "how to make a GIF image displacement when leaping?". Can you please explain what should be happening and how the behavior currently differs from what you want.
You need to login to post a reply.