我有一个DragEvent,可以处理棋盘游戏中的棋子。抓住一块时,可能的目标位置会用绿色标记(“ selectedPiece =位置”->“ drawBoard()”),一旦放置一块,这些标记就会消失(“ selectedPiece = null”->“ drawBoard()” )。但是,如果将棋子掉到板子外面,标记就会保留。有没有办法检测到带有无效目标的液滴?
ImageView getMoveablePiece(Position position)
{
ImageView piece = getPiece(pos);
piece.setOnDragDetected((MouseEvent event) -> {
Dragboard db = piece.startDragAndDrop(TransferMode.MOVE);
ClipboardContent content = new ClipboardContent();
content.putImage(piece.getImage());
db.setContent(content);
selectedPiece = position;
drawBoard();
event.consume();
});
return piece;
}