2D Side Scroller Question

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 8)

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.

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.

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

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 ???

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.

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.