• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Adjust game tile map image to screen size

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm making a game which requires Tile Map and I made an image that contains the tile map. In the image there will be colors drawn which then will represent where the block should be and what type of block (Grass, Stone, Sand).

For example:

--------------------------- Color DARK GRAY (#404040)

--------------------------- Color RED (#FF0000)

--------------------------- Color BLUE (#0026FF)

In my case the Color DARK GRAY with the hex of 404040 is representing my stone block.

Here's some code to begin with:

*Block size is 64x64.


My question is how can I manage to adjust the tile map which in my case is 100x100 to any screen size so it'll fit. By "fit" I mean to fit where the tiles from the image should be on the screen.

For example -

In the tile image the tiles are here which is how it supposed to be on EVERY screen:

----------------
In my screen which is 1920x1080 the tiles are here:

---------------
In screens of 800x400 the tiles are here:

----------------
I thought something like this:
It didn't worked and the game loaded slowly.

If anybody have an idea how to manage to adjust it, it'll be great.

Thanks in advance.
 
Saloon Keeper
Posts: 14498
325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you always want to show the entire map on the screen, regardless of the resolution? It's probably easiest to let the view technology handle the mapping from 'world space' to 'screen space'.

You can use an OpenGL library to render your tiles. I strongly recommend LWJGL. Look up some tutorials on how to do 2D graphics using these libraries.
 
Amit Shef
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey and thanks for the reply. Can you give me an example of handling view technology?
 
Stephan van Hulst
Saloon Keeper
Posts: 14498
325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wouldn't be able to give an example here, that would provide a better explanation that what you get when you Google for an LWJGL tutorial.
 
Rancher
Posts: 1059
27
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I do this, I decide how many tiles I wish to display on the screen for my game, then see the size of the display area--you can get this within Toolkit API. Once I have the size of the screen it is an easy thing to divide the physical screen dimensions by the number of blocks I want along each axis. I truncate the math, integer math, and center my board in the middle of the screen.
 
Amit Shef
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Stephan, i will take a look on LWJGL tutorials.

Les Morgan wrote:When I do this, I decide how many tiles I wish to display on the screen for my game, then see the size of the display area--you can get this within Toolkit API. Once I have the size of the screen it is an easy thing to divide the physical screen dimensions by the number of blocks I want along each axis. I truncate the math, integer math, and center my board in the middle of the screen.



Hey Morgan thank you very much for replying. Can you give me a quick example? I got the screen size width and height and decided that I want 20 blocks in every axis.



From there where do I go with my code?


 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Amit Shef wrote:Thank you Stephan, i will take a look on LWJGL tutorials...


If there's a library around, then I'd definitely learn it and use it. Part of the art of programming is "not re-inventing the wheel".

If you really need to "roll your own" though, then I'd say that one of the first things you need to do is create a Tile class that understands
(a) The size of Panel it will be displayed in.
(b) The dimension of the "grid" it's part of (rows and columns)
Then it should be a simple matter to resize it if any of those values (particularly Panel size) change.

Alternatively, I wonder if BoxLayout might help. It can certainly split the display into "tile-like" portions, but whether you can then colour them individually, I have no idea. I'm pretty sure that they resize automatically though.

And that's the limits of my GUI knowledge.

Winston
 
Les Morgan
Rancher
Posts: 1059
27
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Amit Shef wrote:
Hey Morgan thank you very much for replying. Can you give me a quick example? I got the screen size width and height and decided that I want 20 blocks in every axis.


Here you go:
 
Sometimes you feel like a nut. Sometimes you feel like a tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic