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

2018/3/8

How to get an actor location?

Kestroz Kestroz

2018/3/8

#
Hi I'm trying to get a game where I have an actor holding a sword, which is another actor. Im making it so I set the sword's location to the character actor's location. When I run my code an error appears saying non-static variable xloc cannot be referenced from a static context. Character's Actor: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Character1 here. * * @author (your name) * @version (a version number or a date) */ public class Character1 extends Actor { public int xloc = getX(); public int yloc = getY(); Sword Actor Code: public class Sword extends Actor { public int xlocation = Character1.xloc; public int ylocation = Character1.yloc;
danpost danpost

2018/3/8

#
Unless it is a magical sword, it should not follow the actor holding it. The actor should control the orientation/location of the sword.
You need to login to post a reply.