Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (686)
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 game  (Read 1005 times)
0 Members and 1 Guest are viewing this topic.
Offline Nijokijun

Junior Newbie

« Posted 2012-11-23 01:43:56 »

How would I go about scrolling a 2D game, would I use a camera object, and if so, I would I work out the offset and how would I render that?

I'm not using any game engine, btw.

Sorry if this isnt a very descriptive post...
Offline SwampChicken
« Reply #1 - Posted 2012-11-23 02:30:46 »

Umm, there is no need for a camera object in a 2D game.
2D games usually draw, or move tiles/sprites around in a off-screen buffer.
Offline Nijokijun

Junior Newbie

« Reply #2 - Posted 2012-11-23 02:32:12 »

I wasn't sure if I should use one, but how would I add scrolling on the x and y axis?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Cero
« Reply #3 - Posted 2012-11-23 02:46:34 »

Umm, there is no need for a camera object in a 2D game.
There is no NEED, but it makes things very easy. For example rotating a camera vs. rotating EVERYTHING and accordingly - whats do you think makes more sense ?

I'm not using any game engine, btw.
Well, what are you using ?

Offline Nijokijun

Junior Newbie

« Reply #4 - Posted 2012-11-23 03:13:16 »

I'm using Java2D
Offline kramin42
« Reply #5 - Posted 2012-11-23 06:08:57 »

Never actually done this before but a basic way of doing it would be:

AffineTransform identity = new AffineTransform();

g2d.translate(-viewX, -viewY);

//rendering code here


where viewX and viewY are the x and y coordinates of the top left corner of your view. If you wanted to stay centered on the character you could do this first:

viewX = charX - screenWidth/2;
viewY = charY - screenHeight/2;

Where charX and charY are the coordinates of the character.

"All science is either physics or stamp collecting." - Ernest Rutherford.
Offline Cero
« Reply #6 - Posted 2012-11-23 15:15:13 »

of course you need to think about culling as well

in java2d I wrote my own camera, but it was just a rect and whenever I draw ANYTHING I would subtract camera.x and camera.y from that position

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

Dwinin (63 views)
2015-11-07 13:29:08

Rems19 (77 views)
2015-10-31 01:36:56

Rems19 (69 views)
2015-10-31 01:32:37

williamwoles (103 views)
2015-10-23 10:42:59

williamwoles (91 views)
2015-10-23 10:42:45

Jervac_ (105 views)
2015-10-18 23:29:12

DarkCart (131 views)
2015-10-16 00:58:11

KaiHH (114 views)
2015-10-11 14:10:14

KaiHH (153 views)
2015-10-11 13:26:18

BurntPizza (167 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 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!