new control added WaterMovementControl
tell me what you think. In the original game the swamp water’s texture scrolls constantly away from the drainage pipe this control is designed to do just that.
public class WaterMovementControl extends AbstractControl {
private float offsetX;
private float offsetY;
public class WaterMovement() {
offsetX = offsetY = 0;
}
@Override
public void setSpatial(Spatial spatial) {
resetTexCoords();
super.setSpatial(spatial);
}
@Override
public void controlUpdate(float tpf)
if(spatial != null) {
float moveX = (offsetX >= 1) ? -offsetX : tpf;
float moveY = (offsetY >= 1) ? -offsetY : tpf;
offsetX += moveX;
offsetY += moveY;
spatialUpdate(spatial, moveX, moveY);
}
}
@Override
public void controlRender(RenderManager renderManager, ViewPort viewPort) {
}
public void spatialUpdate(Spatial spatial, float moveX, float moveY) {
if(spatial instanceof Node, tpf) {
nodeUpdate(spatial, moveX, moveY);
} else if(spatial instanceof Geometry) {
geometryUpdate(spatial, moveX, moveY);
}
}
public void nodeUpdate(Node node, float moveX, float moveY) {
List<Spatial> children = node.getChildren();
for(Spatial child : children) {
spatialUpdate(child, moveX, moveY);
}
}
public void geometryUpdate(Geometry geometry, float moveX, float moveY) {
Mesh mesh = geometry.getMesh();
VertexBuffer texCoordBuffer = mesh.getBuffer(VertexBuffer.Type.TexCoord);
FloatBuffer texCoordDataBuffer = (FloatBuffer) texCoordBuffer.getData();
while(texCoordDataBuffer.hasRemaining()) {
int position = texCoordDataBuffer.position();
float value = texCoordDataBuffer.get();
if((position & 1) == 0) {
texCoordDataBuffer.set(position, value + moveX);
} else {
texCoordDataBuffer.set(position, value + moveY);
}
}
}
private void resetTexCoords() {
if(this.spatial != null) {
spatialUpdate(spatial, -offsetX, -offsetY);
}
offsetX = offsetY = 0;
}
}
I will add moveSpeedX
and moveSpeedY
later time witch will be multiplied by tpf
at update time and set to the moveX
and moveY
variables accordingly.