Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (492)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Some JavaFX game templates.  (Read 4014 times)
0 Members and 1 Guest are viewing this topic.
Offline nozh2002

Senior Newbie





« Posted 2009-04-26 04:07:49 »

Well, this is not how to do this best I guess, this is how I do this,
hope it will be helpful:

For NetBeans -

I put images in Pictures subdirectory in <Project>/src/<package> directory.
Place where Main.fx source code located.

Images handling:
--------------------

def goldenRedImages: Image[] =
for ( name in [
        "gr001.gif",
        "gr002.gif",
        "gr003.gif",
        "gr004.gif",
        "gr005.gif",
        "gr006.gif",
        "gr007.gif",
        "gr008.gif"
    ])
    Image {
        url: "{__DIR__}Pictures/{name}"
}

def goldenRedDX = [ 0,  0, 14, 10, 30, 14, 46, -13];
def goldenRedDY = [ 0,  0,  2,  4, 15  15, 10,   8];
--------------------------------------------------------------------------------
DX  and DY is horizontal and vertical coordinates shifts to line up pictures.

Then I define game view where this images will be seen:
------------------------------------------------------------------------------
def gameFieldView: Node =
Group{
    content: [
        ImageView {
            x: bind 300 + goldenRedDX[ goldenRed ] + goldenRedX
            y: bind 40 + goldenRedDY[ goldenRed ] + goldenRedY
            image: bind goldenRedImages[ goldenRed ]
        }
    ]
};
-----------------------------------------------------------------------------------
And this is all what I need to do for drawing. If I need to
change picture seen in this view only thing to do - change
variable goldenRed - because it is binded to this image view
JavaFX will take car of all drawing for me.

I should not worry about clearing previous picture, repainting
new, synchronizing it with other pictures and with screen updates...

I will only in this case change
goldenRed - which define picture for me (and shifts)
goldenRedY - Vertical coordinates
goldenRedX - Horizontal coordinates

That's it. Once I define this GameField, I may foget about all
representation and focus on the game play itself.

Regards, Vassili.
Offline nozh2002

Senior Newbie





« Reply #1 - Posted 2009-04-26 04:20:03 »

Same idea for Lines game, but I bind entire game array to image view.
Each cell binded to corresponded ImageView and also each has
MousePressed event:
--------------------------------------------------------------------------------

def gameFieldView: Node =
Group{
    content: [
        for ( x in [0..8]) {
            for ( y in [0..8]) {
                ImageView {
                    x: x * 33 + 1;
                    y: y * 33 + 1;
                    image: bind gameImages[ gameField[ x + (y * 9)] ]
                    onMousePressed: function(me: MouseEvent){
                        print( "cell {x}, {y} selected");
                    }
                }
            }
        }
    ]
};
-------------------------------------------------------------------------------

All I need to do now - just work with array itself and all changes will
be on the screen right away drawn not by me but JavaFX with it smart
effective etc graphic engine.

This is all simple and elegant beauty of binding.

Again I am not an multi media guy, but very enthusiastic about JavaFX
rapid development side, same as for scripts but with full strength and
performance of Java behind with all this hot spot magic...

Regards, Vassili.
Offline nozh2002

Senior Newbie





« Reply #2 - Posted 2009-04-26 05:25:41 »

How GoldenRed walk.

I use Timer - standard animation JavaFX construction. However I do
not really use it as it is intended to be used, but instead just for
clocking, switching off thing I do not understand yet like interpolate...

For me it is just thing which run certain code in certain time:
-----------------------------------------------------------------------------------

var walkForwardRate = 10;
def walkForwardTimer: Timeline = Timeline {
    repeatCount: Timeline.INDEFINITE
    rate: bind walkForwardRate
    interpolate: false
    keyFrames: [
        KeyFrame {
            time: 1s
            action: function() {
                goldenRedX += 10;
                goldenRed = 1;
            }
        }
        KeyFrame {
            time: 2s
            action: function() {
                goldenRedX += 10;
                goldenRed = 0;
                walkForwardTimer.stop();
            }
        }
    ]
}
-----------------------------------------------------------
As you may see I just change two variables -
goldenRed - which defines picture visible in corresponded ImageView (which I bind to golden Red)
goldenRedX - which defines image horizontal position.

How it will be painted - not my business, somehow, best possible, way using
hardware acceleration or something it will be drawn by JavaFX

Now to trigger this walk - I use onKeyPressed event function:
---------------------------------------------------------------
Stage {
    title: "GoldenRed"
    width: 800
    height: 320
    scene: Scene {
        content: [
            Rectangle {
                fill: Color.rgb(205, 225, 255);
                width: 800
                height: 160
            }
            gameFieldView
            Rectangle {
                opacity: 0
                focusable: true
                width: 800
                height: 350
                onKeyPressed: function(ke: KeyEvent){
                    if (ke.text == "Right") {
                        walkForwardTimer.play();
                    }
                }
            }
        ]
    }
}
--------------------------------------------------------------------------
It just starts this timer and timer stop itself at the end.
If I need to interrupt this timer because different key was
pressed - I just do:
--------------------------------------------------------------------------
walkForwardTimer.stop();
--------------------------------------------------------------------------
I also may just pause it.

Regards, Vassili.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (16 views)
2014-08-31 22:59:12

TehJavaDev (24 views)
2014-08-28 18:26:30

CopyableCougar4 (33 views)
2014-08-22 19:31:30

atombrot (42 views)
2014-08-19 09:29:53

Tekkerue (41 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (26 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (73 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!