This site requires JavaScript, please enable it in your browser!
Greenfoot back
KierTulp
KierTulp wrote ...

2013/1/10

spawning at location problems

KierTulp KierTulp

2013/1/10

#
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:
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()); 
    }  
}
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?
KierTulp KierTulp

2013/1/12

#
bump.
You need to login to post a reply.