My Triangle Space Ship – JavaFX media sound


I grew up with old arcade games such as Asteroids and thought about making a simple ship, yes the famous triangle in JavaFX. I had to dig up my old trigonometry book. Remember unit circles? Although, I have learned that in JavaFX there is an attribute called rotation it is important to know that it is in degrees, so converting them to radian measure is key to making your velocity correct. Please keep in mind there are simple optimizations for my calculation and would need refactoring. Another goal was to play sound effects. Click below to launch the demo. The objective is to fly around and shoot at the box on the left. My little triangle space ship has powerful missiles!


The I do not have a place to host the media Sound files and the demo will not play the sound effects. I am still looking at a way to put into the jar file and use them.

My Triangle Space Ship

My Triangle Space Ship


Left arrow – move left
Right arrow – move right
Up arrow – fly forward
Down arrow – stop
Space bar – Fire missles

Click here (JavaWebstart): Play My Triangle Space Ship


  1. Learn rotation
  2. play sound effects


  1. Rotation is a Float which is in degrees at a pivot point or center of a rectangular bounded region. But for triangles or polygons use the translateX and translateY or the centroid formula.
  2. Use JavaFX’s media

var missleLaunch = Media{
source: “demos/fxfun/my_triangle_ship/Missile_SE.mp3”

var missleHit = Media{
source: “demos/fxfun/my_triangle_ship/explosion2.mp3”
var player = MediaPlayer{
media: missleLaunch,
autoPlay: false

1 thought on “My Triangle Space Ship – JavaFX media sound

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s