• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Offsetting X/Y

Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70318
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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”.
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic