private SequentialTransition CalculateTransition( Card c, HBox PlayerCardBox, ImageView imView, int iCardDrawn) { // This is the card that is going to be dealt to the player. String strCard = "/res/img/" + c.getCardImg(); ImageView imgvCardDealt = new ImageView(new Image(getClass().getResourceAsStream(strCard), 96, 71, true, true)); // imgvCardFaceDown - There's already a place holder card // sitting in // the player's hbox. It's face down. Find it // and then determine it's bounds and top left hand handle. ImageView imgvCardFaceDown = (ImageView) PlayerCardBox.getChildren().get(iCardDrawn - 1); Bounds bndCardDealt = imgvCardFaceDown.localToScene(imgvCardFaceDown.getBoundsInLocal()); Point2D pntCardDealt = new Point2D(bndCardDealt.getMinX(), bndCardDealt.getMinY()); // imgvDealerDeck = the card in the common area, where dealer's // card // is located. Find the boundary top left point. ImageView imgvDealerDeck = (ImageView) HboxCommonArea.getChildren().get(0); Bounds bndCardDeck = imgvDealerDeck.localToScene(imgvDealerDeck.getBoundsInLocal()); Point2D pntCardDeck = new Point2D(bndCardDeck.getMinX(), bndCardDeck.getMinY()); // Add a sequential transition to the card (move, rotate) SequentialTransition transMoveRotCard = createTransition(pntCardDeck, pntCardDealt, imView); // Add a parallel transition to the card (fade in/fade out). final ParallelTransition transFadeCardInOut = createFadeTransition( imgvCardFaceDown, new Image(getClass().getResourceAsStream(strCard), 75, 75, true, true)); SequentialTransition transAllActions = new SequentialTransition(); transAllActions.getChildren().addAll(transMoveRotCard, transFadeCardInOut); return transAllActions; }
/** Create the game's scene */ public Scene init(int width, int height) { // Create a scene graph to organize the scene Group root = new Group(); // Create a place to see the shapes myScene = new Scene(root, width, height, Color.WHITE); // Make some shapes and set their properties Image image = new Image(getClass().getClassLoader().getResourceAsStream("duke.gif")); myBouncer = new ImageView(image); // x and y represent the top left corner, so center it myBouncer.setX(width / 2 - myBouncer.getBoundsInLocal().getWidth() / 2); myBouncer.setY(height / 2 - myBouncer.getBoundsInLocal().getHeight() / 2); myTopBlock = new Rectangle(width / 2 - 25, height / 2 - 100, 50, 50); myTopBlock.setFill(Color.RED); myBottomBlock = new Rectangle(width / 2 - 25, height / 2 + 50, 50, 50); myBottomBlock.setFill(Color.BISQUE); // order added to the group is the order in whuch they are drawn root.getChildren().add(myBouncer); root.getChildren().add(myTopBlock); root.getChildren().add(myBottomBlock); // Respond to input myScene.setOnKeyPressed(e -> handleKeyInput(e.getCode())); myScene.setOnMouseClicked(e -> handleMouseInput(e.getX(), e.getY())); return myScene; }