aspose file tools*
The moose likes Game Development and the fly likes Offsetting X/Y Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Game Development
Bookmark "Offsetting X/Y" Watch "Offsetting X/Y" New topic
Author

Offsetting X/Y

Bryce Heath
Greenhorn

Joined: Sep 16, 2011
Posts: 19
Hi again guys
I have been hard at work reading about tile map based games. I have managed to make a program that runs a movable sprite, around a tilemap created from a text file. This map is also set with collision detection on all tiles and the players sprite. My new project is to make this program have an RPG overhead view with X/Y scrolling as the player moves around. After many days of reading, I have found this is done by making a "camera" class that is used as a location reference for what tiles need to be drawn on screen. Now my problem is that I have not found a tutorial that has been able to explain this is a way I understand. I now this is a lot to ask on a forum, but if anyone has the time, I could really use a dumbed down version of this, or even if it is possible with my current code.
Hope someone can help Thanks.
//The Tile maker class that reads the text file map and eventually places the Chars in an array list.


//This is the game class


//This is the hero sprite class


//this is the class of one of the tiles


Sorry for all the code, Im not sure what people might want to see to be able to help me. If any one has any ideas ect please let me know
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38881
    
  23
I am afraid that code is far too long for anybody to read. You will have to shorten it.
Why are you catching an ArrayOutOfBoundsException? That makes me wonder whether you know how to iterate an array.
When you add the blocks, you are going up to width - 1. How do you know that is the correct figure? How you you know the sizes of the boxes will ever add up to 1 less than the width of the display? You need to check that arithmetic very carefully.

I shall move this discussion to our games forum because that is far too large for “beginning”.
Bobby John
Greenhorn

Joined: Feb 10, 2012
Posts: 2
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.
 
 
subject: Offsetting X/Y