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

2021/9/21

Help getX(), getY() From Different Actor

Monk_08 Monk_08

2021/9/21

#
public void tp()
    {
        if ((isTouching(Teleport.class )))
        {
                 
            //I got to randomly placed Teleports and i want to get the x, y values of them   
         
            //somthing like setLocation(Teleport1X, Teleport1Y); 
            
               
        }
    }

    public void tp1()
    {
        if ((isTouching(Teleport1.class )))
        {
        
            //somthing like setLocation(TeleportX, TeleportY); 

         
        }
    }
Thanks For The Help
danpost danpost

2021/9/21

#
After isTouching is found to be true, continue with:
Teleport teleport = (Teleport)getOneIntersectingObject(Teleport.class);
int teleportX = teleport.getX();
int teleportY = teleport.getY();
Similar for Teleport1 object.
Monk_08 Monk_08

2021/9/24

#
Sorry for the late answer I'm struggling with implementing it sorry I'm very new to java/greenfoot and why did u use the getOneIntersectingObject and what is it supposed to do
danpost danpost

2021/9/24

#
Monk_08 wrote...
Sorry for the late answer I'm struggling with implementing it sorry I'm very new to java/greenfoot and why did u use the getOneIntersectingObject and what is it supposed to do
Documentation is here. You need a reference to the actor it is touching before you can acquire its position using getX and getY.
Monk_08 Monk_08

2021/9/24

#
That makes sense Thank You :)
You need to login to post a reply.