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
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Scrolling map  (Read 1579 times)
0 Members and 1 Guest are viewing this topic.
Offline Shazer2

Junior Devvie

Medals: 3

Aspiring developer.

« Posted 2011-09-09 07: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.


"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 12: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 Devvie

Medals: 3
Exp: 3 years


« Reply #2 - Posted 2011-09-09 12: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 20: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  

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 (258 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 (160 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 Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!