Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (429)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (468)
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  
  2D Side Scroller Question  (Read 3295 times)
0 Members and 1 Guest are viewing this topic.
Offline DMastaGX

Senior Newbie





« Posted 2008-06-06 19:08:53 »

I'm trying to make a game and I currently have an Animation that moves around and jumps inside a 800x600 frame. I want to add this animation inside a 2D Tile based environment (Sort of like Mario Bros. ). Do I have to ditch the frame, and use the Tile Map ? or the Tile Map goes inside the frame ? Can anyone tell me How to get started in making a Tile Based Map for me to put the Animation ?

Thanks  Cool
Offline fletchergames

Senior Member





« Reply #1 - Posted 2008-06-07 16:24:44 »

The tile map isn't a component.  You just create a 2d array of tiles.  And then draw them.  Typically, you would draw them within the frame's paintComponent method if you have everything in a frame.

The book "Developing Games in Java" by David Brackeen shows you all the basics of programming a 2d tile-based platformer.
Offline DMastaGX

Senior Newbie





« Reply #2 - Posted 2008-06-08 05:23:29 »

Yeah that's the book I'm reading. I was doing fine until I reached chapter 5 where he talks about tile maps. I'll just re-read till I understand or something.
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


Game Engineer


« Reply #3 - Posted 2008-06-08 19:18:02 »

You can also check out http://www.cokeandcode.com/node/1087 on Kevin Glass's website.

See my work:
OTC Software
Offline DMastaGX

Senior Newbie





« Reply #4 - Posted 2008-06-15 17:21:29 »

The tile map isn't a component.  You just create a 2d array of tiles.  And then draw them.  Typically, you would draw them within the frame's paintComponent method if you have everything in a frame.

The book "Developing Games in Java" by David Brackeen shows you all the basics of programming a 2d tile-based platformer.

Thanks for the tip.I was able to do What you said. I created a Text file that represents a Map then It's read and the corresponding Letter in the text file will copy the corresponding Tile to a 2D Image Array. Then I drew this 2D Image Array into the screen and my Animation is moving fine inside it. Do you have any Ideas on how to make the camera scroll Huh
Offline fletchergames

Senior Member





« Reply #5 - Posted 2008-06-16 04:40:59 »

Store the x and y coordinates (within the array, not on the screen) of the tile appearing at the top-left corner of the screen.  When drawing the screen, have your for loops start at that tile and end one screen away.

When the player gets close to the edge of the screen (or whenever you want to scroll the screen), just change the x and y coordinates so that a different tile is at the top-left.

Edit: It can actually be kind of tricky to make it look right.  You might want to have a couple more variables to allow it to scroll a partial tile at a time.  You also have to have a fast main loop so that it scrolls quickly enough.

The millisecond timer on Windows usually has a granularity that's a bit too high, but there's not much you can do about it.  The nanosecond timer is unreliable.
Offline Orangy Tang

JGO Kernel


Medals: 51
Projects: 11


Monkey for a head


« Reply #6 - Posted 2008-06-16 12:02:35 »

Edit: It can actually be kind of tricky to make it look right.  You might want to have a couple more variables to allow it to scroll a partial tile at a time.  You also have to have a fast main loop so that it scrolls quickly enough.

Instead of trying to store the current tile pos plus a tile offset, I find it easier to store the camera position in world coords. Then when drawing you just need to find the tile indices of the visible area and loop between them.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11


Game Engineer


« Reply #7 - Posted 2008-06-27 18:16:04 »

Instead of trying to store the current tile pos plus a tile offset, I find it easier to store the camera position in world coords. Then when drawing you just need to find the tile indices of the visible area and loop between them.
Well, it's not too complicated to just say:

xPos = gridLocX*gridSize+xOffset

I think either way is simple and easy.

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.

theagentd (6 views)
2014-04-24 23:00:44

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

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

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

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

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

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

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

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

trollwarrior1 (216 views)
2014-04-04 12:06:45
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!