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
loops
By Yichui, with 1 reply.
Replied to by danpost, about 7 years ago:
Yichui wrote...
for-loop scenarios (e.g. changing speed/image of an enemy once a certain score is achieved)
I do not see how your examples could have anything to do with looping. You would not continuously change an enemy's speed or its image multiple times between consecutive frames in the running of the scenario. Loops are used to execute code multiple times during the same act step (at one moment in time as far as a human is concerned). Only the end result will be apparent to the user. One of the first uses you might have for a
for
loop is to add multiple objects into
HealthGUI stops program immediately after world is constructed
By SushiLlama, with 3 replies.
Last reply by danpost, about 7 years ago:
SushiLlama wrote...
Thats everything? Does the default case need it too? Thank you!!!
As long as the
default
case is listed last -- no. There is no more code in the
switch
after the last case, so it is not required for the last one listed.
Random objects
By vande, with 1 reply.
Replied to by SushiLlama, about 7 years ago:
Hey, first of all you could give us more concrete Information, but ill try my best to help. Well Greenfoot.getRandomNumber(10) gives you a 0,1,2,3,4,5,6,7,8,9. So you would want to add 1 in order to start from 1 and end at 9 -> when you dont want to start from 0, you have to add the offset (difference of the higher number mius the smaller one). In your case that would be 10 because the highest number 25 is 10 away from your small number 15. So your code should look like this: public int getRandomNumber(int startNumber,int endNumber) { int offsetRandom = Greenfoot.getRandomNumber(en
Prevent image automatically turning when turning
By SushiLlama, with 22 replies.
Last reply by SushiLlama, about 7 years ago:
Thank you so much!!! Just a week and i already fell in love with this kind community! Solved
How can I draw something?
By ihjufaeshiju, with 1 reply.
Replied to by danpost, about 7 years ago:
You would need to add the
Screen
actor into the world for it to be visible. Also, when drawing the polygon, the last value needs to match the number of elements in the arrays (4, not 3).
errors when compiling system.out.print
By jbiser361, with 2 replies.
Last reply by jbiser361, about 7 years ago:
ooo thank you so much!
Build a Color object called yell to represent yellow using three integer values.
By jbiser361, with 1 reply.
Replied to by danpost, about 7 years ago:
jbiser361 wrote...
im just a little confused about the wording because i don't believe you can create a color object.... can someone give me an example of this lol
The
greenfoot.Color
class had two
public
constructors (one even uses exactly three
int
values). It definitely is possible to create a Color object.
Trying to make a tank that faces whichever way its moving
By CharizardXRules, with 1 reply.
Replied to by danpost, about 7 years ago:
If I understand correctly, you want the following for line 23: <Code Omitted>If not that, then maybe this (my original thought):: <Code Omitted>It really depends on the initial direction the
BarrelLeft
object is pointing (as well as the
BarrelRight
object).
Random spawn at edge of screen across screen
By GreenHead456, with 16 replies.
Last reply by GreenHead456, about 7 years ago:
OK thanks, I will refer to this for future projects.
Putting images from the gallery into the code
By CodingCowgirl, with 2 replies.
Last reply by CodingCowgirl, about 7 years ago:
I've already done this. But thanks for answering.
Checking arrangements of actors
By randomuser, with 7 replies.
Last reply by danpost, about 7 years ago:
randomuser wrote...
with that, my code pops up with an error saying 'incompatible types: boolean cannot be converted to boolean' (I'm sorry about this code never quite seeming to work)
Sorry -- my bad. It was supposed to be: <Code Omitted>
Image Constantly Blinks/Changes
By m0nday_, with 1 reply.
Replied to by danpost, about 7 years ago:
Line 20 will always be executed because
isSeen
is being assigned a
true
value in line 19. That is, line 19 is equivalent to: <Code Omitted>To compare values, use the conditional equality operator, '
==
'. As: <Code Omitted>
text box or image showing up when character goes on top of character
By Bluetiger, with 6 replies.
Last reply by danpost, about 7 years ago:
Bluetiger wrote...
That game seems quite helpful. Is there anyway I could see the code for it?
Run the scenario. Click on buttons (ground platforms -- "Where", "What" and "Who" buttons).
Help with organizing my programming so it looks better and fixing errors
By KIOP, with 15 replies.
Last reply by danpost, about 7 years ago:
The class code itself should have one pair -- one (opening bracket) after the class declaration line and one (closing bracket) at the end of the class. Each method, likewise, should have one pair -- one after the declaration line and one at its end. Any and all local code blocks (for
iif
,
for
,
switch
,
do
,
while
, etc) should have one pair -- one at the beginning and one at its end. Any and all
excess
brackets must be removed (see lines 24 and 50).
Left justify and paragraph form a long line of string
By protocolUnknown, with 1 reply.
Replied to by danpost, about 7 years ago:
"At a set number of characters"? -- no. You could just make one yourself, if you wanted, however.
168
169
170
171
172
173
174
X