Scrolling tiles? - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Scrolling tiles? (/thread-7780.html)
Pages: 1 2
Scrolling tiles? - Josh - May 7, 2002 07:42 PM
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?
Scrolling tiles? - swcrissman - May 8, 2002 06:58 AM
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.
Scrolling tiles? - Carlos Camacho - May 8, 2002 04:38 PM
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?
Scrolling tiles? - cloke - May 8, 2002 05:41 PM
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.
Scrolling tiles? - Josh - May 8, 2002 06:31 PM
Quote:Originally posted by clokeIf 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 swcrissmanI 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...
Scrolling tiles? - Unregistered - Jun 5, 2002 09:41 PM
A few things:
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.
move left 1/4 more tile.
switch to 'left1' frame.
move left 1/4 more tile.
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.
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. ^_^
Scrolling tiles? - Carlos Camacho - Jun 5, 2002 09:51 PM
cloke, we always need example code. So please do clean it u0p, stuff-it and email it to me..
Scrolling tiles? - Unregistered - Jun 5, 2002 11:12 PM
Yatta! Folks, it worked out fine. Well, mostly fine. Two caveats:
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. ^_^;;;
Scrolling tiles? - NecrosaJoe - Jun 5, 2002 11:24 PM
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?
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. ^_^
Scrolling tiles? - NecrosaJoe - Jun 6, 2002 09:44 PM
another update, if anyone cares. ^_^
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! ^^;;
Scrolling tiles? - NecrosaJoe - Jun 6, 2002 11:30 PM
"Build failed(see build log for details)"
"/usr/bin/ld: multiple definitions of symbol _mBoxBordRect
/Users/osword/Desktop/Funk You/build/Funk You.build/Funk You.build/Objects-normal/ppc/ZoneView.o definition of _mBoxBordRect in section (__DATA,__common)
/Users/osword/Desktop/Funk You/build/Funk You.build/Funk You.build/Objects-normal/ppc/ConeriaCastleFloorOneView.o definition of _mBoxBordRect in section (__DATA,__common)
/usr/bin/ld: multiple definitions of symbol _mBoxOrig
/Users/osword/Desktop/Funk You/build/Funk You.build/Funk You.build/Objects-normal/ppc/ZoneView.o definition of _mBoxOrig in section (__DATA,__common)
/Users/osword/Desktop/Funk You/build/Funk You.build/Funk You.build/Objects-normal/ppc/ConeriaCastleFloorOneView.o definition of _mBoxOrig in section (__DATA,__common)
/usr/bin/ld: multiple definitions of symbol _resetMBoxRects
/Users/osword/Desktop/Funk You/build/Funk You.build/Funk You.build/Objects-normal/ppc/ZoneView.o definition of _resetMBoxRects in section (__TEXT,__text)
/Users/osword/Desktop/Funk You/build/Funk You.build/Funk You.build/Objects-normal/ppc/ConeriaCastleFloorOneView.o definition of _resetMBoxRects in section (__TEXT,__text)
...failed MasterObjectFile.Combine /Users/osword/Desktop/Funk You/build/Funk You.build/Funk You.build/Objects-normal/ProjectBuilderMasterObjectFile.o ..."
the relevant lines are, I believe:
mBoxOrig = NSMakePoint(96, 416);
mBoxBordRect = NSMakeRect(0, 144, 448, 32);
@interface ZoneView : NSView
Sigh, this is the pain that comes with refactoring... any insight would be appreciated as to why I cannot compile. I've already scrapped my build directory, twice. myarg. ^_^;; can I get a hand?
Scrolling tiles? - NecrosaJoe - Jun 6, 2002 11:43 PM
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.
Scrolling tiles? - OneSadCookie - Jun 7, 2002 12:29 AM
Sounds like the standard declaration vs definition problem that new C coders always run into in their first large-ish project.
The solution is to declare the variables/functions extern in the header, and define them (ie no extern) in a single source file.
It's been covered before, I think on this forum. A search should turn up the discussion.
The real solution, of course, is not to have global variables
Scrolling tiles? - NecrosaJoe - Jun 7, 2002 08:12 AM
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. ^_^
Scrolling tiles? - WFleming - Jun 9, 2002 08:26 PM
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.
Check it out at http://www.spriteworld.org
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.