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

Need help with screen offset

David McGratton
Greenhorn

Joined: Jul 28, 2011
Posts: 5
Hi all,

I am an amateur game programmer and am currently trying to make a simple turnbased game. I have been using samples to try and understand it all, and implementing them into my game. I have restarted recenetly from scratch and here is the current game progress and problem.

A text file is read and stored in an array list and this is used to create the map, consisting of 64x64 sized tiles on screen.
The currently selected tile is overlayed with a red box called "focus". A tile is selected by mouse clicking, so the user clicks a tile and the focus moves to that tile.

My problem is with screen resolution. With a resolution of 1024 x 768, everything works fine, because both screen width and height is divisible by 64. All the tiles line up perfectly, the game focus positions fine when screen is clicked, and the screen scrolls correctly.

With a resolution of 1280 x 800, the screen height is not divisible by 64, and this causes the problems. The user would click on a tile, and the focus moves to the incorrect tile ( usually above or below where he or she pointed). Ive been trying very hard to fix this and am getting frustrated. The easy thing to do is to change tile size to 32 which i dont want to do.

The renderer code involved is this:



The "click" code is as follows:



To repeat, the problem is this: When the screen resolution is not divisible by the tile size eg 64x64, clicking on a tile on the screen does not function as it should, probably due to offset.

If you are able to help, or require more information on how to help, please get in touch. Thank you for reading.

Kindest Regards.
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

Then don't always use "64".


Set this up in the beginning. When you go to divide, divide by "variable", not by 64. You can add more else if statements if you test more screen resolutions.


John Price


“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
David McGratton
Greenhorn

Joined: Jul 28, 2011
Posts: 5
john price wrote:Then don't always use "64".


Set this up in the beginning. When you go to divide, divide by "variable", not by 64. You can add more else if statements if you test more screen resolutions.


John Price


Hi John,

Thank you for your speedy reply and help, I appreciate it. I incorrectly thought your solution was for the mouse coordinates and then knew it wouldnt work. However if I use your advice for the offset, the clicking works to a much better degree, although not perfect. The trick is for me to find the right variable so that the top left tile lines up perfectly with the screen when it is not divisible by 64.

The current offset code centres in the middle of the focus, leaving the bottom 32 pixels of a tile at the top of the screen showing and the top 32 pixels of a tile at the bottom of the screen showing, which messes up focus when clicking.

The solution seems to be to use 16 for offest instead of 64

Kindest Regards
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

No problem! I did clear up the problem, right? You can use a double value instead of an int value to be more precise...
John Price
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help with screen offset