Introduction
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!
Update
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
Commands:
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
Problem
- Learn rotation
- play sound effects
Solution
- 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.
- 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
}
Cool site 🙂