Sash becomes lost after resize - java

I have an application that I have created a sash for, so that users can resize the Styled Text objects as they choose. I have a bug though that if the application is maximized, the sash is moved very low on the application, and then the user un-maximizes the application, the sash is then still beyond the bounds of the screen.
How can I make it so that when the user changes the application from maximized, to a smaller size, the sash automatically moves within the bounds of the application size; as in the first picture?
Also, is there a better (more dynamic) way to control the position limits for the sash?
separator.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
double height = shlPstmKnowledgeCatalogue.getBounds().height;
double qpBtnHeight = btnQuickParts.getBounds().height;
double workLblHeight = lblWorkInstructions.getBounds().height;
if (!shlPstmKnowledgeCatalogue.getMaximized()) {
if (event.y < workLblHeight + 30) {
event.y = (int) workLblHeight + 30;
}
else if (event.y > height - qpBtnHeight - 90) {
event.y = (int) (height - qpBtnHeight - 90);
}
}
else {
if (event.y < workLblHeight + 30) {
event.y = (int) (workLblHeight + 30);
}
else if (event.y > height - qpBtnHeight - 90) {
event.y = (int) (height - qpBtnHeight - 90);
}
}
separator.setBounds(event.x, event.y, event.width, event.height);
FormData formData = new FormData();
formData.top = new FormAttachment(0, event.y);
formData.left = new FormAttachment(lblScript, 6);
formData.right = new FormAttachment(script, 0, SWT.RIGHT);
formData.height = 5;
separator.setLayoutData(formData);
/*
* Used to move the script label with the movement of the script
* text box. Otherwise, the label gets lost behind the text boxes.
*/
FormData lblScriptData = new FormData();
lblScriptData.top = new FormAttachment(0, event.y - 5);
lblScriptData.bottom = new FormAttachment(0, event.y + 12);
lblScriptData.left = new FormAttachment (workInstructions,2, SWT.LEFT);
lblScript.setLayoutData(lblScriptData);
shlPstmKnowledgeCatalogue.layout(true);
}
});
/*
* Attaches the Work Instuction text box to the sash for dynamic resizing
* The resizing is done in relation to the Script text box
*/
FormData workInstForm = new FormData();
workInstForm.left = new FormAttachment(0, 194);
workInstForm.right = new FormAttachment(100, -6);
workInstForm.bottom = new FormAttachment(separator, -15);
workInstForm.top = new FormAttachment(lblWorkInstructions, 7);
workInstructions.setLayoutData(workInstForm);
formToolkit.adapt(workInstructions, true, true);
/*
* Attaches the Script text box to the sash for dynamic resizing
* The resizing is done in relation to the work instruction text box
*/
FormData scriptForm = new FormData();
scriptForm.top = new FormAttachment(separator, 15);
scriptForm.right = new FormAttachment(workInstructions, 0, SWT.RIGHT);
scriptForm.left = new FormAttachment(workInstructions, 0, SWT.LEFT);
scriptForm.bottom = new FormAttachment(btnQuickParts, -6);
script.setLayoutData(scriptForm);
formToolkit.adapt(script, true, true);

I ended up writing a separate method to constantly check the position of the sash. Maybe it is not the most efficient way of doing it, but it does work!
/**
* Check the sash position to verify that it is within the bounds of the shell.
* This is primarily used when the user maxmimizes the application, moves the
* sash, then minimizes the application.
*/
private void checkSashPosition() {
if (!shlPstmKnowledgeCatalogue.isDisposed() && separator.getBounds().y > shlPstmKnowledgeCatalogue.getBounds().height) {
separator.setLocation(235, shlPstmKnowledgeCatalogue.getBounds().height - 248);
workInstructions.setSize(455, 100);
script.setSize(455, 130);
script.setLocation(194, 167);
lblScript.setLocation(194, 143);
}
}
The method is called inside of a while-loop, and the objects that are relative to the sash are also adjusted.

Related

JavaFX animation on canvas

