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

2020/1/10

How do i change my background with a button

1
2
Yuuki Yuuki

2020/1/10

#
So basically I'm writing a code and the backround has to change when it clicks "z", this is my code
public void changeImage()
    {
        if (Greenfoot.isKeyDown("z")){
            setBackground("Pokemenu.jpg");
    }
    }
danpost danpost

2020/1/10

#
Yuuki wrote...
the backround has to change when it clicks "z", this is my code << Code Omitted >>
You need to call this method from the act method of the class (or change this method to be the act method).
Yuuki Yuuki

2020/1/13

#
ok. thanks.
Yuuki Yuuki

2020/1/13

#
Ok, so I did that, but it doesn't work, as it just stays the same, what do i do?
danpost danpost

2020/1/13

#
Yuuki wrote...
Ok, so I did that, but it doesn't work, as it just stays the same, what do i do?
No errors? Maybe you should provide the entire class codes.
Yuuki Yuuki

2020/1/15

#
Funny, im stupid, dont mind me, it was just the fact that I didnt have it to the right png.
Yuuki Yuuki

2020/1/15

#
How do i move things along the Y-Axis?
danpost danpost

2020/1/15

#
Yuuki wrote...
How do i move things along the Y-Axis?
Either use:
turn(90);
move(??);
turn(-90);
or
setLocation(getX(), getY()+??);
Yuuki Yuuki

2020/1/22

#
thank you very much, to keep you busy, can you help me get an image to get gradually larger with time ?
Yuuki Yuuki

2020/1/22

#
and to add to that, how do i make more actors spawn over time
danpost danpost

2020/1/22

#
Yuuki wrote...
thank you very much, to keep you busy, can you help me get an image to get gradually larger with time ?
Save initial image in a field within the class. Use:
// field
private GreenfootImage baseImage;

// in constructor
baseImage = getImage();

// one way to make larger
GreenfootImage growImage = new GreenfootImage(baseImage);
growImage.scale(getImage().getWidth()*5/4, getImage().getHeight()*5/4);
setImage(growImage);
The change in size, here, is given in the scaling line. Better might be to have a sized field to count the number of times it has been scaled and use its value to determine what factor is used for scaling.
danpost danpost

2020/1/22

#
Yuuki wrote...
and to add to that, how do i make more actors spawn over time
Use an act method in your World subclass. The either add a timer field or use random chance to regulate the spawning.
Yuuki Yuuki

2020/1/23

#
Hmm, ok, so inmy ongoing quest to never stop annoying you, how do i make actors randomly spawn within a certain distance from my actor overtime.
Yuuki Yuuki

2020/1/23

#
What i mean is like, the actor is moving by my command, how do i get that a different actor to spawn a set distance away from the original actor.
danpost danpost

2020/1/23

#
Yuuki wrote...
What i mean is like, the actor is moving by my command, how do i get that a different actor to spawn a set distance away from the original actor.
Keep a reference field to the original actor in your world class so you can get its location easily when needed.
There are more replies on the next page.
1
2