Salve a tutti. Con il seguente codice, l'immagine riesce a spostarsi correttamente:
Ma io ho la necessità di creare una classe esterna che serva a spostare un'immagine senza utilizzare i "bind".codice:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javafxapplication2; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.animation.Timeline; import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.scene.input.MouseEvent; var dx: Number; var dy: Number; var image: ImageView; var timeline = Timeline { keyFrames: [ KeyFrame { time: 0s, values: [ dx => 0.0, dy => 0.0 ] } KeyFrame { time: 1s, values: [ dx => 150, dy => 150 ] } ] } Stage { title: "Test" scene: Scene { width: 550, height: 350 content: [ image = ImageView { x: bind dx, y: bind dy image: Image { url: "http://www.google.it/logos/2010/joseffrank-hp.gif"; } onMousePressed: function(e: MouseEvent) { timeline.play(); } } ] } }
Per questo ho creato una piccola classe di test:
Ma purtroppo questa soluzione non funziona... l'immagine rimane immobile! Perchè?codice:package javafxapplication2; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.animation.Timeline; import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.scene.input.MouseEvent; var image: ImageView; var timeline = Timeline { def im = image; keyFrames: [ KeyFrame { time: 0s, values: [ im.x => 20.0, im.y => 20.0 ] } KeyFrame { time: 1s, values: [ im.x => 150.0, im.y => 150.0 ] } ] } Stage { title: "Test" scene: Scene { width: 550, height: 350 content: [ image = ImageView { x: 20.0, y: 20.0 image: Image { url: "http://www.google.it/logos/2010/joseffrank-hp.gif"; } onMousePressed: function(e: MouseEvent) { timeline.play(); } } ] } }

Rispondi quotando