Game Development & Game Environments

These questions are simple.

  1. How would I create a map larger than the screen its running on?
  2. How would I use the same image for the entire map, for example a 500 by 500 pixel ground piece, and repeat it across the entire map?
  3. How would I move the camera?

With JavaFX of course

Are you familiar with how the “scene graph” works?

If you have a 500x500 pixel ground piece, it can be displayed multiple times via the ImageView class. You would have one per each copy to be displayed. Each stores its own coordinates, and all of them can refer to the same .png or whatever form of image you have.

I haven’t used the camera much. I have one program where I have one running around across the top of a chess board that I wrote over 5 years ago. I recall consulting “JavaFX for Dummies” on the code on that! Memories/knowledge: “Use it or lose it!”

1 Like

Ok, so I’ll have to do that manually

i dont know what that is lol

In this tutorial I wrote several years ago, the second part is on the basic structure of the scene graph. The word “graph” is being used in a broader sense that includes things like tree structures, not so much a Cartesian 2D graph.

The “game” in the tutorial is incomplete, starts out with just a bouncing ball. And the IDE-related stuff is pretty much out-dated. So IDK that it would be the best place to learn. Maybe others here will have links to more current tutorials. I’m happy to answer any questions along the way, though. I pretty much check in several times a day here because I help out with moderation.

1 Like

Image 1.

Image 2. Capture2

Image 3.Capture3

Now for some reason, when I click the button to spawn the ant, the button doesn’t spawn the ant. Any idea what’s going on? (had to rereply because new users not able to post many embeds

@yems_1.6.0.3 While I certainly not an expert in this topic, I can say that it is better for you to just give the source code blocks instead of images for code.

For example, the following will result in a sample code in the post.

This is the code for Hello World program.

```java
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}
```

Hope you liked it!

Will be rendered in the browser as follows:


This is the code for Hello World program.

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

Hope you liked it!


Please try using these code blocks instead of embedding images in future. It’d be greatly appreciated if you could also edit existing posts to use code blocks instead of the images.

2 Likes

Oh right I forgot Discourse has preformatted text

I would use store an ImageView instead of an Image with each Ant.

When you create an instance of an object, it would be a good idea to use lower case for the first letter. Otherwise, it is easy to confuse an instance with the static reference to the class.

When you declare and create the Ant instance in the handle() method, this new instance is not saved anywhere, and thus will get garbaged-collected when the handle() method finishes executing.

So, there’s a bit to clean up here. I do think if you post code, it will be easier for folks here to test and then edit that code and repost corrections that you might be able to use.

I’m curious what language you used to code games with before attempting to use Java with JavaFX?

1 Like

Ok so I found a better game library and JavaFX is more for websites, so I stopped using that.

“better” is subjective and JavaFX isn’t more for websites, it’s used a lot outside of a web browser. If you’re unable to understand how objects work, you’ll go nowhere in object oriented programming, not only in Java.

1 Like

coolㅤㅤㅤㅤㅤㅤㅤㅤ