|
This thread is locked; no one can reply to it. |
1
2
|
Screen "Scrolling" |
Simsimius
Member #6,017
July 2005
|
Well, here's the story. I decided to make my first game that uses an area larger then the default game screen. Since I've never done this before, I got the basic game template I always use. So the game has a black background, and one sprite. Because in order to create a larger area I defined the size of the virtual screen. #include <allegro.h> #define VIRTUAL_W 2400; #define VIRTUAL_H 1800; And in my movement code, I have this:
I'm trying to get the current screen to go the next area (Normally, X=0. I want the X=800, which is the next area/screen). Any help with what I'm doing wrong? ____ |
James Stanley
Member #7,275
May 2006
|
Can we see your scroll_screen function? |
Simsimius
Member #6,017
July 2005
|
I'm using the Allegro scroll screen: int scroll_screen(int x, int y);
Quote:
Attempts to scroll the hardware screen to display a different part of the virtual screen (initially it will be positioned at 0, 0, which is the top left corner). You can use this to move the screen display around in a large virtual screen space, or to page flip back and forth between two non-overlapping areas of the virtual screen. Note that to draw outside the original position in the screen bitmap you will have to alter the clipping rectangle with set_clip_rect(). Allegro will handle any necessary vertical retrace synchronisation when scrolling the screen, so you don't need to call vsync() before it. This means that scroll_screen() has the same time delay effects as vsync(). Return value: Returns zero on success. Returns non-zero if the graphics driver can't handle hardware scrolling or the virtual screen is not large enough. See also: set_gfx_mode, show_video_bitmap, request_scroll, request_video_bitmap. So, any ideas on what I've done wrong? EDIT: If you can't reply to this post, then PM me. ____ |
LennyLen
Member #5,313
December 2004
|
Well, since scroll_screen() can only be called in your code when (xpos == SCREEN_W - sprite->w), I'd be checking whether or not this expression is ever true.
|
Simsimius
Member #6,017
July 2005
|
Great idea! I entered this code in the character class: and the output file does say "Xpos DOES equal SCREEN_W - sprite->w". So it does turn out to be true. I must be doing something wrong with the scroll_screen. Any ideas? ____ |
LennyLen
Member #5,313
December 2004
|
Did you read the following part of the scroll_screen() section of the manual? Quote: Mode-X scrolling is reliable and will work on any card, other drivers may not work or not work reliably. See the platform-specific section of the docs for more information. [edit]You should really be checking the return value as well.
|
Simsimius
Member #6,017
July 2005
|
Return value for what? And I can't seem to find the relevant information in the docs about "Mode X". Sorry for asking too much, but I'm still a "beginner". ____ |
Ariesnl
Member #2,902
November 2002
|
Why don't you make a "camera" and draw everything according to your camera position ? [one moment'I'll grab my code] 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
|
Mode X is an archaic DOS graphics mode. Anyway, the usual way of doing scrolling is not by using virtual screen space and the *_scroll() functions, but by changing the position of objects you blit to the screen. -- |
LennyLen
Member #5,313
December 2004
|
Quote: Return value for what? The return value of the call to scroll_screen. Try this: if(xpos == SCREEN_W - sprite->w) { if (scroll_screen(800, ypos) != 0) allegro_message("scroll_screen() failed!\n"); exit(-1); }
|
Ariesnl
Member #2,902
November 2002
|
void TSprite::draw(int camx,int camy) { int DrawX=int(screenmid_x+(x-camx)); int DrawY=int(screenmid_y+(y-camy)); // only draw what we see if ((image!=NULL)&&(DrawX+(image->Width()/2)>0)&&(DrawX-(image->Width()/2)<800)&&(DrawY+(image->Height()/2)>0)&& (DrawY-(image->Height()/2)<600)) { image->BlitRotated(DrawX, DrawY,angle,opacity); } } this is my sprite drawing code .. the camx,camy coords are the MIDDLE of your viewscreen so if there is a spaceship at (10500,600) and your camera is also at (10500,600) the spaceship will appear in the middle of your screen and sprite coords are the middle of the sprite NOT top left... why ? easier to make the aiming and docking AI code 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
|
Quote:
gnolam I think I get what you mean, however, that would be more complicated then having everything written to the virtual screen, and just making the screen scroll. Quote:
Ariesnl [one moment'I'll grab my code] I think you might be on the same idea as gnolam. However, I'll have to wait and see. EDIT: EDIT2: And everyone: ____ |
Ariesnl
Member #2,902
November 2002
|
look again 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
|
I saw it and edited my post. But I don't fully understand that method. Would you be able to explain in more detail? Thanks. EDIT: Hold on, I think I got it. So, the screen remains the same, but you have camx and camy, which can be as large as whatever, and all characters, AI, etc. follow those set of co-ordinates? ____ |
Ariesnl
Member #2,902
November 2002
|
By the way I'm using Openlayer so some functions are diffrent.. However it is highly advised to use OpenLayer... Quote: So, the screen remains the same, but you have camx and camy, which can be as large as whatever, and all characters, AI, etc. follow those set of co-ordinates? ... In the oposite direction offcourse 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
|
I think I can manage to get a similar method in Allegro. But I have just wondered something about the initial scroll-screen function: ____ |
Ariesnl
Member #2,902
November 2002
|
I don't know actually 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
|
The more I think about the method, the more sense it makes. Hopefully, this is what I plan to do: Using this, all objects, code, etc. will be placed according to camx and camy. The only thing I can't work out is how to scroll, BUT, I think that using x++ and y++ for camx and camy (for when the player moves) will work. Btw, how do I "reward" people who helped me via the forum? I DO tick the box marked "The question has been answered to my satisfaction!", right? ____ |
LennyLen
Member #5,313
December 2004
|
Quote: Was I meant to create a bitmap for the entire virtual screen? Yes, definitely. [edit] Quote: Btw, how do I "reward" people who helped me via the forum? I DO tick the box marked "The question has been answered to my satisfaction!", right? See previous answer.
|
Ariesnl
Member #2,902
November 2002
|
yes just camx++ will sctoll to the left (as the camera goes to the right) and so on If you check the "question was answered..." you'll get a credit list BTW what game are you making ? 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
|
Lennylen: Quote:
Quote: How should I go around doing this (just to check if it works). Ariesnl: ____ |
LennyLen
Member #5,313
December 2004
|
Quote: How should I go around doing this (just to check if it works). Take a look at the exscroll.c example that came with Allegro. Actually, you should try running ex_scroll.exe, as if it doesn't work, then you'll know that hardware scrolling isn't available on your system.
|
Simsimius
Member #6,017
July 2005
|
I will. Ariesnl: How would I, for example, get the following primitive to be at a certain camC and camY point (I'm using the primitive to test it out) circlefill(buffer, int x, int y, int radius, int color); EDIT: This isn't easy. The code you supplied above doesn't seem too easy to understand. EDIT: Quote: Unable to set a 320x240 mode with 640x240 virtual dimensions
EDIT3: ____ |
Tobias Dammers
Member #2,604
August 2002
|
Simsimius: Even if the scrolling functions happen to work on your particular computer, I suggest you never touch them again. Seriously. draw_sprite(playerspr, screenbuffer, x, y); the new code would say: draw_sprite(playerspr, screenbuffer, x + scroll_x, y + scroll_y);
As long as you apply the same offset to all drawing operations, you achieve the same effect as hardware scrolling. --- |
Simsimius
Member #6,017
July 2005
|
So, let me get this straight, the method I originally tried is not recommended, at least by you. ok. Now, the code you showed me near the bottom looks promising. So, draw_sprite(playerspr, screenbuffer, x + scroll_x, y + scroll_y);
The value of scroll_x scroll_y should be the size of the area beyone the usual 800, 600? Correct? 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 >_< ____ |
|
1
2
|