I'm a newbie of Java. I tried to make a simple 'binary search tree' program. I have a problem during making so I'm looking for the answer.
When the program was looking for correct place where I added a number in, I wanted to put 'flickering' function during processing, but it works like this. enter image description here
(It's not flickering but just multiplying.)
How can I figure this problem out?
Here is 'add' method that I wrote in controller.
public void handleAddAction(ActionEvent event) {
System.out.println("add ? ?");
String key = addfield.getText();
int length = key.length();
if ( length > 0 ) {
boolean integerornot = isStringInteger(key, 10);
if ( integerornot == true ) {
int intkey = Integer.parseInt(key);
if (bst.size() > 10) {
Alert maxerror = new Alert(Alert.AlertType.WARNING);
maxerror.setTitle("Message");
maxerror.setHeaderText("The maximum number of nodes is 10.");
maxerror.showAndWait();
}else if(bst.contains(intkey)!=null) {
Alert duperror = new Alert(Alert.AlertType.WARNING);
duperror.setTitle("Message");
duperror.setHeaderText("Duplicated numbers cannot be added.");
duperror.showAndWait();
}else if (intkey>=0 && intkey <= 9) {
bst.insert(intkey);
addfield.setText("");
DoubleProperty x = new SimpleDoubleProperty();
DoubleProperty y = new SimpleDoubleProperty();
compareNode(bst.root,intkey);
gc.setStroke(Color.rgb(15, 76, 129));
gc.setFill(Color.WHITE);
gc.fillOval(width-10, height-15, 25, 25);
gc.strokeOval(width-10, height-15, 25, 25);
gc.setFill(Color.rgb(15, 76, 129));
gc.fillText(key, width, height);
if(bst.size()>1) {
gc.strokeLine(width-ratiowidth, height-50 +(25/2), width-ratiowidth, height -50 +(25/2) +10);
gc.strokeLine(width-ratiowidth, height-50 +(25/2)+10, width, height -50 +(25/2) +10);
gc.strokeLine(width, height-50 +(25/2) +10, width, height -(25/2));
gc.fillPolygon(new double [] {width-5, width, width+5}, new double[] {height -(25/2) -10, height -(25/2), height -(25/2)-10}, 3);
Timeline timeline = new Timeline(
new KeyFrame(Duration.seconds(0),
new KeyValue(x, width-ratiowidth),
new KeyValue(y, height-50)
),
new KeyFrame(Duration.millis(10),
new KeyValue(x, width),
new KeyValue(y, height)
)
);
// timeline.setCycleCount(Timeline.INDEFINITE);
AnimationTimer timer = new AnimationTimer() {
public void handle(long now) {
gc.setStroke(Color.BLUE);
gc.strokeOval(x.doubleValue(), y.doubleValue(), 30, 30);
}
} ;
timer.start();
timeline.play();
}
prekey = intkey;
height = 20;
width = 740;
ratiowidth = 740;
} else {
Alert inerror = new Alert(Alert.AlertType.WARNING);
inerror.setTitle("Message");
inerror.setHeaderText("Only numbers from 0 to 9 can be added.");
inerror.showAndWait();
}
}else {
Alert string = new Alert(Alert.AlertType.WARNING);
string.setTitle("Message");
string.setHeaderText("Please insert integer.");
string.showAndWait();
}
}else {
Alert noinput = new Alert(Alert.AlertType.WARNING);
noinput.setTitle("Message");
noinput.setHeaderText("You did not input anything! Please insert value.");
noinput.showAndWait();
}
addfield.setText("");
}
Thank you in advance :)

JavaFX z-buffer issues

