Win a copy of Spring Boot in Practice this week in the Spring forum!

Bobby John

Greenhorn
+ Follow
since Feb 10, 2012
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bobby John

Its really simple, create a class called Camera with an x and y coordinate.
Draw your tiles at whatever coordinate, plus the x and y from the Camera class.

Then, intstead of changing the coordinates of the player sprite, set them to the center of the screen, and change the Camera coordinates instead. This will keep the player in the center, and the tiles will move instead.
10 years ago
I tend to use spritesheets, purely for the fact that all my images are in one place. Im interested to know how it affects performance though.

I do it by creating a 256x256 image in Paint.NET and then use the GridMaker plugin to create the cells, usually 16x16, but you could also do 32x32.
Then I create a class called SpriteSheet and use it to load the image into a BufferedImage. I create a class called Sprite which also holds a BufferedImage. Using .getSubImage(), you can define the x and y of the individual sprite and the width and height.



As the cells are all the same size, you can create an array of sprites for a row on the sprite sheet using a for loop, multiplying the value by the sprite width each time it loops. The array can be useful for holding the frames for an animation.

I don't think it would improve performance if you only had a small number of images to load. But if you had say 1000 images that needed to be loaded, I think it would be faster to load a few spritesheets than lots of smaller images.
10 years ago