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

2020/3/18

Need to access attributes of superclass from subclass

GrucifyMe GrucifyMe

2020/3/18

#
So I basically have an Actor class called "Player" and its subclass called "Laser", and as the name implies, I want to add a laser at the Player's location that moves up by a certain speed each frame, but I want to access Player's attributes, specifically its X and Y location, which I am unable to do in its subclass. Here is the code in the subclass Laser currently:
addObject(laser, player.getImage().getX(), player.getImage().getY());
Thanks in advance
danpost danpost

2020/3/18

#
Laser should NOT extend Player (a laser is not a player). Your line of code should get x and y from player, not from the image of the player.
You need to login to post a reply.