Scrolling tiles?

In the game that I am currently working on, we use tiles. That's all fine and dandy, but we also need it to scroll. So my question is: what is the best (easiest) way to scroll? The one idea that I thought of was to check the position of the player and then scroll accordingly. Would that work?

In general, yes, that's what you have to do. There are typcially two types of scroll I can think of:

The first kind keeps the player in the center of the screen, and just kind of moves the board beneath them. So if you hit left, in code, you move the player left, but visually, you keep the player in the same place and the board moves to the right. I hope thats clear. Really, I think that's most typical nowadays.

The second kind of scrolling is screen to screen. The best example of this is the original zelda, although I suppose we may be getting to the point where some people have never played the original zelda (oh, the injustice!). Anyway, in this kind of scrolling, you move the player around on the screen, and if they hit the edge of the screen moving out of it, then you change screens so that they are in the next 'room'. So if I hit left, my player visually moves left until he hits the edge of the screen, and then when I try to move left again, he shows up on the right side of the screen as though he just entered the next room over.

In either case, you'll update the screen based upon the players location. You check to see where they are in the game world, and what the offset is from them to the corner of your screen, and then draw the appropriate tiles in place based on that.

I know this has come up several times in the old forums, so you may want to search there. I know the macgamewiki has a link to the old forums on its FAQ page, in case you dont have one handy. Also, I know that gamedev.net has several articles related to tile based games, although I don't know whether any of them will be of assistance.

Spencer, good general explanation. In the case of the player being drawn in the middle, and scrolling the world, don't forget the case of when the player reaches the "edge" of the world. For example, in Warcraft the world simply won't scroll anymore as the player goes to the edge.

I haven't seen any Zelda "like" engines used in Mac games, so it would be nice if someone does one.

In fact, since this is an area which so many people come in contact with when making RPGs, it would be great for someone to whip up a nice scrolling framework, complete with multiple layers (like 3, floor, objects, high objects like trees). Make it flexible to handle various tile-sizes, etc...

On the subject of Zelda-like engines, a tutorial on this (Cocoa?) would also be really good. Any takers?

I was working on a Zelda like game for a while (and have recently started working on it again). It consisted of a map editing tool and the game. Basically, all I have is a character that walks around on a map and when it reaches an edge it goes to another map. If some one is interested in looking at the code I could clean it up and post it.

Quote:Originally posted by cloke I was working on a Zelda like game for a while (and have recently started working on it again). It consisted of a map editing tool and the game. Basically, all I have is a character that walks around on a map and when it reaches an edge it goes to another map. If some one is interested in looking at the code I could clean it up and post it.

If you could that would be nice... Unfortunately, that type of scrolling wouldn't be good for the game that I am developing, since it is a racing game.

Quote:Originally posted by swcrissmanThe best example of this is the original zelda, although I suppose we may be getting to the point where some people have never played the original zelda (oh, the injustice!).

I am proud to say that I have played the original Zelda. Perhaps that should be a new requirment in school... playing the original zelda... of course, they would have to find working Nintendos...

I'm working on a game of the former scrolling technique(keep the player still; move the map)- though even within that there are two animation modes, which I fondly call "The Dragon Warrior Approach" and "The Final Fantasy Approach." I spent a lot of time poring over these two carts to find out how animation worked in them... I'm porting, most copyright-infringingly, Final fantasy to Mac OS X, you see- the original game.
At any rate, final fantasy(ignoring the NPC sprites) works like this, in moving left:
move left 1/4 a tile.
switch to 'left2' frame.
move left 1/4 more tile.
pause.
move left 1/4 more tile.
switch to 'left1' frame.
move left 1/4 more tile.
end.

all movements in final fantasy go in four steps: in battle, for instance, the character slides forward, switches to 'battle walking' stance, slides forward, slides forward, switches to 'battle standing' stance, then performs the next action. 'attack 1' 'attack 2' 'attack 1' 'attack 2'. then, slides back in reverse of the former process. it's kind of cool, really...

the dragon warrior school hsa two frames constantly swapping, and movement only occurs at certain times. everyone who needs to move moves at that time, just slides forward while in the second frame.

incidentally, each movement on the map in final fantasy takes place in 50 millisecond-increments. so, 5 tiles per second.

what i'm planning on doing(haven't tested for speed) is using an NSTimer to fire off every 20 seconds and call a method that sets certain variables like orientation, background position, and frame to draw based on a modulo operation... if you're curious, I could post the code.

-(NS)joie

PS: I just beat the original Zelda last weekend. Also the original Final Fantasy. Also the original Dragon Warrior. Yes, I am a God, by the way. ^_^

For some reason, any arrow key input is received as "NSLeftArrowFunctionKey". I don't know why. It makes me sad.

Also, moving left and right is a LOT slower than moving up and down... about half as fast, maybe slower than that. Shall I chalk that up to the slowness of NSImage? I'm using a big one. And then a bunch of small ones. Yes, that's probably it. ^^;;

Quite frankly, CopyBits() and gWorlds creep me out, so I'll just wait until the end of summer to judge about sideways speeds... ^_^;; Or maybe I'll read up on some Carbon...

Anyway, hurray! I've got a good, sound, 2-d animation sprite engine groove goin'. It's a little laggy, but it'll pick up. and it only took me a day- hey wait, it DID only take a day, didn't it?? @_@ Wow... I love this platform! ^___^

... anybody know how I can get a cheesy MIDI to play? ^^;; (In the app, of course! Not in some evil embed tag. ^_^;;;

well. It seems that by using the [image lockFocus]; [image unlockFocus]; combo... the speeds increased astronomically. ^^;; Yay Apple! Now if only this happened automagically... but what's the magic behind it?

-joie

<edit>
by the way... a few posts up, I said I was going to fire an NSTimer every 20 seconds, this is patently false. 20 milliseconds. It was late last night. I'm sorry. ^^;
I got keyboard input to work by poking around these forums. ^_^ Now I can't get a MIDI to play in the background, but that isn't a huge deal... time to go work on collision detection and pushing the "A" button. ^_^
</edit>

Now there's collision detection. Other sprites. The ability to inspect one's surroundings. Support for locked doors. Support for LOTS OF TREASURE... also, support for boss monsters, conversations, teleporters, stairs, and washing your hands. ^_^ It's coming right along. All I need to do is find someplace to teleport to, and refactor the view subclass. fun fun! ^^;;

hooray for ugly and inelegant solutions! I turned the function into a method which only self invokes. Ugh. My function was working before I moved things around... but then it wouldn't work at all, anywhere. oh well.. now it compiles.

hm.. thanks. ^_^ But what you said about global variables is absolutely right. Why should it matter to the 2nd floor of the castle if the message box is open in the Temple of Fiends? thanks for the help. ^_^

You might want to check out SpriteWorld (a Mac C Sprite Animation Library) for your game. It makes tiling and scrolling easy (as well as scrolling without tiling). It also makes handling your sprites very easy.

Best part about it is that it is an open source project, so completely free to use.

Best example of a game using SpriteWorld is Ambrosia Software's lastest Escape Velocity game (Nova I think) which uses parts of spriteworld.

The only downside is that the current version (2.3.1) only supports Classic mac programming (compatible with systems 7 - 9.x (and OS X in classic mode)). The good news is that a new version (3.0) is coming closer to release. You can currently download an alpha version (fully functional, no known bugs) which supports Carbon development and Hardware Acceleration (OpenGl as well as QD3D RAVE), among other things.

I've been using SpriteWorld to make game similiar to Metroid, and it has made life much easier.