Skip to main content

Keep your FX Code Clean (My version)

Posted by rbair on March 24, 2009 at 11:54 AM PDT

The Exploding Pixels blog has an entry on clean FX code formatting. I didn't really like the options provided so far, so I decided to write a quick blog with my version.


def backgroundImage = Image { url: "{__DIR__}background.png" };
var verticalPositionOfLine:Number;

var s = Stage {
    title: "Background Image"
    scene: Scene {
        width: 200
        height: 232
        content: [
            ImageView { image: backgroundImage },
            // Paints two moving lines
            Group {
                translateY: bind verticalPositionOfLine
                content: [
                    Line { startX:0, startY:20, endX:200, endY:0, stroke:Color.RED }
                    Line { startX:0, startY:30, endX:200, endY:10, stroke:Color.RED }
                ]
            }
        ]
    }
}

// Start the line animation
Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames: [
      at (0s) { verticalPositionOfLine => -20 }
      at (3s) { verticalPositionOfLine => 200 tween Interpolator.LINEAR }
    }
}.play();
s

Comments

Nice...I think your version of the code is quite readable. -Ken