Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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 2890 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
« League of Dukes »

JGO Kernel


Medals: 39
Projects: 12


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: 48
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
« League of Dukes »

JGO Kernel


Medals: 39
Projects: 12


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.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (76 views)
2013-05-17 21:29:12

alaslipknot (88 views)
2013-05-16 21:24:48

gouessej (117 views)
2013-05-16 00:53:38

gouessej (113 views)
2013-05-16 00:17:58

theagentd (125 views)
2013-05-15 15:01:13

theagentd (112 views)
2013-05-15 15:00:54

StreetDoggy (156 views)
2013-05-14 15:56:26

kutucuk (178 views)
2013-05-12 17:10:36

kutucuk (178 views)
2013-05-12 15:36:09

UnluckyDevil (186 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.099 seconds with 20 queries.