hello.
I have made a button which turns on a magnet, which should then spawn a beam under the magnet pulling the player up. the problem is that the beam is not getting spawned under the magnet, but on the beam. here is the code I am using:
as you see I am using getX() and getY() in the magnet class, but he is getting the x and y of the knop class. do you know a way of fixing this?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Knop extends Magnet
{
public boolean knopAan;
public int counter = 0;
public void act()
{
move(7);
spawn();
}
public boolean isUmanNear()
{
if(!getObjectsInRange(40, Uman.class).isEmpty())
{
return true;
}
else {
return false;
}
}
public void isXPressed()
{
if(isUmanNear())
{
if(Greenfoot.isKeyDown("x"))
{
setImage("knop2.png");
knopAan = true;
}
else
knopAan = false;
}
}
public void spawn()
{
{
if(Greenfoot.isKeyDown("x"))
{
counter++;
}
if(counter == 1 && isUmanNear())
{
ding();
}
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Magnet extends Scroll
{
public void act()
{
move(7);
}
public void ding()
{
on();
}
public void on()
{
GravityUp GravityUp = new GravityUp();
getWorld().addObject(GravityUp, getX() ,getY());
}
}

