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

2024/1/29

How to change background while running a loop

TillaB13 TillaB13

2024/1/29

#
Im trying to make the screen change when the actor "dies" but its making my greenfoot crash, any advice?
danpost danpost

2024/1/29

#
TillaB13 wrote...
Im trying to make the screen change when the actor "dies" but its making my greenfoot crash, any advice?
Please show all classes with codes related to the background image.
TillaB13 TillaB13

2024/1/30

#
The class for the dead.lol background only has the super(600, 400, 1); code The backgronud of the level has the super constructer and the addition of other object This is all in my "Ball" class which is my character This is the method is use to jump: public void gravity(int power, boolean bounced) { if(isTouching(Ground.class) || bounced) { int x = 0; int v = power; int g = -2; isJumping = true; setLocation(getX(),getY()-1);//so that its not touching the ground while((getOneObjectAtOffset(0,18,Ground.class))==null)// && (getOneObjectAtOffset(15,1,Ground.class))==null && (getOneObjectAtOffset(-15,1,Ground.class))==null) { if(Greenfoot.isKeyDown("right")) { if(getOneObjectAtOffset(18,0,Ground.class)==null) { x = a; } } else if(Greenfoot.isKeyDown("left")) { if(getOneObjectAtOffset(-18,0,Ground.class)==null) { x = -a; } } while(!(getOneObjectAtOffset(-18,0,Ground.class)==null)) { setLocation(getX()+1,getY()); } while(!(getOneObjectAtOffset(18,0,Ground.class)==null)) { setLocation(getX()-1,getY()); } if(getOneObjectAtOffset(0,18-v,Ground.class)==null) { setLocation(getX() + x, getY()-v); v+=g; } else { while(getOneObjectAtOffset(0,18,Ground.class)==null) { setLocation(getX(), getY()+4); } } Greenfoot.delay(1); x=0; lava(); if(isTouching(Key.class)) { canClear = true; Actor Key1 = getOneObjectAtOffset(0,0,Key.class); getWorld().removeObject(Key1); } if(getOneObjectAtOffset(0,18,Bouncer.class)!=null) { gravity(30, true); } if((getOneObjectAtOffset(0,-18,Ground.class)!=null))// || getOneObjectAtOffset(-10,-18,Ground.class)!=null || getOneObjectAtOffset(10,-18,Ground.class)!=null) && (getOneObjectAtOffset(-15,10,Ground.class)==null) || !(getOneObjectAtOffset(15,10,Ground.class)==null)) { while(getOneObjectAtOffset(0,-18,Ground.class)!=null) //|| getOneObjectAtOffset(-10,-18,Ground.class)!=null || getOneObjectAtOffset(10,-18,Ground.class)!=null) { setLocation(getX(),getY()+1); } setLocation(getX(),getY()+1); gravity(0, true); } if(isTouching(Pusher.class)) { push(); } if(getOneObjectAtOffset(0,-18,Pusher_left.class)!=null) { push_left(); } } while(getOneObjectAtOffset(0,18,Ground.class)!=null) { setLocation(getX(), getY()-1); } setLocation(getX(), getY()+1); isJumping = false; } } "dying" method public void lava() { if(isTouching(lava.class)) { Greenfoot.setWorld(new dead_lol()); //dead_lol is the death screen } }
TillaB13 TillaB13

2024/1/30

#
There are some long lines I forgot to get rid of the comments on, sorry
danpost danpost

2024/1/31

#
TillaB13 wrote...
There are some long lines I forgot to get rid of the comments on, sorry
No problem. You should use code tags, though, to make the code easier to read. Where are you calling the lava method from? (show method and indicate what class it is in). Please provide the codes in the dead_lol class as well.
TillaB13 TillaB13

2024/2/1

#
I am calling the lava method from my main act() method in my character actor and in my methods for jumping/being pushed Lava method is in my ball class, which is my character public void lava() { if(isTouching(lava.class)) { Greenfoot.setWorld(new dead_lol()); } } World subclass for the dead_lol screen, I havent changed the code in this public class dead_lol extends World { /** * Constructor for objects of class dead_lol. * */ public dead_lol() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); } }
TillaB13 TillaB13

2024/2/1

#
Also, what are code tags?
danpost danpost

2024/2/2

#
TillaB13 wrote...
Also, what are code tags?
Just log in and click on the "Quote" under my name, danpost. Then look at the code, particularly the square brackets at both ends of the code:
public class dead_lol extends World
{

    /**
     * Constructor for objects of class dead_lol.
     * 
     */
    public dead_lol()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1); 
    }
}
danpost danpost

2024/2/2

#
As for the information and the code provided, I do not see anything that would cause your program to crash. Are you getting a code trace in your error environment?
TillaB13 TillaB13

2024/2/2

#
Thank you for the help, but I figured it out. I needed to break out of the loop and let the lava() method run in the act method. I LOVE YOU DANPOST THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!!!
You need to login to post a reply.