-
Notifications
You must be signed in to change notification settings - Fork 0
Entity class
This class is the ground structure for creating an entity/object for a scene. Another class has to extend it.
//implementation of the entity class.
pulbic class Player extends Entity {
@Override
public void init() {
}
@Override
public void logicLoop() {
}
@Override
public void renderLoop() {
}
}
Every class that extends this will be called entity
in this documentation.
One of the most important use cases is creating an entity, that can be added to a scene.
The Player
class from above could be added to a scene like in the following example:
//The scene class
public class GameScene extends Scene {
@Override
public void init() {
//initialisation of the player class.
Player player = new Player();
//assignment of the player entity to the scene.
addObject(player);
}
@Override
public void logicLoop() {
}
@Override
public void renderLoop() {
}
}
This method is executed once, when the entity is initialized.
This method gets executed 60 times per second (if you didn't change it with Game.setFrameRate()
). It is most commonly used for the logic of the entity.
This method gets executed 60 times per second (if you didn't change it with Game.setFrameRate()
). It is most commonly used for the graphics and design of the entity.
Every entity can store other entities. If you want to learn more about the commands used for these actions, click here
Every entity has an x
and y
position, a width
and a height
, a rotation
and a rotationPos
. None of these variables have to assigned in the constructor. If you dont set them, they will be 0
or null
. All of these variables are public, so they can be changed directly.
These variables set the position of your entity in the scene.
These variables set the dimensions of your entity.
This is the rotation of the entity in radiants. The engine will automaticly rotate all graphics in the renderLoop to fit the set rotation.
This variable is the point, where the the graphics should be rotated around.
This method is used to rotate the object, so it faces the given Point p.
This method moves the entity to the given point in the set speed. (I recommend using values over 3 because with lower values, the result would be greatly impacted)
This method is used to move the entity.
This method anchores the x
and y
coordinates to the position of the camera. While this is set to true, you wont be able to modify these values.
If you want to offset the position of the entity, use the setAnchorX(int offsetX)
and the setAnchorY(int offsetY)
or the
setAnchor(int offsetX, int offsetY)
method.