So i'm trying to move a GameComponent on it's center (an interactible object in my game engine) around the screen with the mouse.
I already done a peace of code, but i'm not able to pick up the object in it's center, i can get it's x position, y position and width/height.
Here is my code that handles object movement (the render is not nessessary because the object is rendering entirely correctly) :
public void updateComponent() {
int x = Mouse.getX();
int y = SLDTGame.getScreenHeight() - Mouse.getY();
int xSlot = slotX + slotWidth;
int ySlot = slotY + slotHeight;
if (slotTaken){
slotX = x;
slotY = y;
}
if (xSlot >= SLDTGame.getScreenWidth()){
slotX = SLDTGame.getScreenWidth() - (slotWidth + 5);
Mouse.setCursorPosition(SLDTGame.getScreenWidth() - (slotWidth + 7), SLDTGame.getScreenHeight() - Mouse.getY());
slotTaken = false;
return;
}
if (ySlot >= SLDTGame.getScreenHeight()){
slotY = SLDTGame.getScreenHeight() - (slotHeight + 5);
Mouse.setCursorPosition(Mouse.getX(), SLDTGame.getScreenHeight() - (slotHeight + 7));
slotTaken = false;
return;
}
if (x <= xSlot && x >= slotX){
if (y <= ySlot && y >= slotY){
if (Mouse.isButtonDown(0)) {
slotTaken = true;
}
System.out.println("You are in the slot !");
}
}
if (!Mouse.isButtonDown(0)) {
slotTaken = false;
}
}
Yuri6037