Skip to content
Advertisement

JavaFX – move projectiles

First of all, this is my very first post here. Hello everyone!

I am a beginner in Java/JavaFX. Currently I wrote some simple “game” to learn some basic stuff in game development, doing that just for fun right now. So far I get a player which moves to the left/right (movement is unrestricted, but never mind that now) and fires projectiles. I got this done, code below:

JavaScript

Now the weird part. If I comment the moveEnemy() method out, everything seems OK – the “enemies” (black rectangles) appear in random places along the x axis on the top of the root.

I thought I’ll move enemies by means of the same method which I used to move projectiles. However, if I actually use this, my enemies keep appearing at the left top corner and dissappear almost instantly. Why is that?

Many thanks!

Edit: maybe I wasn’t clear. I don’t expect a ready-made solution, but an explanation.

Advertisement

Answer

Ok, I got it sorted out, thanks kleopatra for help! Probably there is still a room for improvement, but nonetheless its some progress:

JavaScript

Now I’ll play with the code a bit, try detecting collisions, restricting movement, adding some more stuff etc.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement