Skip to content

JavaFX: Side-scrolling

An side-scrolling game attempt.

an plane

I used two images, this mountain background made with Gimp (xcf sources here) and that ship above made with Inkscape (svg sources here).

import javafx.ui.*;
import javafx.ui.canvas.*;
 
var scroll;
scroll = [1..800] dur 60000 linear continue if true;
 
var mountains = Clip{
    transform: bind translate(-scroll,0)
    shape: Rect {x:bind scroll, y:0, width:400, height:200}
    content: [ImageView {
            transform: translate(0,0)
            image: Image { url: "http://silveiraneto.net/downloads/mountains.png"}
        },
        ImageView {
            transform: translate(800,0)
            image: Image { url: "http://silveiraneto.net/downloads/mountains.png"}
        }
    ]
};
 
var h = 50;
 
var ship = ImageView {
    cursor: HAND
    transform: bind translate(0,h)
    image: Image { url: "http://silveiraneto.net/downloads/jfx_plane.png"}
    onMouseDragged: operation(e) {
        h += e.localDragTranslation.y;
    }
};
 
Canvas {
    content: [mountains, ship]
}
Published inenglish

9 Comments

  1. vinay vinay

    Error in syntactic analysis in temp.fx:
    java.lang.ArrayIndexOutOfBoundsException: -1
    at org.antlr.runtime.Parser.getMissingSymbol(Parser.java:62)
    at org.antlr.runtime.BaseRecognizer.recoverFromMismatchedToken(BaseRecognizer.java:624)
    at org.antlr.runtime.BaseRecognizer.match(BaseRecognizer.java:117)
    at com.sun.tools.javafx.antlr.v3Parser.module(v3Parser.java:289)
    at com.sun.tools.javafx.antlr.JavafxSyntacticAnalysis.parse(JavafxSyntacticAnalysis.java:70)
    at com.sun.tools.javafx.main.JavafxCompiler.parse(JavafxCompiler.java:478)
    at com.sun.tools.javafx.main.JavafxCompiler.parse(JavafxCompiler.java:519)
    at com.sun.tools.javafx.main.JavafxCompiler.parseFiles(JavafxCompiler.java:825)
    at com.sun.tools.javafx.main.JavafxCompiler.compile(JavafxCompiler.java:665)
    at com.sun.tools.javafx.main.Main.compile(Main.java:597)
    at com.sun.tools.javafx.main.Main.compile(Main.java:304)
    at com.sun.tools.javafx.Main.compile(Main.java:84)
    at com.sun.tools.javafx.Main.main(Main.java:69)

  2. @Vinay right is this moment JavaFX language are passing by some changes and getting better. Unfortunately this made mostly of my codes posted here not parseable using NetBeans JavaFX plugin.
    For running them you should find out the JavaFX Pad and past this code there.

  3. asgardoo asgardoo

    wow,so clean code and so effective~

  4. JavaFX 1.0 is released, do you have a plan to rewrite your code to the latest syntax? That will be very helpful for people. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *