This site requires JavaScript, please enable it in your browser!
Greenfoot
Username
Password
Remember Me?
Sign Up, Lost Password
Activity
About
Documentation
Download
Discuss
Scenarios
Discussions
You need to login to take part
Current Discussions
addObject() or setImage() won´t work
By elektro, with 2 replies.
Last reply by danpost, over 3 years ago:
You need an
addObject
line to put
question
in the world.
How do you make a grid in a non grid world?
By Darkstep, with 1 reply.
Replied to by danpost, over 3 years ago:
Darkstep wrote...
I know you have to use a GridActor for actors going into the grid and a separate actor class for the actual grid itself
Actually ... no. You do not have to use
GridActor
(specific to a grid world) and you do not need an actor for the grid (grid can be drawn onto the world background). All coordinates will be based on "cell" width A virtual 0 coordinate would be just half a "cell" width. A virtual 1 coordinate would be one and one-half "cell" widths. All are half a "cell" width plus the virtual coordinate times a "cell" width.
How to addObject in constructor of an actor class
By Nicole05, with 1 reply.
Replied to by RcCookie, over 3 years ago:
The problem is that when the object is created it is not in a world yet. So, it has to add itself to the world first, then it can add other objects. These information have to be passed into the constructor. <Code Omitted>By doing so you can also replace this <Code Omitted>with this <Code Omitted>
Why won't "or" not work
By Gabe1098, with 3 replies.
Last reply by Gabe1098, over 3 years ago:
Roshan123 wrote...
In line 4 <Code Omitted>
Thank you so much!!!
Help idk whats wrong with this
By mariq_rasyid29, with 3 replies.
Last reply by mariq_rasyid29, over 3 years ago:
thx all for help me ^^
Add a object on scenario doesn't work
By Sajji25, with 2 replies.
Last reply by Super_Hippo, over 3 years ago:
In your constructor, you add “new” instances of the Intel and AMD classes. There are not the ones in your variables, so the mouseClicked method will always return false. As a side note, you shouldn’t use the very same names for classes and objects to avoid confusion.
Colored Code Questions
By Gabe1098, with 8 replies.
Last reply by Gabe1098, over 3 years ago:
Super_Hippo wrote...
The act method is executed once per act cycle for the active world and all actors in the world. A (do-)loop executes until it finishes. Nothing else is happening in the meantime.
Thank you so much!!!
I need help with a snake game
By Pimkimi, with 5 replies.
Last reply by Pimkimi, over 3 years ago:
danpost wrote...
Pimkimi wrote...
if you need the entire code, just ask, i will give it with pleasure
To have entire snake move as a unit, best would be to control all parts from the head. I have several snake demos in my
Demos by danpost
collection. You may want to check them out.
Being a beginner, I don't understand all your code. I don't know how to apply it in my code with the values and classes I have. But thanks anyway! And thank you for your previous quick answers, I appreciate it
Problem with removing Objects
By Turbo_Thorsten, with 10 replies.
Last reply by Turbo_Thorsten, over 3 years ago:
Found a Solution
Problem with executing a method from another class
By Turbo_Thorsten, with 7 replies.
Last reply by Turbo_Thorsten, over 3 years ago:
Ok I'm ending this thread bc I found a solution. I don't really understand it but it's working so thank y'all
How add background music and stop when world changes
By Gh0sT, with 3 replies.
Last reply by Gabe1098, over 3 years ago:
oh wait you meant the music I thought you meant the whole project
I got a problem with a Timer
By Turbo_Thorsten, with 4 replies.
Last reply by Turbo_Thorsten, over 3 years ago:
danpost wrote...
Turbo_Thorsten wrote...
The virus and the bacterias should freeze at the same time for the same time but that isn't the case. The bacteria timer is sometimes faster than the virus timer and I don't get why.
For better control, remove timers from both
Virus
and
Bacteria
classes Put a timer in
MyWorld
class and control it from
act
method there. At beginning of
act
methods of the enemy classes, use: <Code Omitted>The
boolean
fields,
freezeVirus
and
freezeBacteria
, are not needed.
My character can move in 8 directions and I can't make it work so that my character can't go past a border(object not the world border).
By Turbo_Thorsten, with 9 replies.
Last reply by Turbo_Thorsten, over 3 years ago:
danpost wrote...
Two problems with it. One is that the moving distance does not match the "rebound" distance (when a border is encountered). The other is "rebound" code does not know which direction of movement caused the collision. Turning 180 does no good unless the actor faces the direction it moved. I would move the "rebound" code into the
checkKeypress
method and rewrite the method as follows:
Problem with removeObjects
By Turbo_Thorsten, with 9 replies.
Last reply by Turbo_Thorsten, over 3 years ago:
danpost wrote...
Super_Hippo wrote...
You remove the actor from the world in line 32. After that, you call the nuke method (line 40). The actor isn’t in the world anymore, so line 57 will never execute.
Move line 32 to after line 46.
Thank you it works!
how do I call
By Gabe1098, with 3 replies.
Last reply by danpost, over 3 years ago:
Gabe1098 wrote...
Thanks! but how do I do a public one?
Same way from within the class (for
this
one). That is, the above line is equivalent to: <Code Omitted>following the standard: <Code Omitted>where 'this' refers to the object the method is executing on (or for). Similar to the English grammar of a sentence -- subject followed by verb. From outside the class where the method is public, a reference to the object of the class the method is in is needed and must be explicitly given. For example:
60
61
62
63
64
65
66
X