Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Scrolling map  (Read 947 times)
0 Members and 1 Guest are viewing this topic.
Offline Shazer2

Junior Member


Medals: 3


Aspiring developer.


« Posted 2011-09-09 09:19:04 »

I want to achieve movement like Legends of Yore where the map scrolls whenever I reach a certain position. I have no current code at the moment and was wondering if anyone could point me in the right direction to get something like this working.

Thanks,
Shazer2.

"When you want to be successful as bad as you want to breathe, then you will be successful." - Eric Thomas
Offline Z-Man
« Reply #1 - Posted 2011-09-09 14:09:50 »

The basic idea, or at least the way I think about it, is that you aren't actually moving the user your moving the map and everything else around the user. So your basically tricking whoever is playing your game into thinking that their player is moving when in reality it isn't.
Offline Kurten

Junior Member


Medals: 3
Exp: 3 years


-w-


« Reply #2 - Posted 2011-09-09 14:18:34 »

I worked out a very rough code block for this some time ago, i don't have the code but the general idea was like this:

Make the player coordinates final, put him in the middle of the screen, then load up a 2D array of tiles, give them relative coordinates, coordinates that is changeable that is. When the player moves, instead of adding velocity to the player, add it to the tiles so that they move. Each update you loop through the tiles within view of the player in a nested for loop to update their current position with the
position X = velocity X * elapsed time
Position Y = velocity Y * elapsed time

Rough sketch, but i hope this helps you a bit at least
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #3 - Posted 2011-09-09 22:27:48 »

I find a good way of doing it is moving the player freely (as Kurten said) and then scroll everything by his offset from the center of the screen. The great thing about this is you can change it up so that the map only scrolls when you get the edges and such, and the player's position actually changes (as it should, because he does exist within the world).

Think of it this way: the character is moving around within the world, what is staying centered is actually the camera that's watching him. The world itself is not moving, only the camera and character are. So the character moves, then the camera follows.

Make sense?

See my work:
OTC Software
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (26 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (19 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (56 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!