I'm making a GUI for the game (Open Gl). That is, I have a Gui Screen on which other components are added. So I wanted to make all other GUIs move to the left relative to the original position of GuiScreen. It works but not as I wanted simply contrary to logic.
Here i have this situation (this code runs in onUpdate(), just do every frame):
private void moveRelativeContent(Gui guiContent)
{
guiContent.position.x = guiContent.startPosition.x + this.position.x();
guiContent.position.y = guiContent.startPosition.y + this.position.y();
}
As you can see I'm just using assignment. That is, I assign the content position from the List<Gui>
to the sum of the original content position plus the current GuiScreen position. That is guiContent.position
needs each frame always be guiContent.startPosition + this.position;
. It's logical. But for me it's work very strange. I have every frame guiContent.position
increases. It's like he's using the +=
command instead of the =
command.
Values before method:
Before: ScreenPosX: 0.02
Before: Current Gui PosX: 0.0039999485
Before: Current Gui Start PosX: 0.0039999485
Values after method:
After: ScreenPos: 0.02
After: Current Gui PosX: 0.023999948
After: Current Gui Start PosX: 0.023999948
First look in my initialized GameObject
code (include Gui
s):
public GameObject(float posX, float posY, float posZ,
float rotX, float rotY, float rotZ,
float scaleX, float scaleY, float scaleZ)
{
this();
...
this.startPosition = new Vector3f(posX, posY, posZ);
this.startRotation = new Vector3f(rotX, rotY, rotZ);
this.startScale = new Vector3f(scaleX, scaleY, scaleZ);
this.position = this.startPosition;
this.rotation = this.startRotation;
this.scale = this.startScale;
...
}
Here another version's of this constructor:
public GameObject(Vector3f position, Vector3f rotation, Vector3f scale)
{
this(position.x(), position.y(), position.z(),
rotation.x(), rotation.y(), rotation.z(),
scale.x() , scale.y() , scale.z() );
}
public GameObject(Vector2f position, Vector2f rotation, Vector2f scale)
{
this(position.x(), position.y(),
rotation.x(), rotation.y(),
scale.x() , scale.y() );
}
Next where started updated GuiScreen
. This code, from my Scene
and WorldScene.class
in main onUpdate()
:
@Override
public abstract void onUpdate(); // in Scene
@Override
public void onUpdate() // in WorldScene
{
if(!this.isInGamePause)
{
... this some in-game code
this.client.selectedGuiScreen.close(); // close once
}
else if(this.isInGamePause)
{
...
this.client.selectedGuiScreen.open(); // open once
this.client.selectedGuiScreen.onUpdate();
}
...
this.updateFrameTime();
this.client.getGameWindow().updateViewport();
this.client.getGameWindow().updateWindow();
...
}
Next step its my GuiScreen.class
``onUpdate()``` method:
public GameObject onUpdate()
{
for(Gui guiContent : this.allContent)
{
guiContent.onUpdate();
if(guiContent.getId() == 0)
{
SimplePrint.message("Before: ScreenPosX: " + this.position.x);
SimplePrint.message("Before: Current Gui PosX: " + guiContent.position.x);
SimplePrint.message("Before: Current Gui Start PosX: " + guiContent.startPosition.x);
}
this.moveRelaviteContent(guiContent);
if(guiContent.getId() == 0)
{
SimplePrint.message("After: ScreenPos: " + this.position.x);
SimplePrint.message("After: Current Gui PosX: " + guiContent.position.x);
SimplePrint.message("After: Current Gui Start PosX: " + guiContent.startPosition.x);
}
System.exit(0);
}
return this;
}
And finally if who interested my guiContent.onUpdate()
:
@Override
public GameObject onUpdate()
{
if(this.scale.x() <= 0) this.scale.x = 0.2f;
if(this.scale.y() <= 0) this.scale.y = 0.2f;
if(this.scale.x() >= 2) this.scale.x = 2f;
if(this.scale.y() >= 2) this.scale.y = 2f;
//this.rotateGui();
return super.onUpdate();
}
Ps: Immediately say that mistakes in other methods I have no. I just double-checked 100 times.
And most interesting the that I in test project tested and guiContent.position = guiContent.startPosition + this.position;
worked as I intended. Please help and the I already 3 day not can understand in than the problem.