Scrolling

Moderator
Posts: 449
Joined: 2003.08
Post: #1
I've read Mac Game Programming, but I was wondering how todo vertical scrolling, and also, for some reason, I am really confused by tiles. How do you choose which tiles you want from a picture full of them. Do you type the coordinates of it in the picture and the height/width? Also, should I use tiles, or one big picture. It's going to be a flight combat game. I'm making it with project builder.
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #2
I thought vertical scrolling was done in MGP? Mark S. hangs around the forum so he might be able help you out some there.

As far as tiles go, I usually keep a 2D array of ints that tells me where tiles are and what type of tile is there.
Quote this message in a reply
Moderator
Posts: 449
Joined: 2003.08
Post: #3
cool. MGP doesn't talk about the kind of one i want, I don't think. I wan't a continous vertical scroll, like Deimos Rising at Ambrosia.
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #4
Page 145 talks about scrolling upwards (so the image on the screen goes downwards). Of course, there's no difference between scrolling continuously or scrolling in response to the player's movement.

Elsewhere, page 125 talks about drawing tiles, and there's some code on the next page which shows you how you might draw a tile from the map data.

You probably just need to read the book carefully and try it out to get a handle on how it works, but if you're still stuck I can probably explain it in simpler terms.

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Moderator
Posts: 449
Joined: 2003.08
Post: #5
Yeah, Sometimes I kind of read fast and don't pay attention to stuff. I guess just alter the code a bit to do continous. THanks.
Quote this message in a reply
Member
Posts: 111
Joined: 2002.06
Post: #6
Modifying the code from my book to do continuous vertical scrolling is easy. The function GameApp::ScrollBackground() checks if the player is close to the edge of the screen and scrolls in the appropriate direction if he is. You will rip out most of the code, keeping the call to ScrollUp(). Because you'll be constantly scrolling, you'll want to scroll by a smaller amount than I do in the code.

As Jabber mentioned, most tile-based games store their levels as a 2D array. Each element in the array has a number that tells you which tile to draw in that spot in the level. Email me if you need a more detailed explanation.

The decision to use tiles versus one big picture depends on how you want the game to look, how many levels you want in the game, and how big you want the levels to be. One large image would look better than tiles, but a good artist can give you tiles that don't look like tiles. The advantage of tiles is that you can reuse them. You can take one set of tiles and use them in several levels. With one large image, you need one large image per level. If you want lots of huge levels in your 2D game, go with tiles. If not, go with what you feel more comfortable using.

Mark Szymczyk
http://www.meandmark.com
Quote this message in a reply
Moderator
Posts: 449
Joined: 2003.08
Post: #7
Thanks for the info. One problem I think I'm going to get is keeping the ship on the screen. So that it wont scroll off. and be gone. how would I do that?
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #8
Well, the ship shouldn't scroll off the screen of its own volition because you're going to redraw it each frame at the same position (or some other position, depending on the state of the player's controls). What you'll probably see instead is a trail from the ship's previous location which needs to be cleaned away.

If you're not already doing so, you should treat the ship as a separate object from the background (a sprite). It needs to have its own coordinates so you know where to draw it on the screen, and each frame you must redraw the background at its previous location and draw the sprite again in its new position.

There's some stuff in MGP on page 188 about Dirty Rectangle Animation, which is an economical way of determining which parts of the background should be redrawn.

BTW, you should probably write some code to see how all this works before you go too much further. It's difficult to understand the problems before you've actually made the mistakes!

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Moderator
Posts: 102
Joined: 2003.07
Post: #9
You could go and check out the scrolling tutorial on this site it's in C but it might give you a good Idea on how to do constant scrolling. all you would need to do is reverse some of the values to make it go up instead of sideways.

-CarbonX
Quote this message in a reply
Member
Posts: 31
Joined: 2004.09
Post: #10
This was covered in-depth, just recently. For details on what Deimos does, go here:


Vertical scrolling
Quote this message in a reply
Post Reply