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

2022/1/26

transparent gif

Aaron-aid Aaron-aid

2022/1/26

#
hello, i play a transparent gif but each frames get stuck, (the legs show previous frames even though there is a background)
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Player here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Player extends Actor
{
    boolean touched = true;
    //controlls
    static boolean playerWalking = true;
    GifImage LeftWalk = new GifImage("LeftWalk.gif");
    GifImage RightWalk = new GifImage("RightWalk.gif");
    String direction = "front";
    
    //health
    static int health = 100;
    static int boosterhealth = 200;
    
    /**
     * Act - do whatever the Player wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        start();
    }    
    void start()
    {
        playerMovement();
    }
    void playerMovement()
    {
        p_moveLeft(3);
    }
    void p_moveLeft(int speed)
    {
        if(playerWalking == true)
        {
         if(getWorld().getObjects(playerfeet.class).get(0).touchingWalkinglocation() == false)
         {
             if (direction == "front"){
             setLocation(getX()-speed, getY());
            }
            if (direction == "left"){
             setLocation(getX()+speed, getY());
            }
            if (direction == "right"){
             setLocation(getX()-speed, getY());
            }
         }
         if(getWorld().getObjects(playerfeet.class).get(0).touchingWalkinglocation() == true){
         if (Greenfoot.isKeyDown("D") == false && Greenfoot.isKeyDown("A") == false)
         {
             if (direction == "front"){
             //setImage("");
            }
            if (direction == "left"){
             setImage("idleL.png");
             getImage().scale(60, 140);
            }
            if (direction == "right"){
             setImage("idleR.png");
             getImage().scale(50, 140);
            }
         }
         if(Greenfoot.isKeyDown("D"))
         {
             direction = "right";
             setLocation(getX()+speed, getY());
             setImage(RightWalk.getCurrentImage());
             getImage().scale(200, 150);
             
             
         }
         if(Greenfoot.isKeyDown("A"))
         {
             direction = "left";
             touched = false;
             setLocation(getX()-speed, getY());
             setImage(LeftWalk.getCurrentImage());
             getImage().scale(200, 150);
         }
        }
    }
    }
}
Aaron-aid Aaron-aid

2022/1/26

#
https://www.greenfoot.org/scenarios/29135?_sm_byp=iVV5B6JkB06H6FN2
Aaron-aid Aaron-aid

2022/1/26

#
heres the game (A and D to move)
danpost danpost

2022/1/26

#
Change all your conditions from:
if (direction == "whatever")
to
if ("whatever".equals(direction))
The literal String object given is not the same instance of the String object you are trying to compare to. Using the String instance equals method will compare the contents of the two strings. In general, putting the literal first will ensure that no nullPointerException error will occur (although in your case, I do not think that will be an issue)
Aaron-aid Aaron-aid

2022/1/27

#
oh, thats actully pretty helpful thx
Aaron-aid Aaron-aid

2022/1/27

#
that fixed that issue but im still having probs with the gif :c
danpost danpost

2022/1/27

#
Aaron-aid wrote...
that fixed that issue but im still having probs with the gif :c
Scale down your images in the files themselves. Also, remove any excess transparencies around the outer edges (top, left, right and bottom) of the images.
You need to login to post a reply.