|
|
This thread is locked; no one can reply to it.
|
1
2
|
| Screen "Scrolling" |
|
Ariesnl
Member #2,902
November 2002
|
Top down games need animations too but it's simple just have a pImage pointer that will point to the correct frame
mytimer will be decreased by some timer function Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
|
Simsimius
Member #6,017
July 2005
|
Thanks for the animation code. I'm just still trying to figure out how to scroll. I've got a pen and paper, trying to work out how to get any method of scrolling to work. ____ |
|
Kikaru
Member #7,616
August 2006
|
My method for animation works like this: you declare an array of *BITMAPS, one for every frame, then a number in the object, like int frame; to say which array element to draw. It works really well with draw_sprite functions too! |
|
Ariesnl
Member #2,902
November 2002
|
Take one piece of paper... draw something on it take a second piece of paper .. cut a rectangle hole in it.. put the second one over the 1st one .. Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
|
gnolam
Member #2,030
March 2002
|
Quote: EDIT: No, hang on, the above can't be right. Would it be possible to explain just a little. It seems simple, but I can't figure it out completely. I just can't think today >_< Think of it like this: instead of moving the camera, you're moving the world. draw_sprite(playerspr, screenbuffer, x, y); scroll_x = 10, scroll_y = 0; draw_sprite(playerspr, screenbuffer, x - scroll_x, y - scroll_y); Draw playerspr at 10 pixels left of the previous position. This is equivalent to the "camera" moving 10 pixels to the right. -- |
|
Ariesnl
Member #2,902
November 2002
|
NO! NEVER just move the world .. always seperate WORLD and SCREEN coords !! Otherwise you'll have a hell of a time implementing intelligence. Try implementing A* when recalculating everything according to a scroll value.. Work with simple World coords and let the draw function decide where to draw according to the camara's centerpoint like I showed you also if you do something like this if ((pPlayer!=NULL)&&(!pPlayer->destroyed)) { camx=pPlayer->x; camy=pPlayer->y; } else { // Do some end of game scrolling }
the camera will follow the player nicely Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
|
gnolam
Member #2,030
March 2002
|
Quote: NEVER just move the world .. always seperate WORLD and SCREEN coords !!
No shit Sherlock - that's exactly what the concept of a camera does. -- |
|
Ariesnl
Member #2,902
November 2002
|
you can't say shit here ? I guess you're right.. I was thinking about some OpenGL tut I once had that told me to move the world instead of the cam .. and I (inexperienced as I was thought it was smart... it wasn't) Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
|
Simsimius
Member #6,017
July 2005
|
Trying to take into account what you both say, I tried almost all methods here. The camera wasn't too easy, as I was unable to workout how to implement it in my game (and I found it hard for objects to keep to the cam co-ordinates). The scroll_x and scroll_y seems to work quite well. I just keep the player fixed in the centre and force the scroll_y and scroll_x to implement depending on what direction the player moves. The only trouble here is the AI. But I suppose, as the code above states, using -scroll_x and -scroll_y for the X and Y for all code, I'm sure it can work, right? Btw, does this thread get locked if I say the question has been answered? ____ |
|
Ariesnl
Member #2,902
November 2002
|
In this thread http://www.allegro.cc/forums/thread/587038 Download and view the code and the exe just ignore the tilemap code if it's too complicated Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
|
Simsimius
Member #6,017
July 2005
|
Thanks for the link. A lot of code there, but it does seem useful. (Btw, opened the exe. Looks good). ____ |
|
Ariesnl
Member #2,902
November 2002
|
There's also A* in it you'll need that once you go coding complex AI in a map based game Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
|
Simsimius
Member #6,017
July 2005
|
At the moment I intend to stay simple - at least to get an engine of some sort fully operational, complete with a sample level and graphics, etc. I intend to create some AI that fire invisible rectangles, which are destroyed with a collision with a wall, and, when collide with a player, cause the AI to attack. Hopefully, it will work. Even if it is just for the sake of getting everything else working. ____ |
|
Evert
Member #794
November 2000
|
Quote: Because in order to create a larger area I defined the size of the virtual screen.
It's fine to use this feature if available (though probably a waste of time, see below), but you should be aware that not all drivers are capable of doing this. |
|
Tobias Dammers
Member #2,604
August 2002
|
Let me take a shot at explaining the camera. First of all, forget that there is such a thing as a screen. All your object coordinates are "world" coordinates, and can be whatever you want them to be - meters, feet, yards, miles, you name it. For a simple 2d game, you may choose pixels, but for clarity's sake, I'll use meters as an example. Implement all your game logic (object movement and interaction) using this "world" coordinate set. All positions, velocities, sizes, and whatnot, are stored as meters (or whichever unit you chose). Now comes the drawing part (which, ideally, is separated from logic). To draw the scene, you need to transform "world" coordinates into "screen" coordinates, and the object that achieves this is a camera or camera transform. The camera must do two things: Scale, and translate. Let's assume you specify the camera position in world coordinates; then you'd start with translating. This is easy: Just subtract the camera position from each object's position: x_trans = x - cam->x; y_trans = y - cam->y; Now for the scaling. You need to define a scaling factor for the world units you use, in other words, you need to know how many pixels one unit has. Let's assume 32 pixels per meter: cam->scalefac = 32; x_screen = (x - cam->x) * cam->scalefac; y_screen = (y - cam->y) * cam->scalefac; And finally, you want the camera location displayed at screen center, not top-left, so we'll add another translation to the mix: There you go. If you happen to choose pixels for your units, the scale factor is 1, so you can then leave out the multiplication step. I leave it as an exercise for you to reverse the translation (read: find the world coordinates for a given screen position). --- |
|
|
1
2
|