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

2020/12/2

Game won't load on Greenfoot website

1
2
Gbasire Gbasire

2020/12/2

#
Hello, I made a quick demo game that looks like Pokémon, and I uploaded it on the website. The problem is that the webpage won't load the scenario, it will be stuck on "initialising" for about 5 minutes before loading it. And even after It finally loaded, it will freeze at some moments. It works perfectly on my computer, and I tried to re-upload the scenario, try another browser, but nothing works. What can I do ? (scenario here
Gbasire Gbasire

2020/12/3

#
I believe the problem is that there are gifs, but I'm using the lastest greenfoot version and I optimized them all, so I don't know why this is happening. Do I really need to convert the gifs to separate frames ? :(
danpost danpost

2020/12/3

#
Gbasire wrote...
I believe the problem is that there are gifs
No. I do not believe that is the problem. I believe that your inclusion of wait methods is the problem. The Object class (root of ALL classes) has wait methods that are used by java internally. It may be (and probably so) that calls to those wait methods are being diverted to your wait methods; and because milliseconds are now scaled to per frame amounts (by use of Greenfoot.delay in your wait methods), huge (long term) delays are occurring. Remove all of your wait methods. Use int act counters to control image cycling.
danpost danpost

2020/12/3

#
Tested -- as soon as all wait methods were removed, upload initialized almost immediately.
Gbasire Gbasire

2020/12/3

#
Thank you for your answer, but I'm a beginner to greenfoot, could you show me an example of what you think is the best way to replace a wait method ? Again, thank you really much :)
danpost danpost

2020/12/3

#
Gbasire wrote...
could you show me an example of what you think is the best way to replace a wait method ?
Exaample 1 (only one cycle of images):
import greenfoot.*;

public class Poussiere extends Actor
{
    // the image set
    GreenfootImage[] images =
    {
        new GreenfootImage("Poussiere3.png"),
        new GreenfootImage("Poussiere4.png"),
        new GreenfootImage("Poussiere5.png"),
        new GreenfootImage("Poussiere6.png")
    };
    int imgK; // the counter
    
    public Poussiere()
    {
        setImage(images[0]); // initial image
    }
    
    public void act() 
    {
        if (++imgK == 80) getWorld().removeObject(this); // remove upon image cycle completion
        else if (imgK%20 == 0) setImage(images[imgK/20]); // change image after 20 act cycles
    }
}
Example 2 (controlled cycling of changing image sets):
import greenfoot.*;

public class Boy extends Actor
{
    // the image sets (in order of rotational direction)
    GreenfootImage[][] images =
    {
        {
            new GreenfootImage("boyRight.png"),
            new GreenfootImage("boyRightRun.png")
        },
        {
            new GreenfootImage("boyDown.png"),
            new GreenfootImage("boyDownRun.png")
        },
        {
            new GreenfootImage("boyLeft.png"),
            new GreenfootImage("boyLeftRun.png")
        },
        {
            new GreenfootImage("boyUp.png"),
            new GreenfootImage("boyUpRun.png")
        }
    };
    GreenfootImage[] imgSet = images[3]; // the active image set
    int speed = 2;
    int imgK; // the image counter
    
    public Boy()
    {
        setImage(imgSet[0]); // initial image
    }
    
    public void act() 
    {
        // get moving direction
        int dx = 0, dy = 0;
        if (Greenfoot.isKeyDown("left")) dx--;
        if (Greenfoot.isKeyDown("right")) dx++;
        if (Greenfoot.isKeyDown("up")) dy--;
        if (Greenfoot.isKeyDown("down")) dy++;
        if (dx*dy != 0 || dx+dy == 0) return; // conflicting directions or opposing or no direction
        // image control
        int r = (1-dx)*dx*dx + (2-dy)*dy*dy; // rotational index of moving direction given
        if (imgSet != images[r]) imgK = 0; else imgK = (imgK+1)%12; // controlling image counter
        imgSet = images[r]; // controlling image set
        if (imgK%6 == 0) setImage(imgSet[imgK/6]); // updating image
        // moving
        setLocation(getX()+dx*speed, getY()+dy*speed);
        // colliding
        if (isTouching(Arbre.class)) setLocation(getX()-dx*speed, getY()-dx*speed);
        if (isTouching(Herbes.class))
        {
            int n = Greenfoot.getRandomNumber(100);
            if (n < 20) getWorld().addObject(new Poussiere(), getX(), getY());
            if (n == 20)
            {
                speed = 0;
                getWorld().addObject(new TransitionIn(), 300, 200);
            }
        }
    }
}
Gbasire Gbasire

2020/12/3

#
Hey, so I changed every single class that had wait like you said, but there are 2 problems : 1 : the collisions with trees don't work anymore : if I hit a tree on the side, I will go down, and if I hit a tree on the bottom, i will be able to walk trough it. 2: the game still doesn't want to launch that's really weird, idk what to do
danpost danpost

2020/12/3

#
(1) Show current Boy class codes (or indicate you copy/pasted what I gave above); (2) Make sure to remove wait from ALL classes.
Gbasire Gbasire

2020/12/3

#
I copy pasted the Boy class code, and removed every single "wait" from all classes the code :
import greenfoot.*;
public class Boy extends Actor
{
    // the image sets (in order of rotational direction)
    GreenfootImage[][] images =
    {
        {
            new GreenfootImage("boyRight.png"),
            new GreenfootImage("boyRightRun.png")
        },
        {
            new GreenfootImage("boyDown.png"),
            new GreenfootImage("boyDownRun.png")
        },
        {
            new GreenfootImage("boyLeft.png"),
            new GreenfootImage("boyLeftRun.png")
        },
        {
            new GreenfootImage("boyUp.png"),
            new GreenfootImage("boyUpRun.png")
        }
    };
    GreenfootImage[] imgSet = images[3]; // the active image set
    int speed = 2;
    int imgK; // the image counter 
    public Boy()
    {
        setImage(imgSet[0]); // initial image
    } 
    public void act() 
    {        
        int dx = 0, dy = 0; // get moving direction
        if (Greenfoot.isKeyDown("left")) 
        {
            dx--;
        }
        if (Greenfoot.isKeyDown("right")) 
        {
            dx++;
        }
        if (Greenfoot.isKeyDown("up")) 
        {
            dy--;
        }
        if (Greenfoot.isKeyDown("down")) 
        {
            dy++;
        }
        if (dx*dy != 0 || dx+dy == 0) 
        {
            return; // conflicting directions or opposing or no direction
        } 
        int r = (1-dx)*dx*dx + (2-dy)*dy*dy; // rotational index of moving direction given
        if (imgSet != images[r])
        {
            imgK = 0; // image control
        }
        else 
        {
            imgK = (imgK+1)%12; // controlling image counter
        }
        imgSet = images[r]; // controlling image set
        if (imgK%6 == 0) 
        {
            setImage(imgSet[imgK/6]); // updating image 
        }
        setLocation(getX()+dx*speed, getY()+dy*speed); // moving
        if (isTouching(Arbre.class)) 
        {
            setLocation(getX()-dx*speed, getY()-dx*speed); // colliding
        }
        if (isTouching(Herbes.class))
        {
            int n = Greenfoot.getRandomNumber(100);
            if (n < 20) 
            {
                getWorld().addObject(new Poussiere(), getX(), getY());
            }
            if (n == 20)
            {
                speed = 0;
                getWorld().addObject(new TransitionIn(), 300, 200);
            }
        }
    }
}
danpost danpost

2020/12/3

#
Gbasire wrote...
I ... removed every single "wait" from all classes
Your BattleWorld class still has it.
danpost danpost

2020/12/3

#
Gbasire wrote...
I copy pasted the Boy class code,
Remove checkTree method from Boy class.
danpost danpost

2020/12/3

#
I mistyped a character. Your line 71 in Boy class immediately above should be:
setLocation(getX()-dx*speed, getY()-dy*speed); // colliding
(with a dy)
Gbasire Gbasire

2020/12/3

#
Collisions are fixed, thanks, but even after I removed the Wait from all Worlds, it still won't launch
Gbasire Gbasire

2020/12/3

#
I tried to review all actors entirely but didn't find anything, do you know what could be happening ?
danpost danpost

2020/12/3

#
Gbasire wrote...
I tried to review all actors entirely but didn't find anything, do you know what could be happening ?
Not sure, yet.
There are more replies on the next page.
1
2