Vydělávej až 160.000 Kč měsíčně! Akreditované rekvalifikační kurzy s garancí práce od 0 Kč. Více informací.
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.

Diskuze: JavaFX - Problémy s animací obrázku

Aktivity
Avatar
lincerix
Člen
Avatar
lincerix:27.6.2014 3:19

Nebudu se rozepisovat ->

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fxgame;

import javafx.animation.Animation;
import javafx.animation.TimelineBuilder;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.effect.BoxBlur;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.animation.*;
import javafx.util.Duration;
import javafx.animation.Timeline;

/**
 *
 * @author Avarga
 */
public class FxGame extends Application {
     final static int WITDH = 800; //šírka okna
     final static int HEIGHT = 600;// výška okna
     final static Image BACKGROUND_IMAGE = new Image(FxGame.class.getResource("background.png").toString());
     final static Image TREE_1_IMAGE = new Image(FxGame.class.getResource("three.png").toString());
     final static Image TREE_2_IMAGE = new Image(FxGame.class.getResource("three2.png").toString());
     final static Image TREE_3_IMAGE = new Image(FxGame.class.getResource("three3.png").toString());

     final static Image BIRD_1_IMAGE = new Image(FxGame.class.getResource("bird1.png").toString());
     final static Image BIRD_2_IMAGE = new Image(FxGame.class.getResource("bird2.png").toString());
    @Override
    public void start(Stage primaryStage) {
        final ImageView  background = new ImageView(BACKGROUND_IMAGE);
        background.setEffect(new BoxBlur());


        final ImageView  tree1 = new ImageView(TREE_1_IMAGE); tree1.setTranslateX(20);tree1.setTranslateY(200);
        final ImageView  tree2 = new ImageView(TREE_2_IMAGE);tree2.setTranslateX(60);tree2.setTranslateY(400);
        final ImageView  tree3 = new ImageView(TREE_3_IMAGE);tree3.setTranslateX(90);tree3.setTranslateY(600);
        final Group foreground = new Group(tree1,tree2,tree3);
        foreground.setEffect(new DropShadow());

        final ImageView  bird1 = new ImageView(BIRD_1_IMAGE); //tree1.setTranslateX(20);tree1.setTranslateY(200);
        final ImageView  bird2 = new ImageView(BIRD_2_IMAGE);//tree2.setTranslateX(60);tree2.setTranslateY(400);
        final Group bird = new Group (bird1);




        TimelineBuilder.create()
                .cycleCount(Animation.INDEFINITE)
                .keyFrames(
                new KeyFrame(Duration.millis(150),new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                bird.getChildren().addAll(bird2);
                 //To change body of generated methods, choose Tools | Templates.
            }
        }),
                         new KeyFrame(Duration.millis(300),new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                bird.getChildren().addAll(bird1);
                //To change body of generated methods, choose Tools | Templates.
            }
        })


                )
                 .build()
                .play();

        final Group root = new Group(background,bird,foreground);//import javafx.scene.Group;



        Scene scene = new Scene(root, WITDH, HEIGHT); //Vykresli okno 800*600 (viz datové atributy)
        primaryStage.setTitle("@Game@");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}

Jde o to, že používám nejnovější update JDK/Netbeans. Evidentně třída "TimelineBuilder" je už zrušená. Nemohl by mi někdo říci, jak blok :

TimelineBuilder.create()
              .cycleCount(Animation.INDEFINITE)
              .keyFrames(
              new KeyFrame(Duration.millis(150),new EventHandler<ActionEvent>() {

          @Override
          public void handle(ActionEvent event) {
              bird.getChildren().addAll(bird2);
               //To change body of generated methods, choose Tools | Templates.
          }
      }),
                       new KeyFrame(Duration.millis(300),new EventHandler<ActionEvent>() {

          @Override
          public void handle(ActionEvent event) {
              bird.getChildren().addAll(bird1);
              //To change body of generated methods, choose Tools | Templates.
          }
      })


              )
               .build()
              .play();

Dost by jste mi pomohli.

Díky

Linc

Odpovědět
27.6.2014 3:19
Jsem otřesný programátor - začátečník... Ale nikdy mě nic nebavilo tak moc, jako čučet do Javovského kódu.
Avatar
lincerix
Člen
Avatar
lincerix:27.6.2014 3:21

*jak blok dopsat tak, aby mi to animovalo?
//nějak mi to tam vypadlo :p

Nahoru Odpovědět
27.6.2014 3:21
Jsem otřesný programátor - začátečník... Ale nikdy mě nic nebavilo tak moc, jako čučet do Javovského kódu.
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 2 zpráv z 2.