Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (579)
games submitted by our members
Games in WIP (500)
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  
  Viewpoint theory - Moving a small screen in a big room  (Read 931 times)
0 Members and 1 Guest are viewing this topic.
Offline saucecode

Senior Newbie


Medals: 1



« Posted 2011-12-25 06:14:05 »

So i've been pondering how I would go about implementing a viewport big room small screen kind of concept, and came up with a litte 'theory'.

So everything in the game will have 2 x/y variables, a "render X/Y" position, and a "real X/Y" position. When receiving input (key strokes), the object the viewport is following will be affected by having the realX/Y position changed. The renderX/Y will stay the same to keep the player in the center of the screen. It is vice versa for the 'static' objects, whose real position stays the same, but and input is received, its render position is kept.

In theory (maybe) this means that the screen will look like the player is moving around a world, when really the world is moving according to the input, but in the background, with the realX/Y coordinates, the physics is being run.

So i hope that makes sense.
:/
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #1 - Posted 2011-12-25 06:18:44 »

How about nothing "moves" at all, but rather you modify X and Y offset variables that you use when rendering.

Offline saucecode

Senior Newbie


Medals: 1



« Reply #2 - Posted 2011-12-25 07:03:21 »

How about nothing "moves" at all, but rather you modify X and Y offset variables that you use when rendering.

Yea I would do that if i knew what all that meant. :3
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« Reply #3 - Posted 2011-12-25 07:13:46 »

Every entity in the world has an X and Y that defines where it is by reference of the origin, or usually the top left corner of the map. When you move your character, you just modify his X and Y accordingly and then center the camera on him/her. The camera is composed of and X and Y offset variable that is used to translate the window. Centering is done by doing this:
1  
2  
xOffset = screenWidth/2 - (character.X + character.Width/2);
yOffset = screenHeight/2 - (character.Y + character.Height/2);


And then when rendering your world, you would translate the scene:
1  
graphics.translate(xOffset,yOffset);

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.

xsi3rr4x (38 views)
2014-04-15 18:08:23

BurntPizza (34 views)
2014-04-15 03:46:01

UprightPath (50 views)
2014-04-14 17:39:50

UprightPath (32 views)
2014-04-14 17:35:47

Porlus (49 views)
2014-04-14 15:48:38

tom_mai78101 (71 views)
2014-04-10 04:04:31

BurntPizza (130 views)
2014-04-08 23:06:04

tom_mai78101 (230 views)
2014-04-05 13:34:39

trollwarrior1 (193 views)
2014-04-04 12:06:45

CJLetsGame (200 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!