Hello,
im failry new to java and greenfoot and want to know move an Object.
I have one Worldclass: Level1 and 2 Actor subclasses: Hero and Ground.
This is my code:
World:
Hero:
You see my comments? At this place i want to change the x position of the object mainground which was created at the beginning in the Lelvel1 worldclass.
thanks in advance
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Level1 extends World
{
public Actor player = new Hero();
public Actor mainground = new Ground();
public Level1()
{
super(600, 400, 1);
addObject (player, 60, 336);
addObject(mainground, 300, 400);
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Hero extends Actor
{
public void act()
{
if (Greenfoot.isKeyDown("left")) {
move(-5);
int playerx= getX();
if (playerx<=100)
{
//HOW TO MOVE THE OBJECT MAINGROUND FROM HERE?
}
}else if (Greenfoot.isKeyDown("right")) {
move(5);
int playerx= getX();
if(playerx>=500){
//HOW TO MOVE THE OBJECT MAINGROUND FROM HERE?
}
}
}
}
