當前位置: 首頁>>代碼示例>>Java>>正文


Java Node.setTranslateX方法代碼示例

本文整理匯總了Java中javafx.scene.Node.setTranslateX方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.setTranslateX方法的具體用法?Java Node.setTranslateX怎麽用?Java Node.setTranslateX使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javafx.scene.Node的用法示例。


在下文中一共展示了Node.setTranslateX方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initTimeline

import javafx.scene.Node; //導入方法依賴的package包/類
private void initTimeline() {
    timeline = new Timeline();
    timeline.setCycleCount(Timeline.INDEFINITE);
    KeyFrame kf = new KeyFrame(Config.ANIMATION_TIME, new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            if (state == STATE_SHOW_TITLE) {
                stateArg++;
                int center = Config.SCREEN_WIDTH / 2;
                int offset = (int)(Math.cos(stateArg / 4.0) * (40 - stateArg) / 40 * center);
                brick.setTranslateX(center - brick.getImage().getWidth() / 2 + offset);
                breaker.setTranslateX(center - breaker.getImage().getWidth() / 2 - offset);
                if (stateArg == 40) {
                    stateArg = 0;
                    state = STATE_SHOW_STRIKE;
                }
                return;
            }
            if (state == STATE_SHOW_STRIKE) {
                if (stateArg == 0) {
                    strike.setTranslateX(breaker.getTranslateX() + brick.getImage().getWidth());
                    strike.setScaleX(0);
                    strike.setScaleY(0);
                    strike.setVisible(true);
                }
                stateArg++;
                double coef = stateArg / 30f;
                brick.setTranslateX(breaker.getTranslateX() +
                    (breaker.getImage().getWidth() - brick.getImage().getWidth()) / 2f * (1 - coef));
                strike.setScaleX(coef);
                strike.setScaleY(coef);
                strike.setRotate((30 - stateArg) * 2);
                if (stateArg == 30) {
                    stateArg = 0;
                    state = STATE_SUN;
                }
                return;
            }
            // Here state == STATE_SUN
            if (pressanykey.getOpacity() < 1) {
                pressanykey.setOpacity(pressanykey.getOpacity() + 0.05f);
            }
            stateArg--;
            double x = SUN_AMPLITUDE_X * Math.cos(stateArg / 100.0);
            double y = SUN_AMPLITUDE_Y * Math.sin(stateArg / 100.0);
            if (y < 0) {
                for (Node node : NODES_SHADOWS) {
                    // Workaround RT-1976
                    node.setTranslateX(-1000);
                }
                return;
            }
            double sunX = Config.SCREEN_WIDTH / 2 + x;
            double sunY = Config.SCREEN_HEIGHT / 2 - y;
            sun.setTranslateX(sunX - sun.getImage().getWidth() / 2);
            sun.setTranslateY(sunY - sun.getImage().getHeight() / 2);
            sun.setRotate(-stateArg);
            for (int i = 0; i < NODES.length; i++) {
                NODES_SHADOWS[i].setOpacity(y / SUN_AMPLITUDE_Y / 2);
                NODES_SHADOWS[i].setTranslateX(NODES[i].getTranslateX() +
                    (NODES[i].getTranslateX() + NODES[i].getImage().getWidth() / 2 - sunX) / 20);
                NODES_SHADOWS[i].setTranslateY(NODES[i].getTranslateY() +
                    (NODES[i].getTranslateY() + NODES[i].getImage().getHeight() / 2 - sunY) / 20);
            }
        }
    });
    timeline.getKeyFrames().add(kf);
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:68,代碼來源:Splash.java

示例2: scaleAll

import javafx.scene.Node; //導入方法依賴的package包/類
private static void scaleAll(Scene scene, Node node) {
    double translateX = node.getTranslateX();
    double translateY = node.getTranslateY();
    double baseX = node.getBoundsInParent().getMinX();
    double baseY = node.getBoundsInParent().getMinY();
    double sceneWidth = scene.getWidth();
    double sceneHeight = scene.getHeight();
    ChangeListener<Number> widthResizer = (arg0, oldValue, newValue) -> {
        node.setScaleX(newValue.doubleValue() / sceneWidth);
        node.setTranslateX(translateX + (baseX * newValue.doubleValue() / sceneWidth) - baseX);
    };

    scene.widthProperty().addListener(widthResizer);
    ChangeListener<Number> heightResizer = (arg0, oldValue, newValue) -> {
        node.setScaleY(newValue.doubleValue() / sceneHeight);
        node.setTranslateY(translateY + (baseY * newValue.doubleValue() / sceneHeight) - baseY);
    };
    scene.heightProperty().addListener(heightResizer);

}
 