I'm filling a container with a lot of small boxes and the problem is that you can see trough them from some angles. I've already enabled the depth buffer, but that doesn't work.
The code that handles this part is split into 3. setupUIPreElements sets everything up, setupUIElements adds the boxes and setupUIPostElements adds the container and some camera stuff.
public static void setupUIPreElements(Stage stage){
//Setup grids, groups, scenes, camera and such so that the scene is made from scratch
topGrid = new GridPane();
twoDGroup = new Group();
threeDGroup = new SmartGroup();
root = new HBox();
mainScene = new Scene(root, SCREEN_WIDTH, SCREEN_HEIGHT, true, SceneAntialiasing.BALANCED);
twoD = new SubScene(twoDGroup, SCREEN_WIDTH*.2, SCREEN_HEIGHT);
threeD = new SubScene(threeDGroup, SCREEN_WIDTH*.8, SCREEN_HEIGHT);
anchorAngleX = 0;
anchorAngleY = 0;
angleX = new SimpleDoubleProperty(0);
angleY = new SimpleDoubleProperty(0);
camera = new PerspectiveCamera();
pins = new ProgressIndicator[1];
pin = pins[0] = new ProgressIndicator();
parcels = new ArrayList<UIParcel>();
//add subscenes to scene
root.getChildren().addAll(twoD, threeD);
root.setSpacing(10);
root.setPadding(new Insets(20, 20, 20, 20));
/*START Setup top menu*/
//Setup grid
topGrid.setHgap(10);
topGrid.setVgap(10);
//Setup items
//Add scoring label
scoringLabel = new Label("Score: " + Wrapper.score);
startButton = new Button("Start");
modeSelection = new ChoiceBox(FXCollections.observableArrayList(
"Parcels", "Pentominoes"
));
modeSelection.setValue("");
//Parcel selection UI
ParcelAAmountLabel = new Label("Amount of parcel A: ");
ParcelBAmountLabel = new Label("Amount of parcel B: ");
ParcelCAmountLabel = new Label("Amount of parcel C: ");
ParcelAAmountTextField = new TextField();
ParcelBAmountTextField = new TextField();
ParcelCAmountTextField = new TextField();
ParcelAValueLabel = new Label("Value of parcel A: ");
ParcelBValueLabel = new Label("Value of parcel B: ");
ParcelCValueLabel = new Label("Value of parcel C: ");
ParcelAValueTextField = new TextField();
ParcelBValueTextField = new TextField();
ParcelCValueTextField = new TextField();
//Pentominoe selection UI
LPentominoAmountLabel = new Label("Amount of L pentominoes: ");
PPentominoAmountLabel = new Label("Amount of P pentominoes: ");
TPentominoAmountLabel = new Label("Amount of T pentominoes: ");
LPentominoAmountTextField = new TextField();
PPentominoAmountTextField = new TextField();
TPentominoAmountTextField = new TextField();
LPentominoValueLabel = new Label("Value of L pentominoes: ");
PPentominoValueLabel = new Label("Value of P pentominoes: ");
TPentominoValueLabel = new Label("Value of T pentominoes: ");
LPentominoValueTextField = new TextField();
PPentominoValueTextField = new TextField();
TPentominoValueTextField = new TextField();
//-1 will make it display an animated disk, set to 1 to show that it's done
//pin is the progress indicator
pin.setProgress(-1);
topGrid.add(scoringLabel, 0, 0);
topGrid.add(modeSelection, 0, 1);
topGrid.add(startButton, 0, 8);
twoDGroup.getChildren().add(topGrid);
/*END*/
//Set materials
container_material.setDiffuseColor(CONTAINER_COLOR);
edge_material.setDiffuseColor(EDGE_COLOR);
}
public static void setupUIElements(Stage stage, int[][][] resultBoxesArray){
//TODO check if I can assume the IDs to be either 1, 2 or 3 if filled in or 0 if not
int colorStart = 0;
int colorEnd = 0;
//give every filled in field a box representation and keep color in mind
//create all the boxes
for(int x=0; x<resultBoxesArray.length; x++){
for(int y=0; y<resultBoxesArray[x].length; y++){
for(int z=0; z<resultBoxesArray[x][y].length; z++){
int currentValue = resultBoxesArray[x][y][z];
//if this field is filled
if(currentValue!=0){
//update color range
if(currentValue==1){
colorStart = 0;
colorEnd = 70;
} else if (currentValue==2){
colorStart = 85;
colorEnd = 155;
} else {
colorStart = 170;
colorEnd = 255;
}
//50 is used because that is the size that is given for each cell in the array
UIParcel cellBox = new UIParcel(x*50, y*50, z*50, 50, 50, 50, colorStart, colorEnd);
parcels.add(cellBox);
}
}
}
}
//show them
threeDGroup.getChildren().addAll(parcels);
}
public static void setupUIPostElements(Stage stage){
//Create container (note: Has to be created after adding all the other objects in order to use transparency (I know, javaFX can be crappy))
Box container = new Box(Wrapper.CONTAINER_WIDTH, Wrapper.CONTAINER_HEIGHT, Wrapper.CONTAINER_DEPTH);
container.setTranslateX(Wrapper.CONTAINER_WIDTH/2);
container.setTranslateY(Wrapper.CONTAINER_HEIGHT/2);
container.setTranslateZ(Wrapper.CONTAINER_DEPTH/2);
container.setMaterial(container_material);
threeDGroup.getChildren().add(container);
//Setup camera (so that you can have the container at the origin and can still see it well
//The +threeDOffsetLeft comes from the compensation for the 2D subscene on the left
camera.setTranslateX(-SCREEN_WIDTH/2+Wrapper.CONTAINER_WIDTH/2+threeDOffsetLeft);
camera.setTranslateY(-SCREEN_HEIGHT/2+Wrapper.CONTAINER_HEIGHT/2);
camera.setTranslateZ(-Wrapper.CONTAINER_DEPTH/0.5);
//Setup mouse rotation
initMouseControl(threeDGroup, mainScene, stage);
//Set eventListener for mode selection
modeSelection.getSelectionModel().selectedItemProperty().addListener((v, oldValue, newValue) -> {
//check what mode was selected and show the corresponding options
if(newValue.equals("Parcels")){
//remove other option
if(oldValue.equals("Pentominoes")){
topGrid.getChildren().removeAll(LPentominoAmountLabel, PPentominoAmountLabel, TPentominoAmountLabel, LPentominoAmountTextField, PPentominoAmountTextField, TPentominoAmountTextField, LPentominoValueLabel, PPentominoValueLabel, TPentominoValueLabel, LPentominoValueTextField, PPentominoValueTextField, TPentominoValueTextField);
}
//add labels
topGrid.add(ParcelAAmountLabel, 0, 2);
topGrid.add(ParcelBAmountLabel, 0, 4);
topGrid.add(ParcelCAmountLabel, 0, 6);
topGrid.add(ParcelAValueLabel, 0, 3);
topGrid.add(ParcelBValueLabel, 0, 5);
topGrid.add(ParcelCValueLabel, 0, 7);
//add text fields
topGrid.add(ParcelAAmountTextField, 1, 2);
topGrid.add(ParcelBAmountTextField, 1, 4);
topGrid.add(ParcelCAmountTextField, 1, 6);
topGrid.add(ParcelAValueTextField, 1, 3);
topGrid.add(ParcelBValueTextField, 1, 5);
topGrid.add(ParcelCValueTextField, 1, 7);
} else if (newValue.equals("Pentominoes")){
//remove other option
if(oldValue.equals("Parcels")){
topGrid.getChildren().removeAll(ParcelAAmountLabel, ParcelBAmountLabel, ParcelCAmountLabel, ParcelAAmountTextField, ParcelBAmountTextField, ParcelCAmountTextField, ParcelAValueLabel, ParcelBValueLabel, ParcelCValueLabel, ParcelAValueTextField, ParcelBValueTextField, ParcelCValueTextField);
}
//add labels
topGrid.add(LPentominoAmountLabel, 0, 2);
topGrid.add(PPentominoAmountLabel, 0, 4);
topGrid.add(TPentominoAmountLabel, 0, 6);
topGrid.add(LPentominoValueLabel, 0, 3);
topGrid.add(PPentominoValueLabel, 0, 5);
topGrid.add(TPentominoValueLabel, 0, 7);
//add text fields
topGrid.add(LPentominoAmountTextField, 1, 2);
topGrid.add(PPentominoAmountTextField, 1, 4);
topGrid.add(TPentominoAmountTextField, 1, 6);
topGrid.add(LPentominoValueTextField, 1, 3);
topGrid.add(PPentominoValueTextField, 1, 5);
topGrid.add(TPentominoValueTextField, 1, 7);
}
});
//Set evenListener for start button
startButton.addEventHandler(MouseEvent.MOUSE_CLICKED, event-> {
//Show loading circle (that was created at the start)
topGrid.add(pin, 0, 9);
//TODO use values from the textFields as input
//TODO start calculations
//TODO remove after testing
test.giveInput();
});
threeD.setCamera(camera);
stage.setTitle("Filling 3D objects");
threeD.setFill(BACKGROUND_COLOR);
stage.setScene(mainScene);
stage.show();
}
From the angle that works as desired is looks like this:
From the angle that doesn't work properly it looks like this:
Note that the boxes are added as UIParcel, this is just a class that extends the regular Box with some extra info, it doesn't effect any 3D stuff.
The solution was to also enable depth buffering for the SubScene that contained the 3D elements, it doesn't just follow the settings from the mainScene.
threeD = new SubScene(threeDGroup, SCREEN_WIDTH*.8, SCREEN_HEIGHT);
becomes
threeD = new SubScene(threeDGroup, SCREEN_WIDTH*.8, SCREEN_HEIGHT, true, SceneAntialiasing.BALANCED);
Setting the SceneAntialiasing is also required by the SubScene constructor.

