Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (707)
Games in Android Showcase (206)
games submitted by our members
Games in WIP (781)
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  
  Hexara rewrite with Java 8 & JavaFX  (Read 4099 times)
0 Members and 1 Guest are viewing this topic.
Offline philfrei
« Posted 2017-01-02 00:38:34 »

in progress jar: Hexara8

stalled Java2D version: Hexara (old)



My resolution for 2017 is to finish and publish Hexara. I want to get more adept with JavaFX and Java 8, so I decided to convert the previously stalled project.

Managed to get a running start into the New Year!

I have a three-tiered system set up for timing and animation that seems like it will work out pretty well.
1) asynchronous, e.g., mouse motions, keyboard input (will be loosely coupled to other tiers) [hasn't been implemented yet]
2) graphics animation via an AnimationTimer (runs at 60fps)
3) scheduled events and sound playback (runs at 44100 fps)

The AnimationTimer has but a single line of code. The overridden handle() method consists of the following:
1  
    for (Animatable aa : Animatables.array) aa.update(); 

Animatable is an Interface with one method: update().
Animatables.array is a static array. I use a CopyOnWriteArrayList rather than an ArrayList, to allow concurrent access (can add or delete while array is iterating).

That covers the "update" portion of the game loop. As for "render"--that seems to be automatically handled by JavaFX. There is no need for Swing's paintComponent() method or equivalent.

For the blocks that hold the letters: I'm using Rectangles. For the "cold" blocks, the innermost Rectangle is given a fill of silver (outer rectangles are progressively darker, and just the shape is drawn). The letter nodes are drawn after the Rectangle nodes and set up with a black fill.

For the "hot" blocks, the innermost rectangle is overwritten by a WritableImage (replacing awt.image.BufferedImage) created via a PixelWriter (replacing awt.image.WritableRaster) that obtains data over a 64 by 128 rectangle using Z-animation and a Perlin Simplex Noise function. The animation is run at half the speed (30fps -- seems sufficient and is less of a cpu load than using a smaller z-increment at full speed) and the resulting graphic is scaled, rotated (for even-numbered positions), and translated via an ImageView node. The six ImageView's all use the same static WritableImage as a source.

The series of notes played (via a real-time synth) are scheduled with an audio event-scheduler I wrote. When scheduling, it is possible to include a NoteListener as a callback function.

The NoteListener code on the managing class for the TitleBlocks sets a variable that tells the update() method to flip from "cold" to "hot", for the first six notes. Loose coupling is very important so as not to burden the audio thread--let the animation thread handle the bulk of the work!

The start of the seventh note in the musical motif provides a hook into the note's main volume envelope and flips a flag, so that the animation loop will inspect and use this value to set the Group (all the blocks) opacity--thus the fading of the graphics is a function of the note dying away. I do a bit of filtering and scaling of the envelope values to manage the visual fade. It probably seems a little long for a title sequence, but the intention is to cross-fade with the sounds and images of the main puzzle panel. Also, there will eventually be another visual animation (glow bloom and fade) triggered by the start of the seventh note.

I'm excited that this is coming together! Am pleased that the JavaFX code is clearer, easier to manage, and less verbose than Java2D, so far. Cross-fading to the puzzle panel is going to require some working out. I'm not sure yet if I'll be flipping visibility switches and opacity values of nodes, or nulling and resetting the nodes, or if I'll actually be adding and removing the Nodes from the root node. To be continued.

music and music apps: http://adonax.com
Offline basil_

« JGO Bitwise Duke »


Medals: 369
Exp: 13 years



« Reply #1 - Posted 2017-01-02 00:55:44 »

awesome! glad to see it's still a living project. the game is really good.
Offline philfrei
« Reply #2 - Posted 2017-01-04 04:17:27 »

I have coded the dunes landscape and some twinkling stars.
hexaratitlesxfade.jar


The title blocks are fading out and the landscape is coming in.
OOPS--note to self: have to manage the stars that are appearing in the dunes!

Completed fade:


The dunes are also created via Perlin noise. I'd like to have some sort of mountains in the background, and maybe a bit of atmospheric glow near the horizon. The sky I did before has a crude milky-way sort of cloud in it and some comets. On TODO list.

The biggest hitch was getting worried about altering Node values (opacity property values) from outside of the "JavaFX Application Thread". It took a good half day just to research and figure this out. Turns out that threads created by JavaFX animation timers are considered by JavaFX to be part of the JavaFX Application Thread. So, it's fine. The main thing is to not forget the plan of limiting the Audio thread to passing messages to the Animation thread, and not have it act directly on the Nodes. (Shouldn't do this anyway as the Audio thread needs to run as free as possible.)

I hate spending time second-guessing plans that are working, but I did learn important things in the process.

music and music apps: http://adonax.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online princec

« JGO Spiffy Duke »


Medals: 869
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2017-01-04 09:18:31 »

Don't get confused! AnimationTimers are not threads. They're all invoked on the JavaFX application thread by the JavaFX pulse.

Cas Smiley

Offline nsigma
« Reply #4 - Posted 2017-01-04 10:56:42 »

Don't get confused! AnimationTimers are not threads. They're all invoked on the JavaFX application thread by the JavaFX pulse.

Haha, just made almost identical response on Phil's other topic - heard it from two of us now!  Grin

Praxis LIVE - hybrid visual IDE for (live) creative coding
Pages: [1]
  ignore  |  Print  
 
 

 
Galdo (237 views)
2017-01-12 13:44:09

Archive (405 views)
2017-01-02 05:31:41

0AndrewShepherd0 (864 views)
2016-12-16 03:58:39

0AndrewShepherd0 (801 views)
2016-12-15 21:50:57

Lunch (938 views)
2016-12-06 16:01:40

ral0r2 (1168 views)
2016-11-23 16:08:26

ClaasJG (1270 views)
2016-11-10 17:36:32

CoffeeChemist (1305 views)
2016-11-05 00:46:53

jay4842 (1390 views)
2016-11-01 19:04:52

theagentd (1207 views)
2016-10-24 17:51:53
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21
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!