開發者ID:ciphertechsolutions,項目名稱:IO,代碼行數:21,代碼來源:BaseController.java

示例3: zoomInAndCenter

import javafx.scene.Node; //導入方法依賴的package包/類
private static void zoomInAndCenter(Node node, double initialWidth, double initialHeight, boolean preserveRatio) {
    Parent parent = node.getParent();

    node.toFront();

    Bounds parentBoundsInParent = parent.getBoundsInLocal();

    double xScaleRatio = parentBoundsInParent.getMaxX() / initialWidth;
    double yScaleRatio = parentBoundsInParent.getMaxY() / initialHeight;

    if (preserveRatio) {
        double bestScaleRatio = Math.min(xScaleRatio, yScaleRatio);
        node.setScaleX(bestScaleRatio);
        node.setScaleY(bestScaleRatio);
    } else {
        node.setScaleX(xScaleRatio);
        node.setScaleY(yScaleRatio);
    }

    Bounds boundsInParent = node.getBoundsInParent();

    double translateX = -1 * Math.abs(boundsInParent.getMinY());
    double translateY = -1 * Math.abs(boundsInParent.getMinY());

    node.setTranslateX(translateX);
    node.setTranslateY(translateY);
}
 
開發者ID:schwabdidier,項目名稱:GazePlay,代碼行數:28,代碼來源:StatsDisplay.java

示例4: handle

import javafx.scene.Node; //導入方法依賴的package包/類
@Override
public void handle(MouseEvent event) {

    if( !enabled) {
        return;
    }

    // all in selection
    for( Node node: selectionModel.selection) {
        node.setTranslateX( dragContext.x + event.getSceneX());
        node.setTranslateY( dragContext.y + event.getSceneY());
    }

}
 
開發者ID:lttng,項目名稱:lttng-scope,代碼行數:15,代碼來源:ExampleMouseDrag2.java

示例5: zoomOutAndReset

import javafx.scene.Node; //導入方法依賴的package包/類
private static void zoomOutAndReset(Node node) {
    node.setScaleX(1);
    node.setScaleY(1);
    node.setTranslateX(0);
    node.setTranslateY(0);
}
 
開發者ID:schwabdidier,項目名稱:GazePlay,代碼行數:7,代碼來源:StatsDisplay.java

示例6: handle

import javafx.scene.Node; //導入方法依賴的package包/類
public void handle(MouseEvent event) {

            // left mouse button => dragging
            if (!event.isPrimaryButtonDown())
                return;

            double scale = canvas.getScale();

            Node node = (Node) event.getSource();

            node.setTranslateX(nodeDragContext.translateAnchorX + ((event.getSceneX() - nodeDragContext.mouseAnchorX) / scale));
            node.setTranslateY(nodeDragContext.translateAnchorY + ((event.getSceneY() - nodeDragContext.mouseAnchorY) / scale));

            event.consume();

        }
 
開發者ID:INAETICS,項目名稱:Drones-Simulator,代碼行數:17,代碼來源:NodeGestures.java

示例7: fixPosition

import javafx.scene.Node; //導入方法依賴的package包/類
/**
 * Set node's layout position to current position, remove translate coordinates.
 * @param node
 */
private void fixPosition( Node node) {

    double x = node.getTranslateX();
    double y = node.getTranslateY();

    node.relocate(node.getLayoutX() + x, node.getLayoutY() + y);

    node.setTranslateX(0);
    node.setTranslateY(0);

}
 
開發者ID:lttng,項目名稱:lttng-scope,代碼行數:16,代碼來源:ExampleMouseDrag2.java


注:本文中的javafx.scene.Node.setTranslateX方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。