how to fix custom timeline problem JavaFx?

I have seen this timeline build here then I have tried to make I timeline using hbox and sperators and labels, but I fall in a representation errors
the following controller allows me to build this timeline this above nodes
public class GuiMainController implements Initializable {
#FXML
private BorderPane borderPane;
public void getUnit1(){
//This will fill the Time Line Unit in your Gui
VBox vbox = new VBox();
HBox hbox = new HBox();
hbox.setManaged(false);
for (int i =0; i < 24; i++) {
//For each unit create a new instance
AnchorPane anchorPane = new AnchorPane();
anchorPane.setPrefHeight(30);
anchorPane.setPrefWidth(66);
Separator separatorR = new Separator();
separatorR.setLayoutX(66);
separatorR.setLayoutY(14);
separatorR.setOrientation(Orientation.VERTICAL);
separatorR.setPrefHeight(15);
Separator separatorM = new Separator();
separatorM.setLayoutY(14);
separatorM.setOrientation(Orientation.VERTICAL);
separatorM.setPrefHeight(15);
Separator separatorL = new Separator();
separatorL.setLayoutX(33);
separatorL.setLayoutY(20);
separatorL.setOrientation(Orientation.VERTICAL);
separatorL.setPrefHeight(10);
separatorL.setPrefWidth(6);
Label lblT = new Label();
lblT.setText(i+"h");
Label lblTT = new Label();
lblTT.setLayoutX(66);
lblTT.setText((i+1)+"h");
anchorPane.getChildren().addAll(separatorL,lblT,separatorM,separatorR,lblTT);
hbox.getChildren().add(anchorPane);
}
borderPane.getChildren().add(hbox);
}
public void initialize(URL arg0, ResourceBundle arg1) {
getUnit1();
}
}
How can I made this timeline, any help are appreciated to get some like this
Imho you shouldn't get any layouts involved here, since this way you rely on the exact implementation of those layouts. Furthermore I'm not sure Seperator should be involved here. You could use a Path though and calculate the positions of all the lines on the axis.
private static Label createLabel(String text, double layoutY, double majorTickDistance, int index) {
Label label = new Label(text);
// label width should be exactly the distance between ticks
label.setMaxWidth(Region.USE_PREF_SIZE);
label.setMinWidth(Region.USE_PREF_SIZE);
label.setPrefWidth(majorTickDistance);
// center text
label.setAlignment(Pos.BASELINE_CENTER);
label.setLayoutY(layoutY);
// align center of the label with major tick
label.setLayoutX((index + 0.5) * majorTickDistance);
return label;
}
/**
* #param majorTickDistance the width between major ticks
* #param minorTicks the number of minor ticks between major ticks
* #param majorTickHeight the height of major tick markers
* #param minorTickHeight the height of minor tick markers
* #param firstText the first text for the first major tick
* #param text the text for other ticks
*/
private static Pane createAxis(double majorTickDistance, int minorTicks,
double majorTickHeight, double minorTickHeight, String firstText, String... text) {
final double labelY = majorTickHeight + 3;
final double minorTickDistance = majorTickDistance / minorTicks;
// initialize path with first major tick and horizontal line
Path path = new Path(
new MoveTo(0, 0), new HLineTo(majorTickDistance * text.length),
new MoveTo(0, 0), new VLineTo(majorTickHeight)
);
// add path and first label
Pane pane = new Pane(path, createLabel(firstText, labelY, majorTickDistance, -1));
for (int i = 0; i < text.length; i++) {
double offset = i * majorTickDistance;
// add minor ticks
for (int j = 1; j < minorTicks; j++) {
double x = offset + j * minorTickDistance;
path.getElements().addAll(new MoveTo(x, 0), new VLineTo(minorTickHeight));
}
offset += majorTickDistance;
// add major tick at the end of the current interval
path.getElements().addAll(new MoveTo(offset, 0), new VLineTo(majorTickHeight));
// add label below major tick
pane.getChildren().add(createLabel(text[i], labelY, majorTickDistance, i));
}
pane.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
return pane;
}
#Override
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(new StackPane(createAxis(30, 5, 10, 5, "1", "2", "3", "4", "5", "6")), 400, 400);
primaryStage.setScene(scene);
primaryStage.show();
}

