[JavaFX 8] ParallelCamera: Strange behavior! Don't know what to do.

Hello JGO!
I want to create a small game with JavaFX 8. It’s based on ‘Asteroids’, for those that don’t know:
Asteroids spawn from all sides of your window/screen and you have to shoot them with a spaceship which can freely move within the screen boarders.

I ran into a problem though. To delete an asteroid from the scene when it passes outside the screen I check if they are outside the screen boarders (x and y coords).
But now I cant let them spawn outside to avoid them appearing instant on screen.

So I thought about using a ParallelCamera and move it to x = 100 and y = 100 to create a 100px wide zone where I can spawn asteroids and send them to the other side of the screen.

When i implement the camera images only appear after I resize the whole window. Without the camera everything works as intended. My goal is ofc to get the images on screen without having to resize the whole window…

Edit: Creating a rectangle works just fine, it’s on screen right from the start even with a ParallelCamera. I’m totally lost guys.

rect = new Rectangle(50, 50, 75, 20);
rect.setFill(Color.GREEN);

Pics at the end of this post.

Without ParallelCamera:
[spoiler]
http://www.java-gaming.org/user-generated-content/members/496078/without-cam.jpg
[/spoiler]

With ParallelCamera:
[spoiler]
http://www.java-gaming.org/user-generated-content/members/496078/cam-no-resize.jpg
[/spoiler]

With ParallelCamera but after i manually resized the whole window:
[spoiler]
http://www.java-gaming.org/user-generated-content/members/496078/cam-resized.jpg
[/spoiler]

Code:
[spoiler]http://pastebin.java-gaming.org/8d79c3d193319[/spoiler]

Edit: New pics which include a green rectangle that gets drawn on screen even with ParallelCamera enabled.


After I moved the camera:

Ok, after several hours I found a solution:
Moving/translating the ParallelCamera with camera.setTranslateX, camera.relocate(var1, var2) seem to break something, since images get cut off by the amount of pixels you translate the camera when you e.g. use a small number in setTranslateX().

Further it seems like i don’t have to use a ParallelCamera at all, I can spawn those asteroids on negative x and y coords and let them fly around.

The the best thing at the end:
Using setLayoutX/Y (and possibly setTranslateX/Y) on your scene graph’s root node (in my case a Group node) achieves almost the result I wanted to have with camera.setTranslateX/Y.
The difference between those two is the following:
root.setLayoutX(100) moves every x coordinate 100 units to the right by adding 100 to all nodes whereas camera.setTranslateX(100) moves the eye 100 units to the right without changing the coordinates.

TL;DR: I didn’t know that I could set negative coords which solves my problem. Well I learnt a lot today…about coordinates.

A simple solution would be to alter the bounds. Lets say your screen is200x200. Simply despawn the rocks when they are outside the bounds -100,-100 to 300,300, and spawn the rocks at -50,-50 to 250,250.

I took a different approach:
I do let them spawn outside the screen and assign a destination (Point2D object) and move the asteroids as long the distance between Asteroid location and destination location are > 0. When they reach it (distance <= 0) they get deleted.

I like that solution. However, it occurs to me that distance can never be < 0.

I added the <= in case I want to move the asteroid by 2 pixels each gameLoop iteration and it might happen that distance is 1 and at next iteration it would be -1.

Edit: Getting into Vector math now to get rid off those pesky x and y coords. JavaFX 8 has a nice Point2D/3D class. Reading http://natureofcode.com/book/chapter-1-vectors/ which describes vectors using processing (processing.org).

No, what I mean is… Try walk right now to a point -5m away from you :slight_smile:

Better not trying this I don’t want to crash the universe ;D

I had the same problem. Really don’t know why it works with that behaviour. Or we have to move camera in other way… ???