Correct position on draging pieces
This commit is contained in:
		@ -9,6 +9,8 @@ import java.io.FileNotFoundException;
 | 
				
			|||||||
public class GameUI extends Group{
 | 
					public class GameUI extends Group{
 | 
				
			||||||
    public final static int SEGMENT_SIZE = 50;
 | 
					    public final static int SEGMENT_SIZE = 50;
 | 
				
			||||||
    public final static int SPACE_SIZE = 5;
 | 
					    public final static int SPACE_SIZE = 5;
 | 
				
			||||||
 | 
					    private final Vec2 piece_pos_click = new Vec2();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public GameUI(Map level) throws FileNotFoundException {
 | 
					    public GameUI(Map level) throws FileNotFoundException {
 | 
				
			||||||
        super();
 | 
					        super();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -22,16 +24,23 @@ public class GameUI extends Group{
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        for (Piece p : level.getPieces()) {
 | 
					        for (Piece p : level.getPieces()) {
 | 
				
			||||||
            MatrixShape _piece = new MatrixShape(p);
 | 
					            MatrixShape _piece = new MatrixShape(p);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Pieces Events
 | 
				
			||||||
            _piece.setOnMouseClicked(event -> {
 | 
					            _piece.setOnMouseClicked(event -> {
 | 
				
			||||||
                if(event.getButton() == MouseButton.SECONDARY){
 | 
					                if(event.getButton() == MouseButton.SECONDARY){
 | 
				
			||||||
                    ((Piece) _piece.shape).RotateRight(1);
 | 
					                    ((Piece) _piece.shape).RotateRight(1);
 | 
				
			||||||
                    _piece.update();
 | 
					                    _piece.update();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
            _piece.setOnMouseDragged(event -> {
 | 
					            _piece.setOnMousePressed(event -> {
 | 
				
			||||||
                _piece.setLayoutX(event.getSceneX());
 | 
					                piece_pos_click.x = (int) event.getX();
 | 
				
			||||||
                _piece.setLayoutY(event.getSceneY());
 | 
					                piece_pos_click.y = (int) event.getY();
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					            _piece.setOnMouseDragged(event -> {
 | 
				
			||||||
 | 
					                _piece.setLayoutX(event.getSceneX() - piece_pos_click.x);
 | 
				
			||||||
 | 
					                _piece.setLayoutY(event.getSceneY() - piece_pos_click.y);
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            getChildren().add(_piece);
 | 
					            getChildren().add(_piece);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user