Java SWT: Displaying a Grid over an image

I need to do the following using Java SWT:
Display a list of Pixels as an Image
Allow the user to select a subset of Pixels
Display a Grid over the image as a guide for the user. The Image still needs to handle mouse events
1) and 2) are straightforward, however I don't know how to achieve 3).
Reading up on SWT, I do not see a way to put a Transparent Overlay over an image. Is this possible? Is there another method?
Just draw the grid on top of the Image. Set GG#setAlpha(int) to a low value to make the lines transparent. This will not interfere with mouse events:
public static void main(String[] args)
{
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Stackoverflow");
shell.setLayout(new FillLayout());
Image image = new Image(display, "baz.png");
Label label = new Label(shell, SWT.NONE);
label.addListener(SWT.Paint, new Listener()
{
#Override
public void handleEvent(Event event)
{
GC gc = event.gc;
gc.drawImage(image, 0, 0);
gc.setAlpha(30);
int interval = image.getBounds().height;
for (int i = 0; i < 10; i++)
{
int y = (int) Math.floor(i * (interval / 10.0));
gc.drawLine(0, y, image.getBounds().width, y);
}
interval = image.getBounds().width;
for (int i = 0; i < 10; i++)
{
int x = (int) Math.floor(i * (interval / 10.0));
gc.drawLine(x, 0, x, image.getBounds().width);
}
gc.setAlpha(255);
}
});
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
image.dispose();
}
Looks like this:

