<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Silveira Neto &#187; jfx</title>
	<atom:link href="http://silveiraneto.net/tag/jfx/feed/" rel="self" type="application/rss+xml" />
	<link>http://silveiraneto.net</link>
	<description>the world is a pixel</description>
	<lastBuildDate>Sun, 08 Jan 2012 05:17:57 +0000</lastBuildDate>
	<language>pt-br</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>JavaFX 1.1 for Linux workaround</title>
		<link>http://silveiraneto.net/2009/05/16/javafx-11-for-linux-workaround/</link>
		<comments>http://silveiraneto.net/2009/05/16/javafx-11-for-linux-workaround/#comments</comments>
		<pubDate>Sat, 16 May 2009 11:53:15 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[HuaSong Liu]]></category>
		<category><![CDATA[jaunty jackalope]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[javafx4linux]]></category>
		<category><![CDATA[jfx]]></category>
		<category><![CDATA[Kaesar Alnijres]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[Weiqi Gao]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2581</guid>
		<description><![CDATA[Download javafx4linux.tar.bz2 (~ 36Mb). Installing 1) Extract the javafx4linux.tar.bz2 file. In this example I&#8217;m placing it on my Desktop. After the installing process you can remove it. 2) Open your NetBeans 6.5 and go at Tools → Plugins and go to Downloaded tab. In a plain and new NetBeans installation there will be no plugin [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Download</strong></p>
<blockquote><p><a title="JavaFX for Linux" href="http://silveiraneto.net/downloads/javafx4linux.tar.bz2">javafx4linux.tar.bz2</a> (~ 36Mb).</p></blockquote>
<p><strong>Installing</strong></p>
<p>1) Extract the javafx4linux.tar.bz2 file. In this example I&#8217;m placing it on my Desktop. After the installing process you can remove it.</p>
<p style="text-align: center;"><strong><a href="http://silveiraneto.net/wp-content/uploads/2009/05/javafx_linux_ubuntu_extract.png"><img class="size-medium wp-image-2593 aligncenter" title="javafx linux ubuntu extract" src="http://silveiraneto.net/wp-content/uploads/2009/05/javafx_linux_ubuntu_extract-500x312.png" alt="javafx linux ubuntu extract" width="500" height="312" /></a><br />
</strong></p>
<p>2) Open your NetBeans 6.5 and go at <em>Tools</em> → <em>Plugins</em> and go to <em>Downloaded</em> tab. In a plain and new NetBeans installation there will be no plugin in this tab yet.</p>
<p style="text-align: center;"><strong><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step01.png"><img class="alignnone size-medium wp-image-2582" title="netbeans javafx linux step01" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step01-500x312.png" alt="netbeans javafx linux step01" width="500" height="312" /></a><br />
</strong></p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step02.png"><img class="size-medium wp-image-2583 aligncenter" title="netbeans javafx linux step02" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step02-500x312.png" alt="netbeans javafx linux step02" width="500" height="312" /></a></p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step03.png"><img class="size-medium wp-image-2584 aligncenter" title="netbeans javafx linux step03" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step03-500x312.png" alt="netbeans javafx linux step03" width="500" height="312" /></a></p>
<p>3) Click on the <em>Add Plugins</em> button and head to the directory you extracted the file and select all .nbm files.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step04.png"><img class="size-medium wp-image-2585 aligncenter" title="netbeans javafx linux step 04" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step04-500x312.png" alt="netbeans javafx linux step 04" width="500" height="312" /></a></p>
<p>4) You will see a list of 22 plugins selected. Click on the <em>Install</em> button.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step05.png"><img class="size-medium wp-image-2586 aligncenter" title="netbeans javafx linux step 05" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step05-500x312.png" alt="netbeans javafx linux step 05" width="500" height="312" /></a></p>
<p>5) Just keep clicking on the <em>Next</em> button.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step06.png"><img class="size-medium wp-image-2587 aligncenter" title="netbeans javafx linux step 6" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step06-500x312.png" alt="netbeans javafx linux step 6" width="500" height="312" /></a></p>
<p>6) Check the license agreement accept box.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step07.png"><img class="size-medium wp-image-2588 aligncenter" title="netbeans javafx linux step 7" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step07-500x312.png" alt="netbeans javafx linux step 7" width="500" height="312" /></a></p>
<p>7) You&#8217;ll see a warning because the Linux pluggin is not signed. Don&#8217;t worry, just click <em>Continue</em>.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step08.png"><img class="size-medium wp-image-2589 aligncenter" title="netbeans javafx linux step 8" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step08-500x312.png" alt="netbeans javafx linux step 8" width="500" height="312" /></a></p>
<p>8) Click on Finish to restart NetBeans.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step09.png"><img class="size-medium wp-image-2590 aligncenter" title="netbeans javafx linux step 9" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step09-500x312.png" alt="netbeans javafx linux step 9" width="500" height="312" /></a></p>
<p>9) Now we can test it. Go at <em>File</em> → <em>New Project</em>, select the JavaFX on <em>Categories</em> and <em>JavaFX Script Application</em> on Projects.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step10.png"><img class="alignnone size-medium wp-image-2591" title="netbeans javafx linux step 10" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step10-500x312.png" alt="netbeans javafx linux step 10" width="500" height="312" /></a></p>
<p>10) Put some code and run it. There is. JavaFX on Linux.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step11.png"><img class="size-medium wp-image-2592 aligncenter" title="netbeans javafx linux step 11" src="http://silveiraneto.net/wp-content/uploads/2009/05/netbeans_javafx_linux_step11-500x312.png" alt="netbeans javafx linux step 11" width="500" height="312" /></a></p>
<p><strong>Considerations</strong></p>
<p>This is not a official of JavaFX for Linux! This solution was tested on Ubuntu 9.04 &#8220;Jaunty Jackalope&#8221; with Java 6 update 13 and NetBeans 6.5.1, but should also work with others Linux distributions and Java versions greater than 5.</p>
<p><strong>Known bugs</strong></p>
<p>As a non official workaround for JavaFX for Linux you may notice some drawbacks. Some parts of the JavaFX runtime rely on native implementations on the specific operational system. You may not use some multimedia capabilities as video playback, JavaFX Mobile emulator and some performance issues in some effects. Despite that, is perfectly possible to develop applications using JavaFX on NetBeans.</p>
<p><strong>Thanks</strong></p>
<p>I&#8217;d like to thanks some guys around the world. <a href="http://www.weiqigao.com/blog/2008/12/04/using_javafx_1_0_on_linux.html">Weiqi Gao&#8217;s original post on JavaFX on Linux</a>, <a href="http://java.dzone.com/tips/javafx-11-linux-netbeans">HuaSong Liu article on DZone</a> and <a href="http://java-javafx-iipt.blogspot.com/2009/03/javafx-111-netbeans-651-on-linux.html">Kaesar Alnijres post</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/05/16/javafx-11-for-linux-workaround/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Reading Twitter with JavaFX</title>
		<link>http://silveiraneto.net/2009/01/04/reding-twitter-with-javafx/</link>
		<comments>http://silveiraneto.net/2009/01/04/reding-twitter-with-javafx/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 22:56:55 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[jfx]]></category>
		<category><![CDATA[microblogging]]></category>
		<category><![CDATA[openjfx]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[Social Networking]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2064</guid>
		<description><![CDATA[Twitter is a social network and micro-blogging service that allow you to create and read tweets, 140 characters text-based posts. It&#8217;s becoming a popular tool to keep in touch with your friends, coworkers, bloggers, etc. Here we&#8217;ll create a very simple application that show us tweets related with a given word. Twitter offers a very [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="size-full wp-image-2073 aligncenter" title="twitter bird" src="http://silveiraneto.net/wp-content/uploads/2009/01/twitter-bird.gif" alt="twitter bird" width="250" height="184" /></p>
<p><a title="Twitter Micro Blogging Service" href="http://twitter.com">Twitter</a> is a social network and micro-blogging service that allow you to create and read tweets, 140 characters text-based posts. It&#8217;s becoming a popular tool to keep in touch with your friends, coworkers, bloggers, etc. Here we&#8217;ll create a very simple application that show us tweets related with a given word.</p>
<p>Twitter offers a very simple and powerfull <a href="http://apiwiki.twitter.com/">REST API</a> which supports <a rel="nofollow" href="http://en.wikipedia.org/wiki/XML"><span>XML</span></a>, <a rel="nofollow" href="http://en.wikipedia.org/wiki/Json"><span>JSON</span></a>, and the <a rel="nofollow" href="http://en.wikipedia.org/wiki/RSS"><span>RSS</span></a> and <a rel="nofollow" href="http://en.wikipedia.org/wiki/Atom_%28standard%29">Atom</a> formats. As we are aiming just to read tweets we&#8217;ll use just the Search API.</p>
<p>We do that in three steps:</p>
<ol>
<li>Query Tweets</li>
<li>Parser the Atom result</li>
<li>Show tweets into a GUI</li>
</ol>
<p>Let&#8217;s see them in the order of dependence beetween them.</p>
<p><strong>Displaying a Tweet</strong></p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;">var gradient <span style="color: #339933;">=</span> LinearGradient <span style="color: #009900;">&#123;</span>
    startX<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0.0</span>,
    startY<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0.0</span>,
    endX<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0.0</span>,
    endY<span style="color: #339933;">:</span> <span style="color: #cc66cc;">150.0</span>
    proportional<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">false</span>
    stops<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>Stop <span style="color: #009900;">&#123;</span>offset<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0.0</span> color<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">DARKGRAY</span> <span style="color: #009900;">&#125;</span>,
        Stop <span style="color: #009900;">&#123;</span> offset<span style="color: #339933;">:</span> <span style="color: #cc66cc;">1.0</span> color<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">BLACK</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Tweet <span style="color: #000000; font-weight: bold;">extends</span> CustomNode <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> var image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span>;
    <span style="color: #000000; font-weight: bold;">public</span> var username<span style="color: #339933;">:</span> <span style="color: #003399;">String</span>;
    <span style="color: #000000; font-weight: bold;">public</span> var message<span style="color: #339933;">:</span> <span style="color: #003399;">String</span>;
    <span style="color: #000000; font-weight: bold;">public</span> override function create<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> Node <span style="color: #009900;">&#123;</span>
        var txt <span style="color: #339933;">=</span> Text <span style="color: #009900;">&#123;</span>
            x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">65</span>  y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">35</span> wrappingWidth<span style="color: #339933;">:</span> <span style="color: #cc66cc;">150</span> fill<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">WHITE</span>
            content<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{message}&quot;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #003399;">Group</span> <span style="color: #009900;">&#123;</span>
            content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
                <span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span>
                    width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">220</span> height<span style="color: #339933;">:</span> txt.<span style="color: #006633;">boundsInLocal</span>.<span style="color: #006633;">height</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">40</span>
                    arcHeight<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span> arcWidth<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span> fill<span style="color: #339933;">:</span> gradient
                <span style="color: #009900;">&#125;</span>,
                ImageView <span style="color: #009900;">&#123;</span>
                    x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">5</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> image<span style="color: #339933;">:</span> image
                <span style="color: #009900;">&#125;</span>,
                Text <span style="color: #009900;">&#123;</span>
                    x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">65</span>  y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> fill<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">BLACK</span> content<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{username} said&quot;</span>
                <span style="color: #009900;">&#125;</span>,
                txt
            <span style="color: #009900;">&#93;</span>
        <span style="color: #009900;">&#125;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>For example, <a title="P4bl0's Tweet" href="http://twitter.com/p4bl0/statuses/1095717367">this tweet</a> would become:</p>
<p style="text-align: center;"><img class="size-full wp-image-2070 aligncenter" title="tweet example" src="http://silveiraneto.net/wp-content/uploads/2009/01/tweet_example.png" alt="tweet example" width="220" height="100" /></p>
<p><strong>Parsing ATOM result</strong></p>
<p>In <a title="XML Sandwich JavaFX " href="http://silveiraneto.net/2008/12/25/parsing-xml-sandwich-with-javafx/">my last post about JavaFX</a> I showed how to parse XML documents (and make sandwiches) with JavaFX. Here we&#8217;ll use the Atom format, but use any other would be almost the same. Parsing XML or JSON documents with JavaFX is both very simple using the <a title="JavaFX API" href="http://java.sun.com/javafx/1/docs/api/javafx.data.pull/javafx.data.pull.PullParser.html">javafx.data.pull.PullParser</a> class.</p>
<p>A query output is a Atom XML document with several information. We are interested only in the fields that holds the avatar image, the message and the user name.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;">var tweets <span style="color: #339933;">=</span> VBox <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
def parser <span style="color: #339933;">=</span> PullParser <span style="color: #009900;">&#123;</span>
    var avatar;
    var firstname;
    var text;
    documentType<span style="color: #339933;">:</span> PullParser.<span style="color: #006633;">XML</span>;
&nbsp;
    onEvent<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>event<span style="color: #339933;">:</span> <span style="color: #003399;">Event</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>event.<span style="color: #006633;">type</span> <span style="color: #339933;">==</span> PullParser.<span style="color: #006633;">START_ELEMENT</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>event.<span style="color: #006633;">qname</span>.<span style="color: #006633;">name</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;link&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>event.<span style="color: #006633;">getAttributeValue</span><span style="color: #009900;">&#40;</span>QName<span style="color: #009900;">&#123;</span>name<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;rel&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;image&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    avatar <span style="color: #339933;">=</span> event.<span style="color: #006633;">getAttributeValue</span><span style="color: #009900;">&#40;</span>QName<span style="color: #009900;">&#123;</span>name<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;href&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>event.<span style="color: #006633;">type</span> <span style="color: #339933;">==</span> PullParser.<span style="color: #006633;">END_ELEMENT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>event.<span style="color: #006633;">qname</span>.<span style="color: #006633;">name</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    text <span style="color: #339933;">=</span> event.<span style="color: #006633;">text</span>;
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>event.<span style="color: #006633;">qname</span>.<span style="color: #006633;">name</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#41;</span>and<span style="color: #009900;">&#40;</span>event.<span style="color: #006633;">level</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                var names<span style="color: #339933;">:</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> event.<span style="color: #006633;">text</span>.<span style="color: #006633;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #009900;">&#41;</span>;
                firstname <span style="color: #339933;">=</span> names<span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span>;
                insert Tweet <span style="color: #009900;">&#123;</span>
                        image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>
                            url<span style="color: #339933;">:</span> avatar
                        <span style="color: #009900;">&#125;</span>
                        message<span style="color: #339933;">:</span> text
                        username<span style="color: #339933;">:</span> firstname
                    <span style="color: #009900;">&#125;</span> into tweets.<span style="color: #006633;">content</span>;
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p><strong>Querying Tweets</strong></p>
<p>We can get Atom results through url queries like that:</p>
<ul>
<li>Tweets containing the word Beatles <a href="http://search.twitter.com/search.atom?q=Beatles">http://search.twitter.com/search.atom?q=Beatles</a></li>
<li>Tweets from the user Silveira <a href="http://search.twitter.com/search.atom?q=from%3ASilveira">http://search.twitter.com/search.atom?q=from%3ASilveira</a></li>
<li>Tweets to the user Silveira <a href="http://search.twitter.com/search.atom?q=to%3ASilveira">http://search.twitter.com/search.atom?q=to%3ASilveira</a></li>
<li>Tweets containing the hashtag #CEJUG <a href="http://search.twitter.com/search.atom?q=to%23CEJUG">http://search.twitter.com/search.atom?q=to%23CEJUG</a></li>
</ul>
<p>Notice that queries should be URL encoded. We will use a additional parameters <strong>&amp;rpp=4</strong> to receive<strong> </strong>only 4 results per page. To know more about search queries read the <a title="Twitter Search API" href="http://apiwiki.twitter.com/Search+API+Documentation">Search API Documentation</a>. We get these results as  <a title="Java API InputStream" href="http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html">InputStreams</a> making asynchronous HTTP requests using the <a title="JavaFX API" href="http://java.sun.com/javafx/1/docs/api/javafx.io.http/javafx.io.http.HttpRequest.html">javafx.io.http.HttpRequest</a> class, which it&#8217;s perfect to invoke   RESTful Web Services.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;">word <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Beatles&quot;</span>;
var request <span style="color: #339933;">=</span> HttpRequest <span style="color: #009900;">&#123;</span>
    location<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;http://search.twitter.com/search.atom?q={word}&amp;amp;rpp=4&quot;</span>;
    onInput<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>stream<span style="color: #339933;">:</span> java.<span style="color: #006633;">io</span>.<span style="color: #003399;">InputStream</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        parser.<span style="color: #006633;">input</span> <span style="color: #339933;">=</span> stream;
        parser.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
request.<span style="color: #006633;">enqueue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;</pre>
</div>
</div>
<p><strong>Conclusion</strong></p>
<p>Here is the application running for the word &#8220;House&#8221;.</p>
<p style="text-align: center;"><img class="size-full wp-image-2074 aligncenter" title="twitter with javafx" src="http://silveiraneto.net/wp-content/uploads/2009/01/twitter_with_javafx.png" alt="twitter with javafx" width="220" height="458" /></p>
<p>Is not a complete Twitter client, as it&#8217;s not intended to be, but can show you how to handle a simple asynchronous call and handle Twitter documents. There&#8217;s already a few beta JavaFX Twitter clients like <a title="Tweetbox at Google Code" href="http://code.google.com/p/tweetbox/">Tweetbox</a> and <a title="TwitterFX at Project Kenai" href="http://projectkenai.com/projects/twitterfx">Twitterfx</a> and certanly others will appears.</p>
<p><strong>Download</strong></p>
<p>Sources and Netbeans project, <a href="http://silveiraneto.net/downloads/fxtwitter.tar.bz2">fxtwitter.tar.bz2</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/01/04/reding-twitter-with-javafx/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Parsing a XML Sandwich with JavaFX</title>
		<link>http://silveiraneto.net/2008/12/25/parsing-xml-sandwich-with-javafx/</link>
		<comments>http://silveiraneto.net/2008/12/25/parsing-xml-sandwich-with-javafx/#comments</comments>
		<pubDate>Fri, 26 Dec 2008 02:39:54 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[jfx]]></category>
		<category><![CDATA[openjfx]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[yaml]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2018</guid>
		<description><![CDATA[Let sandwich.xml be a file at /tmp directory with the content above. &#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62; &#160; &#60;bread sesame=&#34;true&#34;&#62; &#60;catchup/&#62; &#60;hamburguer/&#62; &#60;cheese type=&#34;chedar&#34;/&#62; &#60;maionese/&#62; &#60;lettuce/&#62; &#60;/bread&#62; We can open it using java.io.FileInputStream and so use it on a javafx.data.pull.PullParser. A PullParser is a event oriented parser that works with XML and YAML files. Above a general [...]]]></description>
			<content:encoded><![CDATA[<p><center><img src="http://silveiraneto.net/wp-content/uploads/2008/12/sandwich.jpg" alt="delicious sandwich" title="delicious sandwich" width="400" height="257" class="alignnone size-full wp-image-2022" /></center></p>
<p>Let sandwich.xml be a file at /tmp directory with the content above.</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bread</span> <span style="color: #000066;">sesame</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;catchup</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hamburguer</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cheese</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;chedar&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;maionese</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lettuce</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bread<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
<p>We can open it using java.io.FileInputStream and so use it on a <a href="http://java.sun.com/javafx/1/docs/api/javafx.data.pull/javafx.data.pull.PullParser.html">javafx.data.pull.PullParser</a>. A PullParser is a event oriented parser that works with XML and YAML files. Above a general and simple parser with a GUI that show the list of events during the parse process.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.FileInputStream</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.data.pull.Event</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.data.pull.PullParser</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.ext.swing.SwingList</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.ext.swing.SwingListItem</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.Scene</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.stage.Stage</span>;
&nbsp;
var list <span style="color: #339933;">=</span> SwingList <span style="color: #009900;">&#123;</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">600</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">300</span> <span style="color: #009900;">&#125;</span>
&nbsp;
var myparser <span style="color: #339933;">=</span> PullParser <span style="color: #009900;">&#123;</span>
   documentType<span style="color: #339933;">:</span> PullParser.<span style="color: #006633;">XML</span>;
   onEvent<span style="color: #339933;">:</span> function <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span> <span style="color: #003399;">Event</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      var item <span style="color: #339933;">=</span> SwingListItem <span style="color: #009900;">&#123;</span>
         text<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;event {e}&quot;</span>
      <span style="color: #009900;">&#125;</span>;
      insert item into list.<span style="color: #006633;">items</span>;
   <span style="color: #009900;">&#125;</span>
   input<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/tmp/sandwich.xml&quot;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
myparser.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
Stage <span style="color: #009900;">&#123;</span>
   title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;XML Sandwich&quot;</span>
   scene<span style="color: #339933;">:</span> Scene <span style="color: #009900;">&#123;</span> content<span style="color: #339933;">:</span> list <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p><center><img src="http://silveiraneto.net/wp-content/uploads/2008/12/javafx_xml_sandwich.png" alt="javafx xml sandwich" title="javafx xml sandwich" width="625" height="354" class="alignnone size-full wp-image-2021" /></center></p>
<p>The XML cheese element produce two the outputs.</p>
<blockquote><p>type:1 typeName:START_ELEMENT level:1 qname:cheese text:&#8221; namespaces:{} attributes:{type=chedar}<br />
type:2 typeName:END_ELEMENT level:1 qname:cheese text:&#8221; namespaces:{} attributes:{type=chedar}</p></blockquote>
<p>Notice that white spaces like tab and escape characters like new line also produced events from type TEXT. We are not interested on them. Above a parser that looks only those events of type START_ELEMENT or END_ELEMENT, look into it&#8217;s contents, building a sandwich at runtime based on the XML file.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.FileInputStream</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.data.pull.Event</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.data.pull.PullParser</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.data.xml.QName</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.image.Image</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.image.ImageView</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.layout.VBox</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.Scene</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.stage.Stage</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// my sandwich starts as an empty VBox</span>
var mysandwich <span style="color: #339933;">=</span> VBox <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// give a name and returns a ImageView with a png image like the name</span>
function ingredient<span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">return</span> ImageView <span style="color: #009900;">&#123;</span>
      image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>
         url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}{name}.png&quot;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// basicaly, look the event and put a ingredient at mysandwich</span>
var myparser <span style="color: #339933;">=</span> PullParser <span style="color: #009900;">&#123;</span>
   documentType<span style="color: #339933;">:</span> PullParser.<span style="color: #006633;">XML</span>;
   onEvent<span style="color: #339933;">:</span> function <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span> <span style="color: #003399;">Event</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// starter xml elements</span>
      <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">type</span> <span style="color: #339933;">==</span> PullParser.<span style="color: #006633;">START_ELEMENT</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #666666; font-style: italic;">// bread</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">qname</span>.<span style="color: #006633;">name</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;bread&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
             insert ingredient<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;bread_top&quot;</span><span style="color: #009900;">&#41;</span> into mysandwich.<span style="color: #006633;">content</span>;
         <span style="color: #009900;">&#125;</span>
&nbsp;
         <span style="color: #666666; font-style: italic;">// hamburguer</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">qname</span>.<span style="color: #006633;">name</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hamburguer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
             insert ingredient<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hamburguer&quot;</span><span style="color: #009900;">&#41;</span> into mysandwich.<span style="color: #006633;">content</span>;
         <span style="color: #009900;">&#125;</span>
&nbsp;
         <span style="color: #666666; font-style: italic;">// catchup</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">qname</span>.<span style="color: #006633;">name</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;catchup&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
             insert ingredient<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;catchup&quot;</span><span style="color: #009900;">&#41;</span> into mysandwich.<span style="color: #006633;">content</span>;
         <span style="color: #009900;">&#125;</span>
&nbsp;
         <span style="color: #666666; font-style: italic;">// maionese</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">qname</span>.<span style="color: #006633;">name</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;maionese&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
             insert ingredient<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;maionese&quot;</span><span style="color: #009900;">&#41;</span> into mysandwich.<span style="color: #006633;">content</span>;
         <span style="color: #009900;">&#125;</span>
&nbsp;
         <span style="color: #666666; font-style: italic;">// lettuce</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">qname</span>.<span style="color: #006633;">name</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;lettuce&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
             insert ingredient<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;lettuce&quot;</span><span style="color: #009900;">&#41;</span> into mysandwich.<span style="color: #006633;">content</span>;
         <span style="color: #009900;">&#125;</span>
&nbsp;
         <span style="color: #666666; font-style: italic;">// cheese</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">qname</span>.<span style="color: #006633;">name</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cheese&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            var type<span style="color: #339933;">=</span> e.<span style="color: #006633;">getAttributeValue</span><span style="color: #009900;">&#40;</span>QName<span style="color: #009900;">&#123;</span>name<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>type.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cheedar&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                 insert ingredient<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cheedar&quot;</span><span style="color: #009900;">&#41;</span> into mysandwich.<span style="color: #006633;">content</span>;
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                insert ingredient<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cheese&quot;</span><span style="color: #009900;">&#41;</span> into mysandwich.<span style="color: #006633;">content</span>;
            <span style="color: #009900;">&#125;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// ending xml elements (just bread)</span>
      <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">type</span> <span style="color: #339933;">==</span> PullParser.<span style="color: #006633;">END_ELEMENT</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">qname</span>.<span style="color: #006633;">name</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;bread&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            insert ingredient<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;bread_botton&quot;</span><span style="color: #009900;">&#41;</span> into mysandwich.<span style="color: #006633;">content</span>;
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
   input<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/tmp/sandwich.xml&quot;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
myparser.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
Stage <span style="color: #009900;">&#123;</span>
   title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;XML Sandwich&quot;</span>
   scene<span style="color: #339933;">:</span> Scene <span style="color: #009900;">&#123;</span>
      height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">300</span>
      content<span style="color: #339933;">:</span> mysandwich
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>Here&#8217;s our sandwich.</p>
<p><center><img src="http://silveiraneto.net/wp-content/uploads/2008/12/sandwich_javafx.png" alt="sandwich javaFX" title="sandwich javaFX" width="335" height="349" class="alignnone size-full wp-image-2024" /></center></p>
<p>Just changing the XML file you got a new sandwich.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #339933;">&lt;?</span>xml version<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1.0&quot;</span> encoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">?&gt;</span>
<span style="color: #339933;">&lt;!--</span> <span style="color: #000066; font-weight: bold;">double</span> burger <span style="color: #339933;">--&gt;</span>
<span style="color: #339933;">&lt;</span>bread sesame<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span>maionese<span style="color: #339933;">/&gt;</span>
   <span style="color: #339933;">&lt;</span>lettuce<span style="color: #339933;">/&gt;</span>
   <span style="color: #339933;">&lt;</span>hamburguer<span style="color: #339933;">/&gt;</span>
   <span style="color: #339933;">&lt;</span>cheese type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;chedar&quot;</span><span style="color: #339933;">/&gt;</span>
   <span style="color: #339933;">&lt;</span>catchup<span style="color: #339933;">/&gt;</span>
   <span style="color: #339933;">&lt;</span>hamburguer<span style="color: #339933;">/&gt;</span>
   <span style="color: #339933;">&lt;</span>lettuce<span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>bread<span style="color: #339933;">&gt;</span></pre>
</div>
</div>
<p><center><img src="http://silveiraneto.net/wp-content/uploads/2008/12/double_burguer_javafx.png" alt="double burguer " title="double burguer " width="338" height="355" class="alignnone size-full wp-image-2026" /></center></p>
<p>Bon appétit.</p>
<p>For more details on XML and JSON parsing see the <a href="http://java.sun.com/javafx/1/docs/api/javafx.data.pull/javafx.data.pull.PullParser.html">JavaFX API</a>.</p>
<p><small></p>
<ul>
<li><strong>ps:</strong> Sandwich image from <a href="http://commons.wikimedia.org/wiki/File:Lomito1.jpg">commons.wikimedia.org</a></li>
<li><strong>ps2:</strong> We&#8217;re out of sesame.</li>
<li><strong>ps3:</strong> Sources, <a href="http://silveiraneto.net/downloads/xmlsandwich.tar.bz2">xmlsandwich.tar.bz2</a>.</li>
</ul>
<p></small></p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/12/25/parsing-xml-sandwich-with-javafx/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>JavaFX, Simple Tile Set</title>
		<link>http://silveiraneto.net/2008/12/20/javafx-simple-tile-set/</link>
		<comments>http://silveiraneto.net/2008/12/20/javafx-simple-tile-set/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 19:23:57 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[jfx]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[openjfx]]></category>
		<category><![CDATA[pixel art]]></category>
		<category><![CDATA[Tile Set]]></category>
		<category><![CDATA[tileset]]></category>
		<category><![CDATA[video game]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=1951</guid>
		<description><![CDATA[Tile sets are a very simple way to draw scenarios with repeated elements. From simple to complex ones using a very low footprint. First step, load the png file that stores the tileset into a Image. The file tiles.png shoud be in the same directory of the source code. I adjusted some tiles from those [...]]]></description>
			<content:encoded><![CDATA[<p>Tile sets are a very simple way to draw scenarios with repeated elements. From simple to complex ones using a very low footprint.</p>
<p>First step, load the png file that stores the tileset into a <a title="JavaFX API" href="http://java.sun.com/javafx/1/docs/api/javafx.scene.image/javafx.scene.image.Image.html">Image</a>. The file tiles.png shoud be in the same directory of the source code. I adjusted some tiles from those tile set <a title="Tile set" href="http://silveiraneto.net/2008/08/31/my-free-tileset-version-2/">I&#8217;ve blogged here before</a> into a grid of 10&#215;10 tiles.</p>
<p style="text-align: center;"><img class="size-full wp-image-1955 aligncenter" title="Set of tiles, example" src="http://silveiraneto.net/wp-content/uploads/2008/12/tiles.png" alt="Set of tiles, example" width="320" height="320" /></p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;">var tileset <span style="color: #339933;">=</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>
   url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}tiles.png&quot;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>Notice that each tile have 32 of height and 32 of width. We will assume this and use theses numbers when performing calculations to find a single tile in our tile set.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;">def w <span style="color: #339933;">=</span> <span style="color: #cc66cc;">32</span>;
def h <span style="color: #339933;">=</span> <span style="color: #cc66cc;">32</span>;</pre>
</div>
</div>
<p>To display a Image in the screen we use a <a title="JavaFX API" href="http://java.sun.com/javafx/1/docs/api/javafx.scene.image/javafx.scene.image.ImageView.html">ImageView</a> node. A ImageView can have a viewport property to create crop or zoom effect. A viewport is just a <a href="http://java.sun.com/javafx/1/docs/api/javafx.geometry/javafx.geometry.Rectangle2D.html">Rectangle2D</a>, a object with position (minX and minY), height and width. If we want to display the first tile in the tileset we do</p>
<p style="text-align: center;"><img class="size-full wp-image-1956 aligncenter" title="first tile" src="http://silveiraneto.net/wp-content/uploads/2008/12/first_tile.png" alt="first tile" width="32" height="32" /></p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;">ImageView <span style="color: #009900;">&#123;</span>
   image<span style="color: #339933;">:</span> tileset
   viewport<span style="color: #339933;">:</span> <span style="color: #003399;">Rectangle2D</span><span style="color: #009900;">&#123;</span>
      minX<span style="color: #339933;">:</span> 0, minY<span style="color: #339933;">:</span> 0, height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span>, width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>Notice that the minX determines the column and minY the row in the tileset. The first row is 0*32, the second row is 1*32 and so on. If we want to display the tile at the second line and third column of the tileset we do</p>
<p style="text-align: center;"><img class="size-full wp-image-1957 aligncenter" title="another_tile" src="http://silveiraneto.net/wp-content/uploads/2008/12/another_tile.png" alt="another_tile" width="32" height="32" /></p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;">ImageView <span style="color: #009900;">&#123;</span>
   image<span style="color: #339933;">:</span> tileset
   viewport<span style="color: #339933;">:</span> <span style="color: #003399;">Rectangle2D</span><span style="color: #009900;">&#123;</span>
      minX<span style="color: #339933;">:</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">32</span> , minY<span style="color: #339933;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">32</span>, height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span>, width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>Those properties in a Rectangle2D are for init and read only. So I created a list with all Rectangles I can need for use as a viewport.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;">def viewports <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>row in <span style="color: #009900;">&#91;</span>0..9<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>col in <span style="color: #009900;">&#91;</span>0..9<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #003399;">Rectangle2D</span><span style="color: #009900;">&#123;</span>
           minX<span style="color: #339933;">:</span> col <span style="color: #339933;">*</span> w, minY<span style="color: #339933;">:</span> row <span style="color: #339933;">*</span> h, height<span style="color: #339933;">:</span> w, width<span style="color: #339933;">:</span> h
       <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>The scenario map is stored in another list. The first element of the list is 7, that is, the first tile in the scenario is the 7th tile from the tile set.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;">var map <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
    <span style="color: #cc66cc;">7</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">8</span>,
   <span style="color: #cc66cc;">19</span>, <span style="color: #cc66cc;">26</span>, <span style="color: #cc66cc;">40</span>, <span style="color: #cc66cc;">41</span>, <span style="color: #cc66cc;">24</span>, <span style="color: #cc66cc;">13</span>, <span style="color: #cc66cc;">13</span>, <span style="color: #cc66cc;">23</span>, <span style="color: #cc66cc;">24</span>, <span style="color: #cc66cc;">19</span>,
   <span style="color: #cc66cc;">19</span>, <span style="color: #cc66cc;">36</span>, <span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">51</span>, <span style="color: #cc66cc;">34</span>,  <span style="color: #cc66cc;">2</span>,  <span style="color: #cc66cc;">2</span>,  <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">34</span>, <span style="color: #cc66cc;">19</span>,
   <span style="color: #cc66cc;">19</span>,  <span style="color: #cc66cc;">2</span>,  <span style="color: #cc66cc;">2</span>,  <span style="color: #cc66cc;">2</span>,  <span style="color: #cc66cc;">2</span>,  <span style="color: #cc66cc;">2</span>,  <span style="color: #cc66cc;">2</span>,  <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">25</span>, <span style="color: #cc66cc;">19</span>,
   <span style="color: #cc66cc;">19</span>, <span style="color: #cc66cc;">57</span>, <span style="color: #cc66cc;">58</span>, <span style="color: #cc66cc;">44</span>, <span style="color: #cc66cc;">45</span>, <span style="color: #cc66cc;">46</span>,  <span style="color: #cc66cc;">2</span>,  <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">35</span>, <span style="color: #cc66cc;">19</span>,
   <span style="color: #cc66cc;">27</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">6</span>, <span style="color: #cc66cc;">55</span>, <span style="color: #cc66cc;">56</span>,  <span style="color: #cc66cc;">5</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">38</span>,
   <span style="color: #cc66cc;">19</span>, <span style="color: #cc66cc;">60</span>, <span style="color: #cc66cc;">13</span>, <span style="color: #cc66cc;">16</span>, <span style="color: #cc66cc;">47</span>, <span style="color: #cc66cc;">48</span>, <span style="color: #cc66cc;">15</span>, <span style="color: #cc66cc;">13</span>, <span style="color: #cc66cc;">61</span>, <span style="color: #cc66cc;">19</span>,
   <span style="color: #cc66cc;">19</span>, <span style="color: #cc66cc;">70</span>,  <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">33</span>,  <span style="color: #cc66cc;">1</span>,  <span style="color: #cc66cc;">1</span>,  <span style="color: #cc66cc;">1</span>,  <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">71</span>, <span style="color: #cc66cc;">19</span>,
   <span style="color: #cc66cc;">19</span>,  <span style="color: #cc66cc;">1</span>,  <span style="color: #cc66cc;">1</span>,  <span style="color: #cc66cc;">1</span>,  <span style="color: #cc66cc;">1</span>,  <span style="color: #cc66cc;">1</span>,  <span style="color: #cc66cc;">1</span>,  <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">49</span>, <span style="color: #cc66cc;">19</span>,
   <span style="color: #cc66cc;">17</span>,  <span style="color: #cc66cc;">9</span>,  <span style="color: #cc66cc;">9</span>,  <span style="color: #cc66cc;">9</span>,  <span style="color: #cc66cc;">9</span>,  <span style="color: #cc66cc;">9</span>,  <span style="color: #cc66cc;">9</span>,  <span style="color: #cc66cc;">9</span>,  <span style="color: #cc66cc;">9</span>, <span style="color: #cc66cc;">18</span>,
<span style="color: #009900;">&#93;</span>;</pre>
</div>
</div>
<p>Finally to create a scenario with 100 tiles, 10 per row and with 10 rows, in a list called <em>tiles</em>. Each iteration of this loop creates a <em>ImageView</em>. Each <em>ImageView</em> will store a single tile. We get the tile number in the <em>map</em> list and so use it to index the <em>viewports</em> list.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;">var tiles <span style="color: #339933;">=</span>  <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>row in <span style="color: #009900;">&#91;</span>0..9<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>col in <span style="color: #009900;">&#91;</span>0..9<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      ImageView <span style="color: #009900;">&#123;</span>
         x<span style="color: #339933;">:</span> col <span style="color: #339933;">*</span> w, y<span style="color: #339933;">:</span> row <span style="color: #339933;">*</span> h,
         viewport<span style="color: #339933;">:</span> bind viewports<span style="color: #009900;">&#91;</span>map<span style="color: #009900;">&#91;</span>row <span style="color: #339933;">*</span> <span style="color: #cc66cc;">10</span> <span style="color: #339933;">+</span> col<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span>
         image<span style="color: #339933;">:</span> tileset
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>Additionally I added two things to transform this program also in a (extremely)  simple map editor. At each <em>ImageView</em> I added a callback for <em>onMouseClicked</em> event. When you click on a tile, it changes its <em>map</em> position, ie, the tile. The next tile for the left button and the last tile for any other button.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;">onMouseClicked<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span> e<span style="color: #339933;">:</span> <span style="color: #003399;">MouseEvent</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Void</span> <span style="color: #009900;">&#123;</span>
   var amount <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">button</span> <span style="color: #339933;">==</span> MouseButton.<span style="color: #006633;">PRIMARY</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#125;</span>;
   map<span style="color: #009900;">&#91;</span>row <span style="color: #339933;">*</span> <span style="color: #cc66cc;">10</span> <span style="color: #339933;">+</span> col<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>map<span style="color: #009900;">&#91;</span>row <span style="color: #339933;">*</span> <span style="color: #cc66cc;">10</span> <span style="color: #339933;">+</span> col<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> amount<span style="color: #009900;">&#41;</span> mod <span style="color: #cc66cc;">100</span>;
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>The other thing is to print the <em>map</em> list when the program is over. There is the full program:</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">tileeditor</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.stage.Stage</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.Scene</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.image.ImageView</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.image.Image</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.CustomNode</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.Group</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.Node</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.geometry.Rectangle2D</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.input.MouseEvent</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.input.MouseButton</span>;
&nbsp;
def w <span style="color: #339933;">=</span> <span style="color: #cc66cc;">32</span>;
def h <span style="color: #339933;">=</span> <span style="color: #cc66cc;">32</span>;
&nbsp;
var map <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
    <span style="color: #cc66cc;">7</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">8</span>,
   <span style="color: #cc66cc;">19</span>, <span style="color: #cc66cc;">26</span>, <span style="color: #cc66cc;">40</span>, <span style="color: #cc66cc;">41</span>, <span style="color: #cc66cc;">24</span>, <span style="color: #cc66cc;">13</span>, <span style="color: #cc66cc;">13</span>, <span style="color: #cc66cc;">23</span>, <span style="color: #cc66cc;">24</span>, <span style="color: #cc66cc;">19</span>,
   <span style="color: #cc66cc;">19</span>, <span style="color: #cc66cc;">36</span>, <span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">51</span>, <span style="color: #cc66cc;">34</span>,  <span style="color: #cc66cc;">2</span>,  <span style="color: #cc66cc;">2</span>,  <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">34</span>, <span style="color: #cc66cc;">19</span>,
   <span style="color: #cc66cc;">19</span>,  <span style="color: #cc66cc;">2</span>,  <span style="color: #cc66cc;">2</span>,  <span style="color: #cc66cc;">2</span>,  <span style="color: #cc66cc;">2</span>,  <span style="color: #cc66cc;">2</span>,  <span style="color: #cc66cc;">2</span>,  <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">25</span>, <span style="color: #cc66cc;">19</span>,
   <span style="color: #cc66cc;">19</span>, <span style="color: #cc66cc;">57</span>, <span style="color: #cc66cc;">58</span>, <span style="color: #cc66cc;">44</span>, <span style="color: #cc66cc;">45</span>, <span style="color: #cc66cc;">46</span>,  <span style="color: #cc66cc;">2</span>,  <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">35</span>, <span style="color: #cc66cc;">19</span>,
   <span style="color: #cc66cc;">27</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">6</span>, <span style="color: #cc66cc;">55</span>, <span style="color: #cc66cc;">56</span>,  <span style="color: #cc66cc;">5</span>,  <span style="color: #cc66cc;">3</span>,  <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">38</span>,
   <span style="color: #cc66cc;">19</span>, <span style="color: #cc66cc;">60</span>, <span style="color: #cc66cc;">13</span>, <span style="color: #cc66cc;">16</span>, <span style="color: #cc66cc;">47</span>, <span style="color: #cc66cc;">48</span>, <span style="color: #cc66cc;">15</span>, <span style="color: #cc66cc;">13</span>, <span style="color: #cc66cc;">61</span>, <span style="color: #cc66cc;">19</span>,
   <span style="color: #cc66cc;">19</span>, <span style="color: #cc66cc;">70</span>,  <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">33</span>,  <span style="color: #cc66cc;">1</span>,  <span style="color: #cc66cc;">1</span>,  <span style="color: #cc66cc;">1</span>,  <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">71</span>, <span style="color: #cc66cc;">19</span>,
   <span style="color: #cc66cc;">19</span>,  <span style="color: #cc66cc;">1</span>,  <span style="color: #cc66cc;">1</span>,  <span style="color: #cc66cc;">1</span>,  <span style="color: #cc66cc;">1</span>,  <span style="color: #cc66cc;">1</span>,  <span style="color: #cc66cc;">1</span>,  <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">49</span>, <span style="color: #cc66cc;">19</span>,
   <span style="color: #cc66cc;">17</span>,  <span style="color: #cc66cc;">9</span>,  <span style="color: #cc66cc;">9</span>,  <span style="color: #cc66cc;">9</span>,  <span style="color: #cc66cc;">9</span>,  <span style="color: #cc66cc;">9</span>,  <span style="color: #cc66cc;">9</span>,  <span style="color: #cc66cc;">9</span>,  <span style="color: #cc66cc;">9</span>, <span style="color: #cc66cc;">18</span>,
<span style="color: #009900;">&#93;</span>;
&nbsp;
var tileset <span style="color: #339933;">=</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>
    url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}tiles.png&quot;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
def viewports <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>row in <span style="color: #009900;">&#91;</span>0..9<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>col in <span style="color: #009900;">&#91;</span>0..9<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #003399;">Rectangle2D</span><span style="color: #009900;">&#123;</span>
           minX<span style="color: #339933;">:</span> col <span style="color: #339933;">*</span> w, minY<span style="color: #339933;">:</span> row <span style="color: #339933;">*</span> h, height<span style="color: #339933;">:</span> w, width<span style="color: #339933;">:</span> h
       <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
var tiles <span style="color: #339933;">=</span>  <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>row in <span style="color: #009900;">&#91;</span>0..9<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>col in <span style="color: #009900;">&#91;</span>0..9<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      ImageView <span style="color: #009900;">&#123;</span>
         x<span style="color: #339933;">:</span> col <span style="color: #339933;">*</span> w, y<span style="color: #339933;">:</span> row <span style="color: #339933;">*</span> h,
         viewport<span style="color: #339933;">:</span> bind viewports<span style="color: #009900;">&#91;</span>map<span style="color: #009900;">&#91;</span>row <span style="color: #339933;">*</span> <span style="color: #cc66cc;">10</span> <span style="color: #339933;">+</span> col<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span>
         image<span style="color: #339933;">:</span> tileset
&nbsp;
         onMouseClicked<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span> e<span style="color: #339933;">:</span> <span style="color: #003399;">MouseEvent</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Void</span> <span style="color: #009900;">&#123;</span>
            var amount <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">button</span> <span style="color: #339933;">==</span> MouseButton.<span style="color: #006633;">PRIMARY</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#125;</span>;
            map<span style="color: #009900;">&#91;</span>row <span style="color: #339933;">*</span> <span style="color: #cc66cc;">10</span> <span style="color: #339933;">+</span> col<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>map<span style="color: #009900;">&#91;</span>row <span style="color: #339933;">*</span> <span style="color: #cc66cc;">10</span> <span style="color: #339933;">+</span> col<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> amount<span style="color: #009900;">&#41;</span> mod <span style="color: #cc66cc;">100</span>;
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
Stage <span style="color: #009900;">&#123;</span>
    title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;JavaFX Simple Tile Editor&quot;</span>
    scene<span style="color: #339933;">:</span> Scene <span style="color: #009900;">&#123;</span>
        content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span> tiles <span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#125;</span>
    onClose<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        println<span style="color: #009900;">&#40;</span>map<span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>Here is the result for that<em> map</em></p>
<p style="text-align: center;"><img class="size-full wp-image-1961 aligncenter" title="tlemap javafx" src="http://silveiraneto.net/wp-content/uploads/2008/12/tilemap_javafx.png" alt="tlemap javafx" width="320" height="320" /></p>
<p>And you can try it yourself in your browser.<strong> <a title="Simple Tile Editor Online" href="http://silveiraneto.net/downloads/SimpleTileEditor/dist/JavaFxSandBox.html">Play it online now</a></strong>.</p>
<p>Here is a video of it working</p>
<p style="text-align: center;"><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/lxuBEoItB5E&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/lxuBEoItB5E&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></object></p>
<p><strong>Downloads:</strong></p>
<ul>
<li>Complete source code and project in NetBeans, <a title="Simple Tile Editor" href="http://silveiraneto.net/downloads/SimpleTileEditor.tar.bz2">SimpleTileEditor.tar.bz2</a>.</li>
<li>Video of it working, <a title="OGG Video" href="http://silveiraneto.net/downloads/javafx_tile_set.ogv">javafx_tile_set.ogv</a>.</li>
<li>Program main class, <a title="Main class" href="http://silveiraneto.net/downloads/SimpleTileEditor/src/tileeditor/Main.fx">Main.fx</a>.</li>
</ul>
<p><strong>Possibilities</strong></p>
<p>We are using just  a image that can handle 100 tiles, <a href="ttp://silveiraneto.net/wp-content/uploads/2008/12/tiles.png">tiles.png</a> with less than 30Kb. The map is also composed with 100 tiles. Each tile we can choose between 100 different tiles, so we can compose 10<sup>100</sup> different maps (one <a title="Wikipedia, english" href="http://en.wikipedia.org/wiki/Googol">googol</a><sup>10</sup> ). Most of them are useless and without any sense, but some are cool. :)</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/12/20/javafx-simple-tile-set/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NetBeans with JavaFX 1.0 on Linux</title>
		<link>http://silveiraneto.net/2008/12/18/netbeans-with-javafx-10-on-linux/</link>
		<comments>http://silveiraneto.net/2008/12/18/netbeans-with-javafx-10-on-linux/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 03:58:57 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[jfx]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[lolcat]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[openjfx]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=1941</guid>
		<description><![CDATA[Following Weiqi Gao&#8217;s steps it&#8217;s possible to already have a complete JavaFX development environment on Linux. It&#8217;s all there for JavaFX development. Code complementation, live preview, the pallet with code snipets, templates, etc. Easier a lot my work. Those features already availiable on Windows and Mac OS X trought the regular JavaFX Kit.]]></description>
			<content:encoded><![CDATA[<p>Following <a title="JavaFX NetBeans Linux" href="http://www.weiqigao.com/blog/2008/12/11/javafx_1_0_on_linux_netbeans_plugin.html">Weiqi Gao&#8217;s steps</a> it&#8217;s possible to already have a complete JavaFX development environment on Linux.</p>
<p><center><a href="http://silveiraneto.net/wp-content/uploads/2008/12/netbeans_linux_javafx.png"><img class="aligncenter size-medium wp-image-1942" title="netbeans_linux_javafx" src="http://silveiraneto.net/wp-content/uploads/2008/12/netbeans_linux_javafx-500x312.png" alt="netbeans_linux_javafx" width="500" height="312" /></a></center></p>
<p>It&#8217;s all there for JavaFX development. Code complementation, live preview, the pallet with code snipets, templates, etc. Easier a lot my work. Those features already availiable on Windows and Mac OS X trought the <a title="JavaFX Download" href="http://javafx.com/downloads/all.jsp">regular JavaFX Kit</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/12/18/netbeans-with-javafx-10-on-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaFX, how to create a rpg like game</title>
		<link>http://silveiraneto.net/2008/12/08/javafx-how-to-create-a-rpg-like-game/</link>
		<comments>http://silveiraneto.net/2008/12/08/javafx-how-to-create-a-rpg-like-game/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 07:38:04 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[applet]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Web Start]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[jfx]]></category>
		<category><![CDATA[ogv]]></category>
		<category><![CDATA[openjfx]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=1861</guid>
		<description><![CDATA[JavaFX 1.0 is out and there are tons of new cool features, specially for game development.trans I&#8217;ll show in this tutorial how to create a very simple demo that shows how to load imtrages, handle sprites, collisions and keyboard events that you can use to create a game with a old school rpg like vision. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://javafx.com">JavaFX 1.0</a> is out and there are tons of new cool features, specially for game development.trans</p>
<p>I&#8217;ll show in this tutorial how to create a very simple demo that shows how to load imtrages, handle sprites, collisions and keyboard events that you can use to create a game with a old school rpg like vision.</p>
<p>For the background scenario I&#8217;m using the house <a title="My Free Tileset version 2" href="http://silveiraneto.net/2008/08/31/my-free-tileset-version-2/">that I drew</a> and we&#8217;ll call as <strong>house.png</strong>.</p>
<p style="text-align: center;"><a title="Pixelart home" href="http://silveiraneto.net/wp-content/uploads/2008/08/silveira_neto_gpl_pixelart_kitchen_home1.png"><img class="size-full wp-image-1190 aligncenter" title="House pixelart free GPL" src="../wp-content/uploads/2008/08/silveira_neto_gpl_pixelart_kitchen_home1.png" alt="" width="416" height="384" /></a></p>
<p>That we load as a <a title="JavaFX API" href="http://java.sun.com/javafx/1/docs/api/javafx.scene.image/javafx.scene.image.Image.html">Image</a> and place into a <a title="JavaFX API" href="http://java.sun.com/javafx/1/docs/api/javafx.scene.image/javafx.scene.image.ImageView.html">ImageView</a>.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;">ImageView<span style="color: #009900;">&#123;</span>
   image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}house.png&quot;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>For the character I&#8217;m using the last character I drew, <a title="The Nerdy Guy" href="http://silveiraneto.net/2008/12/07/nerdy-guy-my-free-charset-version-2/">the nerdy guy</a>.</p>
<p style="text-align: center;"><img class="size-full wp-image-1863 aligncenter" title="nerdyguy creative commons att share alike" src="../wp-content/uploads/2008/12/nerdyguy_from_silveiranetonet_creativecommons_att_share_alike.png" alt="" width="101" height="183" /></p>
<p>To make the animation easier, I spited it into 9 pieces:</p>
<p><strong>down0.png</strong>, <strong>down1.png</strong> and <strong>down2.png</strong></p>
<p><a href="http://silveiraneto.net/wp-content/uploads/2008/12/down0.png"><img class="alignnone size-full wp-image-1867" title="down0" src="http://silveiraneto.net/wp-content/uploads/2008/12/down0.png" alt="" width="30" height="39" /></a> <a href="http://silveiraneto.net/wp-content/uploads/2008/12/down1.png"><img class="alignnone size-full wp-image-1868" title="down1" src="http://silveiraneto.net/wp-content/uploads/2008/12/down1.png" alt="" width="30" height="39" /></a> <a href="http://silveiraneto.net/wp-content/uploads/2008/12/down2.png"><img class="alignnone size-full wp-image-1869" title="down2" src="http://silveiraneto.net/wp-content/uploads/2008/12/down2.png" alt="" width="30" height="39" /></a></p>
<p><strong>left0.png</strong>, <strong>left1.png</strong> and <strong>left2.png</strong></p>
<p><a href="http://silveiraneto.net/wp-content/uploads/2008/12/left0.png"><img class="alignnone size-full wp-image-1874" title="left0" src="http://silveiraneto.net/wp-content/uploads/2008/12/left0.png" alt="" width="30" height="39" /></a> <a href="http://silveiraneto.net/wp-content/uploads/2008/12/left1.png"><img class="alignnone size-full wp-image-1875" title="left1" src="http://silveiraneto.net/wp-content/uploads/2008/12/left1.png" alt="" width="30" height="39" /></a> <a href="http://silveiraneto.net/wp-content/uploads/2008/12/left2.png"><img class="alignnone size-full wp-image-1876" title="left2" src="http://silveiraneto.net/wp-content/uploads/2008/12/left2.png" alt="" width="30" height="39" /></a></p>
<p><strong>right0.png</strong>, <strong>right1.png</strong> and <strong>righ2.png</strong></p>
<p><a href="http://silveiraneto.net/wp-content/uploads/2008/12/right0.png"><img class="alignnone size-full wp-image-1872" title="right0" src="http://silveiraneto.net/wp-content/uploads/2008/12/right0.png" alt="" width="30" height="40" /></a> <a href="http://silveiraneto.net/wp-content/uploads/2008/12/right1.png"><img class="alignnone size-full wp-image-1873" title="right1" src="http://silveiraneto.net/wp-content/uploads/2008/12/right1.png" alt="" width="30" height="40" /></a> <a href="http://silveiraneto.net/wp-content/uploads/2008/12/right2.png"><img class="alignnone size-medium wp-image-1872" title="right2" src="http://silveiraneto.net/wp-content/uploads/2008/12/right2.png" alt="" width="30" height="40" /></a></p>
<p><strong>up0.png</strong>,<strong> up1.png </strong>and <strong>up2.png</strong></p>
<p><a href="http://silveiraneto.net/wp-content/uploads/2008/12/up0.png"><img class="alignnone size-full wp-image-1877" title="up0" src="http://silveiraneto.net/wp-content/uploads/2008/12/up0.png" alt="" width="30" height="40" /></a> <a href="http://silveiraneto.net/wp-content/uploads/2008/12/up1.png"><img class="alignnone size-full wp-image-1878" title="up1" src="http://silveiraneto.net/wp-content/uploads/2008/12/up1.png" alt="" width="30" height="40" /></a> <a href="http://silveiraneto.net/wp-content/uploads/2008/12/up2.png"><img class="alignnone size-full wp-image-1879" title="up2" src="http://silveiraneto.net/wp-content/uploads/2008/12/up2.png" alt="" width="30" height="40" /></a></p>
<blockquote><p><img class="alignnone size-full wp-image-1881" title="warning" src="http://silveiraneto.net/wp-content/uploads/2008/12/dialog-warning.png" alt="" width="16" height="16" /> All images I&#8217;m using should be in the same directory of source code.</p></blockquote>
<p>Let&#8217;s start loading the scenario and a single character sprite.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.stage.Stage</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.Scene</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.image.*</span>;
&nbsp;
Stage <span style="color: #009900;">&#123;</span>
   title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;RPG-like demo&quot;</span>, width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">424</span>, height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">412</span>
   visible<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>
   scene<span style="color: #339933;">:</span> Scene<span style="color: #009900;">&#123;</span>
      content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
         ImageView<span style="color: #009900;">&#123;</span>
         image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}house.png&quot;</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>,
         ImageView<span style="color: #009900;">&#123;</span>
            x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">320</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">80</span>
            image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}down1.png&quot;</span><span style="color: #009900;">&#125;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#93;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>Saved as Game.fx you can compile and run with in your terminal:</p>
<blockquote><p>$ javafxc Game.fx</p>
<p>$ javafx Game</p></blockquote>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2008/12/screenshot1.png"><img class="size-full wp-image-1883 aligncenter" title="javafx rpg like game demo" src="http://silveiraneto.net/wp-content/uploads/2008/12/screenshot1.png" alt="" width="451" height="433" /></a></p>
<blockquote><p><img class="alignnone size-full wp-image-1881" title="warning" src="http://silveiraneto.net/wp-content/uploads/2008/12/dialog-warning.png" alt="" width="16" height="16" /> <strong>Hint:</strong> You can use <a title="JavaFX Downloads" href="http://javafx.com/downloads">NetBeans 6.5 JavaFX plugin</a> to easier the JavaFX development.</p></blockquote>
<p>To put animation on the character we load all sprites into four lists. Each list for each direction.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// sprites</span>
def up    <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i in <span style="color: #009900;">&#91;</span>0..2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}up{i}.png&quot;</span>    <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>
def right <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i in <span style="color: #009900;">&#91;</span>0..2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}right{i}.png&quot;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>
def down  <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i in <span style="color: #009900;">&#91;</span>0..2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}down{i}.png&quot;</span>  <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>
def left  <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i in <span style="color: #009900;">&#91;</span>0..2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}left{i}.png&quot;</span>  <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>And create vars to store the character position and frame of animation.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;">var frame <span style="color: #339933;">=</span> 0;
var posx <span style="color: #339933;">=</span> <span style="color: #cc66cc;">320</span>;
var posy <span style="color: #339933;">=</span> <span style="color: #cc66cc;">80</span>;</pre>
</div>
</div>
<p>Also store the house background.</p>
<pre>// house background
def house = ImageView{ image: Image {url: "{__DIR__}house.png"} };</pre>
<p>I create booleans to store some key states and at each interval of time I see how they are and do something about. You can handle keyboard event with less code but I like this way because keep visual and game logics a little bit more separated.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// keyboard</span>
var    upkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>;
var rightkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>;
var  downkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>;
var  leftkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// player</span>
var player <span style="color: #339933;">=</span> ImageView<span style="color: #009900;">&#123;</span>
   x<span style="color: #339933;">:</span> bind posx y<span style="color: #339933;">:</span> bind posy
   image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}down1.png&quot;</span><span style="color: #009900;">&#125;</span>
   onKeyPressed<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span><span style="color: #003399;">KeyEvent</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_DOWN</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      downkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span>;
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_UP</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         upkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span>;
      <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_LEFT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         leftkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span>;
      <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_RIGHT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         rightkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span>;
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// onKeyPressed</span>
&nbsp;
   onKeyReleased<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span> <span style="color: #003399;">KeyEvent</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_DOWN</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         downkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>;
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_UP</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         upkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>;
      <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_LEFT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         leftkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>;
      <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_RIGHT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         rightkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>;
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// onKeyReleased</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>See a video of the game working so far:</p>
<p style="text-align: center;"><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/Xv5z-9LGuOc&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/Xv5z-9LGuOc&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></object></p>
<p>Now we will add collisions. In a <a href="http://silveiraneto.net/2008/10/30/javafx-rectangular-collision-detection/">previous post</a> I showed some math behind bounding box game collisions. The good news are that you no longer need to worry about that. There are a lot of API improvements in JavaFX 1.0 that do all the hard work for you, specially the new classes on javafx.geometry package, <a href="http://java.sun.com/javafx/1/docs/api/javafx.geometry/javafx.geometry.Rectangle2D.html">Rectangle2D</a> and <a href="http://java.sun.com/javafx/1/docs/api/javafx.geometry/javafx.geometry.Point2D.html">Point2D</a>.</p>
<p>We create rectangles that represent the obstacles in the house.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// collidable obstacles</span>
def obstacles <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>   0 y<span style="color: #339933;">:</span>   0 width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">382</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>   0 y<span style="color: #339933;">:</span>   0 width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">414</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">384</span> y<span style="color: #339933;">:</span>   0 width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">382</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>   0 y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">224</span> y<span style="color: #339933;">:</span>   0 width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">288</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">288</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">96</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>   0 y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">352</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">352</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">224</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">320</span> width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">96</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">250</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">250</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">200</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">255</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">200</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">170</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">257</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">288</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">320</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">352</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">295</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">60</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">327</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">23</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
<span style="color: #009900;">&#93;</span>;</pre>
</div>
</div>
<p style="text-align: center;"><img class="size-full wp-image-1887 aligncenter" title="bounding boxes" src="http://silveiraneto.net/wp-content/uploads/2008/12/boundingboxes.png" alt="" width="416" height="384" /></p>
<p>We just have to change a little bit the game logics in order to handle collisions.</p>
<p style="text-align: center;"><img class="size-full wp-image-1889 aligncenter" title="boudingbox" src="http://silveiraneto.net/wp-content/uploads/2008/12/boudingbox.png" alt="" width="200" height="260" /></p>
<p>We define a bounding box around the player, it&#8217;s a rectangle from (4, 25) at the player coordinates system and with width 19 and height 10. The idea is to prospect where the player will be in the next step, see if it&#8217;s bouding box don&#8217;t collide with any obstacle and so pass it to the real game position.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// game logics</span>
var gamelogics <span style="color: #339933;">=</span> Timeline <span style="color: #009900;">&#123;</span>
   repeatCount<span style="color: #339933;">:</span> Timeline.<span style="color: #006633;">INDEFINITE</span>
   keyFrames<span style="color: #339933;">:</span> KeyFrame <span style="color: #009900;">&#123;</span>
      time <span style="color: #339933;">:</span> 1s<span style="color: #339933;">/</span><span style="color: #cc66cc;">8</span>
      action<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         var nextposx <span style="color: #339933;">=</span> posx;
         var nextposy <span style="color: #339933;">=</span> posy;
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>downkey<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            nextposy <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">5</span>;
            player.<span style="color: #006633;">image</span> <span style="color: #339933;">=</span> down<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>frame mod <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span>;
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>upkey<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            nextposy <span style="color: #339933;">-=</span> <span style="color: #cc66cc;">5</span>;
            player.<span style="color: #006633;">image</span> <span style="color: #339933;">=</span> up<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>frame mod <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span>;
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>rightkey<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            nextposx <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">5</span>;
            player.<span style="color: #006633;">image</span> <span style="color: #339933;">=</span> right<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>frame mod <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span>;
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>leftkey<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            nextposx <span style="color: #339933;">-=</span> <span style="color: #cc66cc;">5</span>;
            player.<span style="color: #006633;">image</span> <span style="color: #339933;">=</span> left<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>frame mod <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span>;
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>obst in obstacles<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>obst.<span style="color: #006633;">boundsInLocal</span>.<span style="color: #006633;">intersects</span><span style="color: #009900;">&#40;</span>nextposx <span style="color: #339933;">+</span> <span style="color: #cc66cc;">4</span>, nextposy <span style="color: #339933;">+</span> <span style="color: #cc66cc;">25</span>, <span style="color: #cc66cc;">19</span>, <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #000000; font-weight: bold;">return</span>;
            <span style="color: #009900;">&#125;</span>
         <span style="color: #009900;">&#125;</span>
         posx <span style="color: #339933;">=</span> nextposx;
         posy <span style="color: #339933;">=</span> nextposy;
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>This is enough to do the trick but I also added a way to smoothly show the obstacles when pressing the space key.</p>
<p style="text-align: center;"><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/k-MHh6irvwE&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/k-MHh6irvwE&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></object></p>
<p>Here is the complete source code.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">Game</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.stage.Stage</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.*</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.image.*</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.input.*</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.paint.*</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.shape.*</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.animation.*</span>;
&nbsp;
var frame <span style="color: #339933;">=</span> 0;
var posx <span style="color: #339933;">=</span> <span style="color: #cc66cc;">320</span>;
var posy <span style="color: #339933;">=</span> <span style="color: #cc66cc;">80</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// sprites</span>
def up    <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i in <span style="color: #009900;">&#91;</span>0..2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}up{i}.png&quot;</span>    <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>
def right <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i in <span style="color: #009900;">&#91;</span>0..2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}right{i}.png&quot;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>
def down  <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i in <span style="color: #009900;">&#91;</span>0..2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}down{i}.png&quot;</span>  <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>
def left  <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i in <span style="color: #009900;">&#91;</span>0..2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}left{i}.png&quot;</span>  <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// house background</span>
def house <span style="color: #339933;">=</span> ImageView<span style="color: #009900;">&#123;</span> image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}house.png&quot;</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// keyboard</span>
var    upkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>;
var rightkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>;
var  downkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>;
var  leftkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// player</span>
var player <span style="color: #339933;">=</span> ImageView<span style="color: #009900;">&#123;</span>
   x<span style="color: #339933;">:</span> bind posx y<span style="color: #339933;">:</span> bind posy image<span style="color: #339933;">:</span> down<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span>
   onKeyPressed<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span><span style="color: #003399;">KeyEvent</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_DOWN</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         downkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span>;
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_UP</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         upkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span>;
      <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_LEFT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         leftkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span>;
      <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_RIGHT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         rightkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span>;
      <span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_SPACE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>fade<span style="color: #339933;">==</span><span style="color: #cc66cc;">0.0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         	fadein.<span style="color: #006633;">playFromStart</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>fade<span style="color: #339933;">==</span><span style="color: #cc66cc;">1.0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				fadeout.<span style="color: #006633;">playFromStart</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// onKeyPressed</span>
&nbsp;
   onKeyReleased<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span> <span style="color: #003399;">KeyEvent</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_DOWN</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         downkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>;
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_UP</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         upkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>;
      <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_LEFT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         leftkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>;
      <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_RIGHT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         rightkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>;
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// onKeyReleased</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// collidable obstacles</span>
def obstacles <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>   0 y<span style="color: #339933;">:</span>   0 width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">382</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>   0 y<span style="color: #339933;">:</span>   0 width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">414</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">384</span> y<span style="color: #339933;">:</span>   0 width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">382</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>   0 y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">224</span> y<span style="color: #339933;">:</span>   0 width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">288</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">288</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">96</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>   0 y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">352</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">352</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">224</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">320</span> width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">96</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">250</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">250</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">200</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">255</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">200</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">170</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">257</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">288</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">320</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">352</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">295</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">60</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">327</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">23</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
<span style="color: #009900;">&#93;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// game logics</span>
var gamelogics <span style="color: #339933;">=</span> Timeline <span style="color: #009900;">&#123;</span>
   repeatCount<span style="color: #339933;">:</span> Timeline.<span style="color: #006633;">INDEFINITE</span>
   keyFrames<span style="color: #339933;">:</span> KeyFrame <span style="color: #009900;">&#123;</span>
      time <span style="color: #339933;">:</span> 1s<span style="color: #339933;">/</span><span style="color: #cc66cc;">8</span>
      action<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         var nextposx <span style="color: #339933;">=</span> posx;
         var nextposy <span style="color: #339933;">=</span> posy;
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>downkey<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            nextposy <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">5</span>;
            player.<span style="color: #006633;">image</span> <span style="color: #339933;">=</span> down<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>frame mod <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span>;
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>upkey<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            nextposy <span style="color: #339933;">-=</span> <span style="color: #cc66cc;">5</span>;
            player.<span style="color: #006633;">image</span> <span style="color: #339933;">=</span> up<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>frame mod <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span>;
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>rightkey<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            nextposx <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">5</span>;
            player.<span style="color: #006633;">image</span> <span style="color: #339933;">=</span> right<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>frame mod <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span>;
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>leftkey<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            nextposx <span style="color: #339933;">-=</span> <span style="color: #cc66cc;">5</span>;
            player.<span style="color: #006633;">image</span> <span style="color: #339933;">=</span> left<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>frame mod <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span>;
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>obst in obstacles<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>obst.<span style="color: #006633;">boundsInLocal</span>.<span style="color: #006633;">intersects</span><span style="color: #009900;">&#40;</span>nextposx <span style="color: #339933;">+</span> <span style="color: #cc66cc;">4</span>, nextposy <span style="color: #339933;">+</span> <span style="color: #cc66cc;">25</span>, <span style="color: #cc66cc;">19</span>, <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #000000; font-weight: bold;">return</span>;
            <span style="color: #009900;">&#125;</span>
         <span style="color: #009900;">&#125;</span>
         posx <span style="color: #339933;">=</span> nextposx;
         posy <span style="color: #339933;">=</span> nextposy;
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
gamelogics.<span style="color: #006633;">play</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// obstacles view</span>
var fade <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.0</span>;
&nbsp;
var obstacleslayer <span style="color: #339933;">=</span> <span style="color: #003399;">Group</span> <span style="color: #009900;">&#123;</span>
   opacity<span style="color: #339933;">:</span> bind fade
   content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
      <span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>0 y<span style="color: #339933;">:</span>0 width<span style="color: #339933;">:</span><span style="color: #cc66cc;">500</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">500</span> fill<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">BLACK</span> <span style="color: #009900;">&#125;</span>,
      obstacles,
      <span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span>
        x<span style="color: #339933;">:</span> bind posx <span style="color: #339933;">+</span> <span style="color: #cc66cc;">4</span> y<span style="color: #339933;">:</span> bind posy <span style="color: #339933;">+</span> <span style="color: #cc66cc;">25</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">19</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span>
        fill<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">LIME</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
var fadein <span style="color: #339933;">=</span> Timeline <span style="color: #009900;">&#123;</span>
	keyFrames<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
   	at <span style="color: #009900;">&#40;</span>0s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>fade <span style="color: #339933;">=&amp;</span>gt; <span style="color: #cc66cc;">0.0</span><span style="color: #009900;">&#125;</span>
   	at <span style="color: #009900;">&#40;</span>1s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>fade <span style="color: #339933;">=&amp;</span>gt; <span style="color: #cc66cc;">1.0</span><span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
var fadeout <span style="color: #339933;">=</span> Timeline <span style="color: #009900;">&#123;</span>
	keyFrames<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
   	at <span style="color: #009900;">&#40;</span>0s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>fade <span style="color: #339933;">=&amp;</span>gt; <span style="color: #cc66cc;">1.0</span><span style="color: #009900;">&#125;</span>
   	at <span style="color: #009900;">&#40;</span>1s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>fade <span style="color: #339933;">=&amp;</span>gt; <span style="color: #cc66cc;">0.0</span><span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// game stage</span>
Stage <span style="color: #009900;">&#123;</span>
	title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;RPG-like demo&quot;</span>, width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">424</span>, height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">412</span>
	visible<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>
	scene<span style="color: #339933;">:</span> Scene<span style="color: #009900;">&#123;</span>
      fill<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">BLACK</span>
		content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>house, player, obstacleslayer<span style="color: #009900;">&#93;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p><strong>Play Through Java Web Start<br />
</strong></p>
<p style="text-align: center;"><a title="Click to launch" href="http://silveiraneto.net/downloads/nerdy/dist/Nerdy.jnlp"><img class="size-full wp-image-1474 aligncenter" title="webstart" src="../wp-content/uploads/2008/10/webstart.png" alt="" width="88" height="23" /></a></p>
<p>or <a title="Applet Game" href="http://silveiraneto.net/downloads/nerdy/dist/Nerdy.html">click here to play via applet</a>, inside your browser.</p>
<p><small><strong>update: </strong>The applet version and Java Web Start versions should be working now.  The applet version on Linux seems to be having problems with the keyboard handling, use the Java Web Start version while I&#8217;m trying to fix it.</small></p>
<p><strong>Downloads:</strong></p>
<ul>
<li>Source, images and jars, <a title="Zipball with sources and images" href="http://silveiraneto.net/downloads/nerdy.zip">nerdy.zip</a></li>
<li><a title="Nerdy Game" href="http://silveiraneto.net/downloads/nerdy/">All content</a></li>
<li>First video, <a title="OGG Video" href="http://silveiraneto.net/downloads/javafx_nerdy_without_collision.ogv">javafx_nerdy_without_collision.ogv</a></li>
<li>Second video, <a title="OGG Video" href="http://silveiraneto.net/downloads/javafx_nerdy.ogv">javafx_nerdy.ogv</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/12/08/javafx-how-to-create-a-rpg-like-game/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>JavaFX SDK 1.0 on Linux</title>
		<link>http://silveiraneto.net/2008/12/06/javafx-sdk-10-on-linux/</link>
		<comments>http://silveiraneto.net/2008/12/06/javafx-sdk-10-on-linux/#comments</comments>
		<pubDate>Sat, 06 Dec 2008 07:15:35 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[jfx]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[openjfx]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[unofficial]]></category>
		<category><![CDATA[vídeo]]></category>
		<category><![CDATA[Weiqi Gao]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=1853</guid>
		<description><![CDATA[JavaFX 1.0 is out and is absolutely amazing. You guys did really a great work on it. As I really need a working SDK on Linux to continue to study and I don&#8217;t have any Windows/Mac near me, I&#8217;m using the Weiqi Gao&#8217;s workaround. I tried to simplify a little bit more the process for [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://javafx.com">JavaFX 1.0</a> is out and is absolutely amazing. You guys did really a great work on it.</p>
<p style="text-align: center;"><a title="JavaFX Site" href="http://javafx.com"><img class="size-full wp-image-1854 aligncenter" title="javafx site" src="http://silveiraneto.net/wp-content/uploads/2008/12/javafxsite.png" alt="" width="400" height="311" /></a></p>
<p>As I really need a working SDK on Linux to continue to study and I don&#8217;t have any Windows/Mac near me, I&#8217;m using the <a title="Weiqigao Blog" href="http://www.weiqigao.com/blog/2008/08/05/watch_javafx_sdk_run_on_linux.html">Weiqi Gao&#8217;s workaround</a>. I tried to simplify a little bit more the process for those who need JavaFX SDK working on Linux right now.</p>
<p><strong>Download</strong> <a title="JavaFX for Linux" href="http://silveiraneto.net/downloads/javafxsdk_linux_unofficial.tar.bz2">javafxsdk_linux_unofficial.tar.bz2</a> (~18Mb).</p>
<p>And then</p>
<blockquote><p>tar -xjvf javafxsdk_linux_unofficial.tar.bz2<br />
sudo cp javafx /opt/javafx<br />
echo &#8220;PATH=\$PATH:/opt/javafx/bin&#8221; &gt;&gt; ~/.profile<br />
echo &#8220;JAVAFX_HOME=/opt/javafx&#8221; &gt;&gt; ~/.profile<br />
source ~/.profile</p></blockquote>
<p>Now you can call javafx, javafxc, javafxdoc and javafxpackager from your terminal. Don&#8217;t forget that you need Java 1.6 or greater installed.</p>
<p>Here&#8217;s a video showing the SDK working, I&#8217;m compiling and running two sample applications. Remeber that as a temporary unofficial port for Linux, there&#8217;s not native video support nor hardware acceleration.</p>
<p style="text-align: center;"><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/ENf5mXEIiD8&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/ENf5mXEIiD8&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></object></p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/12/06/javafx-sdk-10-on-linux/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>JavaFX, rectangular collision detection</title>
		<link>http://silveiraneto.net/2008/10/30/javafx-rectangular-collision-detection/</link>
		<comments>http://silveiraneto.net/2008/10/30/javafx-rectangular-collision-detection/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 15:26:36 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[jfx]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[openjfx]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rectangle collision]]></category>
		<category><![CDATA[rectangular collision]]></category>
		<category><![CDATA[rectangular collision detection]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=1629</guid>
		<description><![CDATA[In a game I wrote some years ago we handled simple rectangular collisions. Given the points: We did: // returning 0 means collision int collision&#40;int ax, int ay, int bx, int by, int cx, int cy, int dx, int dy&#41;&#123; return &#40;&#40;ax &#62; dx&#41;&#124;&#124;&#40;bx &#60; cx&#41;&#124;&#124;&#40;ay &#62; dy&#41;&#124;&#124;&#40;by &#60; cy&#41;&#41;; &#125; I&#8217;ll show here a [...]]]></description>
			<content:encoded><![CDATA[<p><center><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/NRwRTHPGg6M&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/NRwRTHPGg6M&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></object></center></p>
<p>In <a title="Batalhão" href="http://batalhao.codigolivre.org.br/">a game</a> I wrote some years ago we handled simple rectangular collisions. Given the points:</p>
<p style="text-align: center;"><img class="size-full wp-image-1630 aligncenter" title="abcd" src="http://silveiraneto.net/wp-content/uploads/2008/10/abcd.png" alt="" width="200" height="145" /></p>
<p>We did:</p>
<div class="wp_syntax">
<div class="code">
<pre class="c c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// returning 0 means collision</span>
<span style="color: #993333;">int</span> collision<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> ax<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> ay<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> bx<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> by<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> cx<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> cy<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> dx<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> dy<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ax <span style="color: #339933;">&gt;</span> dx<span style="color: #009900;">&#41;</span>||<span style="color: #009900;">&#40;</span>bx <span style="color: #339933;">&lt;</span> cx<span style="color: #009900;">&#41;</span>||<span style="color: #009900;">&#40;</span>ay <span style="color: #339933;">&gt;</span> dy<span style="color: #009900;">&#41;</span>||<span style="color: #009900;">&#40;</span>by <span style="color: #339933;">&lt;</span> cy<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>I&#8217;ll show here a little demo about how implement simple rectangular collisions on JavaFX.<br />
First I created a movable rectangle using the same idea of draggable nodes I already had <a href="http://silveiraneto.net/2008/08/11/javafx-draggable-node/">posted before</a>.</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.input.MouseEvent</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.geometry.Rectangle</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MovableRectangle <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> attribute startX <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.0</span>;
    <span style="color: #000000; font-weight: bold;">private</span> attribute startY <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.0</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> attribute onMove <span style="color: #339933;">=</span> function<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span><span style="color: #003399;">MouseEvent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Void</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
    override attribute onMousePressed <span style="color: #339933;">=</span> function<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span><span style="color: #003399;">MouseEvent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Void</span> <span style="color: #009900;">&#123;</span>
        startX <span style="color: #339933;">=</span> e.<span style="color: #006633;">getDragX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>translateX;
        startY <span style="color: #339933;">=</span> e.<span style="color: #006633;">getDragY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>translateY;
        onMove<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    override attribute onMouseDragged <span style="color: #339933;">=</span> function<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span><span style="color: #003399;">MouseEvent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Void</span> <span style="color: #009900;">&#123;</span>
        translateX <span style="color: #339933;">=</span> e.<span style="color: #006633;">getDragX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>startX;
        translateY <span style="color: #339933;">=</span> e.<span style="color: #006633;">getDragY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>startY;
        onMove<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>In the main code I some important things:</p>
<ul>
<li><strong>colide</strong>, a color that represents the collision effect. White means no collision and gray means collision.</li>
<li><strong>rec1</strong> and <strong>rec2</strong>, the two rectangles that can collide.</li>
<li><strong>checkcollision()</strong> the function that checks and handles a possible collision.</li>
</ul>
<p>Here is the main code:</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.application.Frame</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.application.Stage</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.geometry.Rectangle</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.paint.Color</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.input.MouseEvent</span>;
&nbsp;
var colide <span style="color: #339933;">=</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">WHITE</span>;
&nbsp;
function checkcollision<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Void</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>
        <span style="color: #009900;">&#40;</span>rec1.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> rec2.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> rec2.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> or
        <span style="color: #009900;">&#40;</span>rec1.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> rec1.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> rec2.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> or
        <span style="color: #009900;">&#40;</span>rec1.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> rec2.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> rec2.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> or
        <span style="color: #009900;">&#40;</span>rec1.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> rec1.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> rec2.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        colide <span style="color: #339933;">=</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">WHITE</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
        colide <span style="color: #339933;">=</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">LIGHTGRAY</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
var rec1<span style="color: #339933;">:</span> MovableRectangle <span style="color: #339933;">=</span> MovableRectangle <span style="color: #009900;">&#123;</span>
    x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span>, y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span>, width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">50</span>, height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">60</span>, fill<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span>
    onMove<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span><span style="color: #003399;">MouseEvent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Void</span> <span style="color: #009900;">&#123;</span>
        checkcollision<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
var rec2<span style="color: #339933;">:</span> MovableRectangle <span style="color: #339933;">=</span> MovableRectangle <span style="color: #009900;">&#123;</span>
    x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">100</span>, y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">100</span>, width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">70</span>, height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">30</span>, fill<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">BLUE</span>
    onMove<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span><span style="color: #003399;">MouseEvent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Void</span> <span style="color: #009900;">&#123;</span>
        checkcollision<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003399;">Frame</span> <span style="color: #009900;">&#123;</span>
    title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Rectangular Collisions&quot;</span>, width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">300</span>, height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">300</span>
    closeAction<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">System</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span> 0 <span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
    visible<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>
&nbsp;
    stage<span style="color: #339933;">:</span> Stage <span style="color: #009900;">&#123;</span>
        fill<span style="color: #339933;">:</span> bind colide
        content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>rec1, rec2<span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>Try it via Java Web Start:</p>
<p><center><a href="http://silveiraneto.net/downloads/collisiondemo/launch.jnlp"><img src="http://silveiraneto.net/wp-content/uploads/2008/10/webstart.png" alt="Java Web Start" /></a></center></p>
<p>Some considerations:</p>
<ul>
<li>You can use rectangular collisions to create bounding boxes to handle collisions in more complex shapes or sprites. Is a common approach in 2d games to avoid more expensive calculations.</li>
<li>There are space for optimizations.</li>
<li>In this case I&#8217;m using only two objects. Some problems raises when I have N objects to handle.</li>
</ul>
<p>More generally, we can code:</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;">function collission<span style="color: #009900;">&#40;</span>ax, ay, bx, by, cx, cy, dx, dy<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #003399;">Boolean</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> not <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ax <span style="color: #339933;">&gt;</span> dx<span style="color: #009900;">&#41;</span>or<span style="color: #009900;">&#40;</span>bx <span style="color: #339933;">&lt;</span> cx<span style="color: #009900;">&#41;</span>or<span style="color: #009900;">&#40;</span>ay <span style="color: #339933;">&gt;</span> dy<span style="color: #009900;">&#41;</span>or<span style="color: #009900;">&#40;</span>by <span style="color: #339933;">&lt;</span> cy<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
function hitnode<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">:</span> Node, b<span style="color: #339933;">:</span>Node<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #003399;">Boolean</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>collission<span style="color: #009900;">&#40;</span>
        a.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, a.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
        a.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> a.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, a.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> a.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
        b.<span style="color: #006633;">getX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, b.<span style="color: #006633;">getY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
        b.<span style="color: #006633;">getX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> b.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, b.<span style="color: #006633;">getY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> b.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>This way we can pass just two bounding boxes to hitnode and easily check collision of a node against a list of bounding boxes nodes.<br />
Using the same approach I also wrote this function to test if a Node is inside another Node:</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;">function inside <span style="color: #009900;">&#40;</span>ax, ay, bx, by, cx, cy, dx, dy<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Boolean</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ax <span style="color: #339933;">&gt;</span> cx<span style="color: #009900;">&#41;</span> and <span style="color: #009900;">&#40;</span>bx <span style="color: #339933;">&lt;</span> dx<span style="color: #009900;">&#41;</span> and <span style="color: #009900;">&#40;</span>ay <span style="color: #339933;">&gt;</span> cy<span style="color: #009900;">&#41;</span> and <span style="color: #009900;">&#40;</span>by <span style="color: #339933;">&lt;</span> dy<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
function insidenode<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">:</span>Node,b<span style="color: #339933;">:</span>Node<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Boolean</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>inside<span style="color: #009900;">&#40;</span>
        a.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, a.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
        a.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> a.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, a.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> a.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
        b.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, b.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
        b.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> b.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, b.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> b.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>Soon I&#8217;ll post game examples showing how to use this method and others collission detection methods.</p>
<p><strong>Downloads:</strong></p>
<ul>
<li>The original video, <a href="http://silveiraneto.net/downloads/javafx_rectangular_collision_detection.ogg">javafx_rectangular_collision_detection.ogg</a></li>
<li>NetBeans 6.1 Project with sources, <a href="http://silveiraneto.net/downloads/javafx_rec_col.tar.gz">javafx_rec_col.tar.gz</a>. Needs <a href="http://javafx.netbeans.org">JavaFX module</a> installed.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/10/30/javafx-rectangular-collision-detection/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>More books</title>
		<link>http://silveiraneto.net/2008/02/28/more-books/</link>
		<comments>http://silveiraneto.net/2008/02/28/more-books/#comments</comments>
		<pubDate>Fri, 29 Feb 2008 00:23:43 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[james weaver]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[jfx]]></category>
		<category><![CDATA[Livros]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/2008/02/28/more-books/</guid>
		<description><![CDATA[More books to my shelf. Ruby On Rails, Executando. Desenvolvimento Rápido para a Web. Bruce A. Tate &#38; Curt Hibbs. Ruby, conhecendo a linguagem. Eustáqui Rangel de Oliveira Jr. JavaFX Script. Dynamic Java Scripting for Rich Internet/Clien-Side Applications. James L. Weaver. First I&#8217;ll take a look &#8230; JavaFX, of course. :) ps: The JavaFX book [...]]]></description>
			<content:encoded><![CDATA[<p>More books to my shelf.</p>
<p style="text-align: center"><img src="http://farm3.static.flickr.com/2229/2298525619_d7a3295f9e.jpg" alt="Livros novos" /></p>
<ul>
<li>Ruby On Rails, Executando. Desenvolvimento Rápido para a Web. Bruce A. Tate &amp; Curt Hibbs.</li>
<li>Ruby, conhecendo a linguagem. Eustáqui Rangel de Oliveira Jr.</li>
<li>JavaFX Script. Dynamic Java Scripting for Rich Internet/Clien-Side Applications. James L. Weaver.</li>
</ul>
<p>First I&#8217;ll take a look &#8230; JavaFX, of course. :)</p>
<p><small><strong>ps:</strong> The JavaFX book I win as a prize for naming the SDN Channel podcast, <a href="http://blogs.sun.com/SDNChannel/" title="SD  Channel" target="_blank">CampusCast</a>. Thanks Edu that bring it to me from USA. ;)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/02/28/more-books/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JavaFX: Side-scrolling</title>
		<link>http://silveiraneto.net/2008/02/20/javafx-side-scrolling/</link>
		<comments>http://silveiraneto.net/2008/02/20/javafx-side-scrolling/#comments</comments>
		<pubDate>Wed, 20 Feb 2008 03:26:28 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[en]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[jfx]]></category>
		<category><![CDATA[jfxbest]]></category>
		<category><![CDATA[mountains]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[ship]]></category>
		<category><![CDATA[side scrolling]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/2008/02/20/javafx-side-scrolling/</guid>
		<description><![CDATA[An side-scrolling game attempt. 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.*; &#160; var scroll; scroll = &#91;1..800&#93; dur 60000 linear continue if true; &#160; var mountains = Clip&#123; transform: bind translate&#40;-scroll,0&#41; shape: Rect &#123;x:bind scroll, [...]]]></description>
			<content:encoded><![CDATA[<p>An side-scrolling game attempt.</p>
<p><img src="http://silveiraneto.net/downloads/jfx_plane.png" alt="an plane" /></p>
<p>I used two images, <a href="http://silveiraneto.net/downloads/mountains.png">this mountain background</a> made with Gimp (<a href="http://silveiraneto.net/downloads/mountains.xcf">xcf sources here</a>) and that ship above made with Inkscape (<a href="http://silveiraneto.net/downloads/jfx_plane.svg">svg sources here</a>).</p>
<p><center><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/5F4STuluSiM&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/5F4STuluSiM&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></object></center></p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.ui.*</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.ui.canvas.*</span>;
&nbsp;
var scroll;
scroll <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>1..800<span style="color: #009900;">&#93;</span> dur <span style="color: #cc66cc;">60000</span> linear <span style="color: #000000; font-weight: bold;">continue</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000066; font-weight: bold;">true</span>;
&nbsp;
var mountains <span style="color: #339933;">=</span> <span style="color: #003399;">Clip</span><span style="color: #009900;">&#123;</span>
    transform<span style="color: #339933;">:</span> bind translate<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>scroll,0<span style="color: #009900;">&#41;</span>
    shape<span style="color: #339933;">:</span> Rect <span style="color: #009900;">&#123;</span>x<span style="color: #339933;">:</span>bind scroll, y<span style="color: #339933;">:</span>0, width<span style="color: #339933;">:</span><span style="color: #cc66cc;">400</span>, height<span style="color: #339933;">:</span><span style="color: #cc66cc;">200</span><span style="color: #009900;">&#125;</span>
    content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>ImageView <span style="color: #009900;">&#123;</span>
            transform<span style="color: #339933;">:</span> translate<span style="color: #009900;">&#40;</span>0,0<span style="color: #009900;">&#41;</span>
            image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span> url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;http://silveiraneto.net/downloads/mountains.png&quot;</span><span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>,
        ImageView <span style="color: #009900;">&#123;</span>
            transform<span style="color: #339933;">:</span> translate<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">800</span>,0<span style="color: #009900;">&#41;</span>
            image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span> url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;http://silveiraneto.net/downloads/mountains.png&quot;</span><span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span>;
&nbsp;
var h <span style="color: #339933;">=</span> <span style="color: #cc66cc;">50</span>;
&nbsp;
var ship <span style="color: #339933;">=</span> ImageView <span style="color: #009900;">&#123;</span>
    cursor<span style="color: #339933;">:</span> HAND
    transform<span style="color: #339933;">:</span> bind translate<span style="color: #009900;">&#40;</span>0,h<span style="color: #009900;">&#41;</span>
    image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span> url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;http://silveiraneto.net/downloads/jfx_plane.png&quot;</span><span style="color: #009900;">&#125;</span>
    onMouseDragged<span style="color: #339933;">:</span> operation<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        h <span style="color: #339933;">+=</span> e.<span style="color: #006633;">localDragTranslation</span>.<span style="color: #006633;">y</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>;
&nbsp;
<span style="color: #003399;">Canvas</span> <span style="color: #009900;">&#123;</span>
    content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>mountains, ship<span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/02/20/javafx-side-scrolling/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

