如果我的MovementSystem
行为是这样的话。
public class MovementSystem extends IntervalIteratingSystem {
private Vector2 temp = new Vector2();
public MovementSystem() {
super(Family.all(TransformComponent.class, MovementComponent.class).get(), Constants.TIME_STEP);
}
@Override
protected void processEntity(Entity entity) {
TransformComponent transform = Mappers.transform.get(entity);
MovementComponent movement = Mappers.movement.get(entity);
Vector2 acceleration = temp.set(movement.accel).scl(0.5f);
movement.velocity.add(acceleration);
Vector2 acceleratedVelocity = temp.set(movement.velocity).scl(0.5f);
transform.position.add(acceleratedVelocity);
}
}
在我的PhysicsSystem
行为中。
public class PhysicsSystem extends IntervalIteratingSystem {
@Override
protected void processEntity(Entity entity) {
PhysicsComponent physics = Mappers.physics.get(entity);
TransformComponent transform = Mappers.transform.get(entity);
SizeComponent size = Mappers.size.get(entity);
transform.position.set(physics.body.getPositon());
transform.rotation = physics.body.getAngle();
}
}
PlayerSystem {
public void updateMovement(Entity entity) {
PlayerComponent player = Mappers.player.get(entity);
PhysicsComponent physics = Mapper.physics.get(entity);
MovementComponent movement = Mapper.movement.get(entity);
float VELOCITY = player.MOVE_VELOCITY;
switch(movement.state) {
case UP: movement.velocity.set(0, VELOCITY) break;
case DOWN: movement.velocity.set(0, -VELOCITY) break;
case LEFT: movement.velocity.set(-VELOCITY, 0) break;
case RIGHT: movement.velocity.set(VELOCITY, 0) break;
}
physics.body.setLinearVelocity(movement.velocity);
}
}
目标
PhysicsSystem
)MovementSystem
)问题
PhysicsSystem
正在覆盖或更新TransformComponent
数据MovementSystem
使用TransformComponent
速度和加速度递增MovementComponent
位置。PhysicsSystem
和MovementSystem
定位而混淆。问题
你认为我做得对吗?这只是我需要修改以适应其目标的行为吗?