Centering map or camera 2D game

I've tried so many solutions that it's possible that my code is a bit mixed up, but whatever I try, it just won't work.
Basically I made a map with Tiled, where my player can run around and bump into stuff. I want the whole map to be visible for the whole time (it's 20 by 15, 64 pixels a tile). The camera doesn't need to move around or follow the player, it has to stay still at the center of the map.
The problem is that the map only shows in the upper right corner of the screen. When I centered the camera to the map itself it messed up the collission detection, (bumping into trees while they were not visible & walking through visible trees). So what I want to do is center the map to 0,0 where my camera also is (at least I think..).
Another thing I'd like to accomplish is that the size of the map gets resized to match different mobile phones. Tried to accomplish this with the stretchviewport, but haven't been able to test this.
public class PlayScreen implements Screen {
TiledMap map;
OrthogonalTiledMapRenderer mapRenderer;
OrthographicCamera cam;
float unitScale = 1 / 64f;
OrthogonalTiledMapRenderer renderer = new OrthogonalTiledMapRenderer(map, unitScale);
Viewport viewport;
public void show() {
map = new TmxMapLoader().load("maps/map.tmx");
mapRenderer = new OrthogonalTiledMapRenderer(map);
cam = new OrthographicCamera(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
cam.setToOrtho(false);
viewport = new StretchViewport(1280, 960, cam);
bounds = new ArrayList<Rectangle>();
for(int i = 0; i < 20; i++){
for(int j = 0; j < 15; j++){
TiledMapTileLayer cur = (TiledMapTileLayer) map.getLayers().get(1);
Cell cell = new Cell();
Vector3 center = new Vector3(cur.getWidth() * cur.getTileWidth() / 2, cur.getHeight() * cur.getTileHeight() / 2, 0);
cam.position.set(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2, 0);
cam.update();
if(cur.getCell(i,j) != null){ //null = first layer != --> if its not
cell = cur.getCell(i, j);
System.out.println(i + ", " + j + ", " + cell.getTile().getId());
bounds.add(new Rectangle(i * 64, j * 64, 64 , 64));
}
}
}
public void render(float delta) {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
mapRenderer.setView(cam);
mapRenderer.render();
cam.position.set(0, 0, 0);
cam.update();
batch.setProjectionMatrix(cam.combined);
batch.begin();
batch.draw(player.getCurrentFrame(), player.getPosition().x , player.getPosition().y);
player.update();
for(int i = 0; i < bounds.size(); i++){
if(bounds.get(i).overlaps(player.getBounds())){
int x = (int)bounds.get(i).x / 64;
int y = (int)bounds.get(i).y / 64;
TiledMapTileLayer cur = (TiledMapTileLayer)map.getLayers().get(1);
Cell cell = cur.getCell(x, y);
if(cell.getTile().getProperties().containsKey("blocked")){
System.out.println("bush");
}
player.reAdjust();
}
}
batch.end();
}
public void resize(int width, int height) {
viewport.update(width, height);
}
Nevermind, I deleted: cam.position.set(0, 0, 0); and everything seems to work just fine. Guess I already made some changes what caused it to work, just didn't see it cause this was still around.

Categories