Discussions
You need to login to take part
Current Discussions
change the color of a label in world when actor location changes?
By lex404, with 2 replies.
Last reply by lex404, about 1 hour ago.
Hey, im working on some code to simulate a MIPS microprocessor. Im trying to change the color of a label when the getX of an actor equals a certain value. A snippet of the code is:
this is in the world class:
<Code Omitted>
i'm not receiving any errors, but its not changing the color like it should. any ideas?
Cutting Images
By kiarocks, with 13 replies.
Last reply by Builderboy2005, about 2 hours ago.
Idk if this is a good place to ask, but how would i cut out a shape like this <Image Omitted> from another image?
Making things happed when in a specific world
By tallyaka, with no replies.
I want to make it so that my actor switches worlds when he goes to the edge of the screen but I can't figure out how to make him go to a different world depending on what world he's in. I tried using the getWorld() command but I couldn't figure out how to make it work.
OR sign
By Richkeys, with 2 replies.
Last reply by Richkeys, about 9 hours ago.
How do you get the II sign working for OR command?
How do I access a method from the World?
By DMCGames, with 1 reply.
Replied to by Morran, about 11 hours ago.
How do you access a method from the World? I am trying to use getworld().Method() but it says cannot find method.
Class parameters
By Gazzzah, with 3 replies.
Last reply by Gazzzah, about 12 hours ago.
Hello, I am trying to make a simple spawn method that includes the class in the parameters.
I'm not really sure how to specify it though.
It would go something like:
<Code Omitted>
What goes in parameter name, or how can I modify it to work.
Image
By citadel, with 3 replies.
Last reply by citadel, about 15 hours ago.
Hi I'm trying to get greenfoot to display an image after my crab eats 10 worms but what is happening is that the crab itself is turning in to the image and before greenfoot can stop the lobster then eats the crab (bigger image) I need a way to remove the lobster before I change the crab into the picture.
<Code Omitted>
That is the code for the crab.
Thank you very much.
Professional content?
By THELAWL, with 1 reply.
Replied to by Morran, about 16 hours ago.
I started greenfoot not to long ago and now am beining to doubt the strengh of this development tool. is it possible to create professional work from greenfoot or is greenfoot just a stepping stone towards more complex development tools like UDK?
Need AI help
By THELAWL, with 17 replies.
Last reply by danpost, about 19 hours ago.
i just started Greenfoot today and was wondering how i could implent an AI into my modified "trick-the-Turtle" game that would make the enemy snakes begin to follow the playr turtle once the player turtle comes to close to a snake.
the problem im having is that i am creating a varible "distance" that defines the distance between a snake and the player turtle.
currently in have made some methods
this is in snake class:
- "newTurtle" is an instance varile declared before act method
public void moveTowardsTurtle()
{
if (newTurtle.getX() > getX() )
{
move(3);
}
}
it compiles fine, yet when i run the game i instantly get this
java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed.
at greenfoot.Actor.failIfNotInWorld(Actor.java:656)
at greenfoot.Actor.getX(Actor.java:157)
at Snake.move2(Snake.java:53)
at Snake.act(Snake.java:23)
at greenfoot.core.Simulation.actActor(Simulation.java:507)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:470)
at greenfoot.core.Simulation.runContent(Simulation.java:204)
at greenfoot.core.Simulation.run(Simulation.java:194)
java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed.
at greenfoot.Actor.failIfNotInWorld(Actor.java:656)
at greenfoot.Actor.getX(Actor.java:157)
at Snake.move2(Snake.java:53)
at Snake.act(Snake.java:23)
at greenfoot.core.Simulation.actActor(Simulation.java:507)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:470)
at greenfoot.core.Simulation.runContent(Simulation.java:204)
at greenfoot.core.Simulation.run(Simulation.java:194)
should i not be useing "getX" for this type of AI, is there a better way?
any help is appreicated
Learning Mathematics in Greenfoot
By nccb, with 6 replies.
Last reply by darkmist255, about 21 hours ago.
I've recently started a blog that some Greenfoot users may be interested in. It's targeted at those who know a bit of programming (i.e. I'm not going explain the very basics of coding), and want to understand the use of mathematics a bit better: either to see why it's useful, or to solve a particular problem in your games. It's called the sinepost, and there's a couple of posts up already on using trigonometry for doing angle calculations, with more posts to come in the next few weeks on things like wrapping around the world, and implementing movement systems. I'd be happy to hear feedback here, on in comments on the blogposts -- I hope it's useful to some of you.
Error: cannot find symbol- variable image 1
By sophiasturges, with 3 replies.
Last reply by sophiasturges, about 24 hours ago.
I'm not sure why I'm getting this error for assigning the up and down image to image 1 and 2? I'm trying to allow the key class to show black or white keys... I'm not having much luck. Help?
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
public class Key extends Actor
{
private boolean isDown;
private String key;
private String sound;
private String upImage;
private String downImage;
/**
* Create a new key.
*/
public Key (String keyName, String soundFile)
{
key = keyName;
sound = soundFile;
upImage = image1;
downImage = image2;
setImage(upImage);
isDown = false;
}
/**
* Do the action for this key.
*/
public void act()
{
if ( !isDown && Greenfoot.isKeyDown(key)){
play();
setImage (downImage);
isDown = true;
}
if (isDown && !Greenfoot.isKeyDown(key)){
setImage (upImage);
isDown = false;
}
}
/**
* Play the note of this key.
*/
public void play()
{
Greenfoot.playSound(sound);
}
}
Thanks,
Sophie
support class - counter
By craigv, with no replies.
how can I use this support class to keep score?
I have an asteroid type game, where my gunner shoots a ball, and makes contact with other objects ( thats when i want a score to be added)
thanks
how to manually "Feed" an object
By CCLong2010, with 9 replies.
Last reply by Duta, 1 day ago.
OK so I am trying to manually feed (add energy) my "friendly cat" to have him wake up. After 10 steps with out eating the pizza he falls asleep and you have to manually feed him to wake him up. Here is the code I have so far...any help would be appreciated.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
*
* FriendlyCat describes cats that
* - move and jump when corresponding control keys are pressed, when having enough energy
* - love pizzas and show their joy by dancing after eating three pizzas
*
*/
public class FriendlyCat extends Cat
{
private int pizzaEaten = 0;
private int energy = 10;
public FriendlyCat()
{
energy = 10;
pizzaEaten = 0;
}
public void act()
{
{
if (energy <= 0)
{
sleep(1);
return;
}
}
findPizza();
if (Greenfoot.isKeyDown("left"))
{
walkLeft(1);
energy --;
}
if (Greenfoot.isKeyDown("right"))
{
walkRight(1);
energy --;
}
if (Greenfoot.isKeyDown("down"))
{
jumpDown(1);
energy --;
}
if (Greenfoot.isKeyDown("up"))
{
jumpUp(1);
energy --;
}
if (energy <= 0)
{
sleep (1);
}
}
public void findPizza()
{
if (canSee(Pizza.class))
{
eat();
remove(Pizza.class);
pizzaEaten ++;
howManyEaten();
energy = energy + 5;
}
}
public void howManyEaten()
{
if (pizzaEaten == 3)
{
dance();
pizzaEaten = 0;
}
}
}