Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (604)
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 811 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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
AffineTransform identity = new AffineTransform();

g2d.translate(-viewX, -viewY);

//
//rendering code here
//

g2d.setTransform(identity);


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:

1  
2  
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.
CodeGolf4k
M4nkala
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.

 

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

The first screenshot will be displayed as a thumbnail.

rwatson462 (36 views)
2014-12-15 09:26:44

Mr.CodeIt (27 views)
2014-12-14 19:50:38

BurntPizza (61 views)
2014-12-09 22:41:13

BurntPizza (96 views)
2014-12-08 04:46:31

JscottyBieshaar (56 views)
2014-12-05 12:39:02

SHC (72 views)
2014-12-03 16:27:13

CopyableCougar4 (74 views)
2014-11-29 21:32:03

toopeicgaming1999 (134 views)
2014-11-26 15:22:04

toopeicgaming1999 (125 views)
2014-11-26 15:20:36

toopeicgaming1999 (35 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 19:56:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-10 08:05:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-03 08:06:02

List of Learning Resources
by Longor1996
2014-08-16 20:10:00

List of Learning Resources
by SilverTiger
2014-08-06 05:03:27

Resources for WIP games
by CogWheelz
2014-08-02 01:50:17

Resources for WIP games
by CogWheelz
2014-08-02 01:49:50

List of Learning Resources
by SilverTiger
2014-08-01 01:59:50
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!