Polygons are not moving...

So, I have this little problem(and by little I mean game breaking). I’m using java.awt.Polygon to make a triangle and using java.awt.Graphics to draw it to the screen. So when I try to increase the velocity on either the x (x += velX) or y (y += velY) axis the triangle doesn’t move! >:( So I made the rendered shape a square without utilizing the Polygon class(I only used the Graphics class). When I tried moving the square the same way I moved the triangle, it worked… Can anyone tell me how this is so? And point me in the right direction to make this work? :clue:

DISCLAIMER I don’t want to use the Polygon.translate(deltaX, deltaY) method because it ignores collisions.

I think you have to add to each vertices’ point data. In other words, each point in the x[] has to have the amount added to it for a horizontal movement.

Sometimes it makes sense to make a wrapper class that has the location that you can just give the X and Y movement amounts in a “normal” fashion, and have this class call the methods needed to handle updating the polygon point arrays.

(Reminding me why I’m glad I switched to JavaFX.)
(Been a while since I fussed with polygons–I hope I’m not totally off base.)

Would all the graphical stuff be easier to do things with, such as moving objects and collision interactions, if I switched my game over to JavaFX?

I’ve heard of JavaFX but never looked into it before.

Yes, it definitely would be much easier, as JavaFX is more modern, robust and object-oriented as the good ol’ Java2D :). It has classes for any Shapes, including Polygons. Many people think that JavaFX works the same way as Java2D, so they draw their stuff on a JavaFX Canvas. But to benefit from the scenegraph and hardware acceleration, you should use the scenegraph objects like Rectangle, Circle, Polygon, ImageView etc. Just to give you this tip.
Switching to JavaFX a few years ago was much better for me as well.

Cheers

If you want to give JavaFX a try, JGO has a tutorial that will take you through the basics. There are a couple gotcha’s, like the fact that there was an earlier version that was discarded, and some of those tutorials are still floating around, confusing people. Once you see the basic setup in action, it is pretty straightforward to learn and use.

Thank you both for the information! And especially thank you for the tutorial, because I looked into JavaFX and tried getting e(fx)clipse for eclipse neon and it was super confusing and I couldn’t even find a download ANYWHERE for that plugin. Now with that tutorial I won’t have to use that plugin ;D