Java-Gaming.org Hi !
 Featured games (91) games approved by the League of Dukes Games in Showcase (757) Games in Android Showcase (229) games submitted by our members Games in WIP (844) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Scrolling tile game help  (Read 1241 times) 0 Members and 1 Guest are viewing this topic.
Farscience

Innocent Bystander

 « Posted 2012-10-04 13:13:41 »

I'm working on a scrolling tile game (think minicraft) and i have two questions:

1. How do I make the screen move depending on where the player is?
2. How do I know which tiles to draw depending on which tiles on currently on screen (my method of this(looping through every single tile) doesn't work).

Any help would be appreciated, and any code examples would be greatly appreciated  .
Regenuluz
 « Reply #1 - Posted 2012-10-04 13:26:46 »

If you store your map in a 2d array, and you know which tile the player is supposed to be on, then it's easy to calculate which tiles to render.

Say the player is on (50, 50) and there can be a total of 40 tiles across the screen and 30 vertical. If you want to keep the player centered, then you just divide 40 by 2 and then you know you have to render x = 30..70 (40 tiles across) and same with the vertical position. 30 / 2 = 15, so y = 35..65.

QuicK

Junior Devvie

 « Reply #2 - Posted 2012-10-09 10:58:04 »

The way I would do this is:

Create a Map class with a 2d array of Tiles.

if the player has free movement rather than tile movment, I would find the nearest tile.

I would then take that tile and center the camera on it. (basically translate the matrix to that position)

I would only render tiles that are within the camera position.x +/- Display.getWidth()/2 and camera position.y +/- Display.getHeight()/2

You might need to play with the render distance to make sure tiles that are half on the screen and half off are still drawn.

If you still need help tomorrow, I might be able to throw something simple together for you
Pages: [1]
 ignore  |  Print

 EgonOlsen (76 views) 2018-06-10 19:43:48 EgonOlsen (56 views) 2018-06-10 19:43:44 EgonOlsen (76 views) 2018-06-10 19:43:20 DesertCoockie (256 views) 2018-05-13 18:23:11 nelsongames (156 views) 2018-04-24 18:15:36 nelsongames (155 views) 2018-04-24 18:14:32 ivj94 (896 views) 2018-03-24 14:47:39 ivj94 (157 views) 2018-03-24 14:46:31 ivj94 (809 views) 2018-03-24 14:43:53 Solater (173 views) 2018-03-17 05:04:08
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org