Get player coordinate inside the world class


(Oli) #1

Does anybody know how to access an entity x y coordinate inside a world class.Those coordinate are changing. I want to make a light that follows the player.

the following does not work and im getting this error: col: 27 Error: Access of possibly undefined property x through a reference with static type Class.

the getInstance() method does not function either since i am allready in the world class

override public function update():void {

        playerLight.x = Player.x
        playerLight.y = Player.y;
        
        super.update();

}


(Jean) #2

Please, the code where you define and create the player (new Player())?

What you probably are making, is getting the CLASS Player and not an INSTANCE OF Player, but without more code I can’t help.


(Oli) #3

I have this in my begin() function add(Global.player);

and this in my loadMap(mapData:Class) function

// Create a player at the player start. Global.player = new Player(int(mapXML.Entities.PlayerStart.@x), int(mapXML.Entities.PlayerStart.@y));


(Martí Angelats i Ribera) #4

Why are you calling x and y from the class Player? Is that a public static property?


(Kyle) #5

If you add it by using Global.player, I suppose you can easily access the player coordinates the same way. Like

        playerLight.x = Global.player.x
        playerLight.y = Global.player.y;

(Oli) #6

I dont know how to do it i just want to acess those two propreties from my world class:(


(Oli) #7

duh thx:) Im so dumb