mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Korrigerer feil konvertering av koordinater i CardChoiceScreen
This commit is contained in:
parent
7f370a9dbc
commit
fbd7bef642
@ -6,6 +6,9 @@ import com.badlogic.gdx.Screen;
|
|||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||||
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
import com.badlogic.gdx.utils.viewport.FitViewport;
|
||||||
|
import com.badlogic.gdx.utils.viewport.Viewport;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
@ -18,14 +21,18 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
|
|||||||
private final OrthographicCamera camera;
|
private final OrthographicCamera camera;
|
||||||
private final CardRectangle cardRectangle;
|
private final CardRectangle cardRectangle;
|
||||||
private final ShapeRenderer shapeRenderer;
|
private final ShapeRenderer shapeRenderer;
|
||||||
|
private final Viewport viewport;
|
||||||
|
|
||||||
public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper) {
|
public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||||
this.roboRallyWrapper = roboRallyWrapper;
|
this.roboRallyWrapper = roboRallyWrapper;
|
||||||
camera = new OrthographicCamera();
|
camera = new OrthographicCamera();
|
||||||
camera.setToOrtho(true, 1200, 1200);
|
int applicationWidth = 600;
|
||||||
|
int applicationHeight = 800;
|
||||||
|
camera.setToOrtho(true, applicationWidth, applicationHeight);
|
||||||
|
viewport = new FitViewport(applicationWidth, applicationHeight, camera);
|
||||||
Rectangle card1 = new Rectangle();
|
Rectangle card1 = new Rectangle();
|
||||||
card1.x = 1200/2;
|
card1.x = 10;
|
||||||
card1.y = 1200/2;
|
card1.y = 10;
|
||||||
card1.width = 100;
|
card1.width = 100;
|
||||||
card1.height = 100;
|
card1.height = 100;
|
||||||
cardRectangle = new CardRectangle(card1);
|
cardRectangle = new CardRectangle(card1);
|
||||||
@ -60,8 +67,8 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resize(int i, int i1) {
|
public void resize(int width, int height) {
|
||||||
//Nothing to do
|
viewport.update(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -86,12 +93,9 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
||||||
System.out.println(screenX + " " + screenY);
|
Vector3 transformed = viewport.unproject(new Vector3(screenX, screenY, 0));
|
||||||
System.out.println(cardRectangle.rectangle.x + " " + cardRectangle.rectangle.y + " " +
|
if (cardRectangle.rectangle.contains(transformed.x, transformed.y)) {
|
||||||
cardRectangle.rectangle.width + " " + cardRectangle.rectangle.height);
|
cardRectangle.selected = !cardRectangle.selected;
|
||||||
if (cardRectangle.rectangle.contains(screenX, screenY)) {
|
|
||||||
cardRectangle.selected = true;
|
|
||||||
System.out.println("Card touched");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user