Class Drawable
java.lang.Object
fr.paris.saclay.sidescroller.drawables.Drawable
- Direct Known Subclasses:
Background
,Entity
,Terrain
Basic template for each object drawn on the screen excluding player UI.
-
Field Summary
FieldsModifier and TypeFieldDescriptionDrawable's facing directionprotected final GamePanel
GamePanel reference.int
Drawable's movement speedint
Drawable's position on the X axis (relative to window)int
Drawable's position on the Y axis (relative to window) -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract void
draw
(Graphics2D graphics2D) Each Drawable object must implement a method to be rendered inside the JFrame.int
Gets x position.abstract void
update()
This method is called by the GamePanel every time a new frame has to be generated.void
updatePositionToCamera
(int deltaX) Updates camera position by setting it equal to the distance travelled by the player.
-
Field Details
-
gamePanel
GamePanel reference. -
xPosition
public int xPositionDrawable's position on the X axis (relative to window) -
yPosition
public int yPositionDrawable's position on the Y axis (relative to window) -
speed
public int speedDrawable's movement speed -
direction
Drawable's facing direction
-
-
Constructor Details
-
Drawable
Creates a Drawable instance and saves GamePanel reference.- Parameters:
gamePanel
- reference.
-
-
Method Details
-
updatePositionToCamera
public void updatePositionToCamera(int deltaX) Updates camera position by setting it equal to the distance travelled by the player.- Parameters:
deltaX
- distance travelled.
-
update
public abstract void update()This method is called by the GamePanel every time a new frame has to be generated. Each Drawable object is responsible for calculating its position, state and aspect (such as sprite animations) for every new frame. -
draw
Each Drawable object must implement a method to be rendered inside the JFrame.- Parameters:
graphics2D
- the rendering environment.
-
getXPosition
public int getXPosition()Gets x position.- Returns:
- the x position
-