How to scroll part of the screen + other Questions
BlitzMax Forums/BlitzMax Beginners Area/How to scroll part of the screen + other Questions
| ||
Hi, I'm writing a simple turn based strategy game that is working okay on a single screen 800 * 600 display. However, the actual game map is approx 1800 * 1800 and I want to be able to scroll in any direction should the cursor get a certain number of pixels away from the edge of the screen. Also, I want part of my screen to stay static (not scroll) as it contains, game information +---------------------------+ |static part of screen | +---------------------------+ | scrollable part of | | the screen | | | | | +---------------------------+ I'm also not sure how this will affect all my coords, having the top part of my screen static, and having the bottom part scrollable. I'm assuming I'll need to create some sort of offset so drawimage and drawtext still display within 800 * 600? Finally, I haven't loaded my background image yet either (I know lots of questions ;-)). I'm assuming tiles are the best way to go, but then how do I go about "joining up" my graphics where before (with a single image) I had a nice transition between my territority types (e.g. from sea to sand). With tiles won't the joins be rigid and very uniformed? Any help/advice/pointers to any of the above topics would be appreciated Regards, KaiserPC |
| ||
Tiles are the way to go and search Transition Tiles for the 'sea to land' query There's a good tutorial on GameDev.net. |
| ||
There's a command for only drawing to part of the screen... setviewport IIRC. So to offset your playing board 200 pixels down the screen it would be something like: Setviewport 0,200 setorigin 0,200 'your normal game drawing stuff here flip() You will have to look those commands up to be sure of the syntax, this is from memory. |
| ||
With tiles won't the joins be rigid and very uniformed? It is probably a matter of having enough tiles to provide the needed varity of transitions. setviewport Some people says that it doesn't always work. I have not experimented enough myself to know if this is true. There are some threads about it somewhere. |
| ||
The static part is easy. Just draw your game board y pixels down, and then draw your info bar. |
| ||
If you first drew the entire gameworld, fullscreen, and then simply drew the interface "on top", like a mask, acting as the interface you could have all your buttons and things on, and giving this mask a large transparent hole the gameworld showed through, would Blitz be smart enough to only render the parts of the gameworld visible through the mask? |
| ||
It renders what you draw in the order you draw it in even when it's outide the graphics coordinates, so if you are sure stuff isn't visible, don't draw it. |
| ||
not sure if this is what you looking for, but i wrote this up quickly. hope it helps. graphics used character: ![]() hud: ![]() background: background link |
| ||
Nice one! Looks like a good starter for 10 :-) thx for all the info/help so far |
| ||
glad you find it useful. its nothing fancy but like i said i just whipped it up quickly, but it should demonstrate atleast one way (not nessicarly the right way) to: -draw the images in a certian order and include the offsets where needed -scroll the map with the mouse although i think probably tiles would be better then one large image -move a charcter or object individually from the scroll - simple use of x and y offsets instead of hardcoding the movement ie. 10 it would be better to store it in a variable ie. global movementspeed = 10 but i'm sure you already know that ;-) |
| ||
SetViewport is borked on a geforce4mx at least.. |
| ||
Framework BRL.Max2D 'Triforce - Tied it down to minimal framework. Import BRL.D3D7Max2D Import BRL.PolledInput Import BRL.JPGLoader Import BRL.PNGLoader Graphics 800,600,0 'gfx Global background = LoadImage("background.jpg") Global character = LoadImage("character.png") Global hud = LoadImage("hud.png") 'var Global mapXcenter = ImageWidth(background)/2 Global mapYcenter = ImageHeight(background)/2 Global characterX = 400 Global characterY = 300 Global Xoffset,Yoffset Global ScrollBoarder = 100 While Not KeyDown(key_Escape) Cls 'draw background 'draw the image from the center of the image to the center of the screen 'and add the xoffet and yoffset 'DrawImage background,(400-mapXcenter)+Xoffset,(300-mapYcenter)+Yoffset TileImage background,(400-mapXcenter)+Xoffset,(300-mapYcenter)+Yoffset '//Triforce 'draw the character 'draw the image at the characters x and y positions 'and add the xoffet and yoffset DrawImage character,characterX + Xoffset,characterY + Yoffset 'draw the static image DrawImage hud,0,0 'controls 'move the character If KeyDown(key_Left) Then characterX :-10 If KeyDown(key_Right) Then characterX :+10 If KeyDown(key_Up) Then characterY :-10 If KeyDown(key_Down) Then characterY :+10 '//Triforce - I added that it check whether or not left mouse button is down. It got rather annoying for the screen to keep on scrolling when switching over to task manager. 'scroll the map If MouseX() < ScrollBoarder And MouseDown(1) Then Xoffset:+10 If MouseX() > 800 - ScrollBoarder And MouseDown(1) Then Xoffset:-10 If MouseY() < ScrollBoarder And MouseDown(1) Then Yoffset:+10 If MouseY() > 600 - ScrollBoarder And MouseDown(1) Then Yoffset:-10 DrawText "MouseX(): "+MouseX(),10,540 DrawText "MouseY(): "+MouseY(),10,550 DrawText "Xoffset: "+Xoffset,10,570 DrawText "Yoffset: "+Yoffset,10,580 Flip - 1 'Triforce - Flip -1 uses less CPU, and I prefer it. You can change it if you want. GCCollect();Wend 'Garbage collection, and repeat While loop. End That's my own edition to the code. Here's the shrunk background. ![]() Everything else wasn't touched. @KingNothing: How do you make the code boxes that small and scrollable? |
| ||
code box = [ codebox ] add code here [ /codebox ] remove the spaces between the [] check this FAQ link nice addition btw, and i know what you mean about scrolling when the mouse is out side the window. simple enough check to add but i was on my way out and just quickly threw together the basic example. |
| ||
Haha.. I was really, really bored so I thought I'd cook up a small rough OOP example. There really isn't any code differences. I just took what you had and turned it into OOP. |
| ||
nice i like. now if your REALLY bored, few things you could do is: 1: instead of tilemap set it to scroll the border of the map to the border of the viewable hud area. 2: get it to take any size map(load different maps) 3: add some basic npc's (static or other) 4: be able to interact with npc's(talk,fight..etc) 5: add static objects that you can or can not interact with(rocks,trees,houses,shops etc.) objects like trees and rocks you can't pass through, but maybe houses and shops you can enter. 6: any thing else interesting that you can think of. then you would have a great little example game, but only if your REALLLLLY bored and have the time ;-) i would love to see what you or anyone else may/could/would come up with, i might even check it out if i get some time. |
| ||
On SetViewport borked: thats incorrect. It works correctly. But on DX7 it uses a technique that needs at least a GeForce 3 level card as it uses clipplanes for the cutting and cards lower than that like GF4 MX and some older intel and S3 only support 2 clip planes while 4 are needed. |
| ||
That SetViewport problem is a funny one. My game project uses it and I have yet to meet a card that has problems with it in DX mode (players can choose between OpenGL and DX as they please). It works with my ThinkPad T40 (age-old ATI Mobility Radeon 9500) and all desktops I've tried so far at work, most of them boasting some low-end integrated Intel chips. Most recently I tested a laptop with a crappy Intel 910-series mobile chip. It works with both DX and GL, although it struggles with keeping up the FPS. So, I can safely assume that any hardware capable of running my game does not suffer from the dreaded SetViewport problem? |
| ||
Out of all honesty, Vilu, it's best to stick with your own methods to drawing a camera. If it really bothers you that SetViewport is funny, then make your own alternative. It would probably be better anyways since it could potentially be faster, simpler, etc.. As for this whole topic I think somebody should write a tutorial. I have this in mind, but I dunno. All I can suggest is to check out Binaryphoenix's World Artist and download the source code. The source code is actually pretty good and understandable. Well commented, clean, etc... Just go to here register an account, then look under the projects section for World Artist. But yeah, I do agree with you, KingNothing.. It would be interesting to see what somebody could do on their freetime with that basic source code :P. |
| ||
ya Triforce like i said i'd love to see what different people come up with, and i still might give it a go myself eventually. but for me right now, the past several days have been spent trying to incorporate multiplayer into my game at a 50/50 win/lose ratio. but thats off topic,so ya if anyones interested feel free to make any additions, or how you'd do what is existing better. |
| ||
Hi, thx again for the initial code :-) I've now got it working the way I want and it should be scaleable based on the resolution. I'm remaking an old strategy game (still early stages) on the c64 that just uses keys so I'm not using the mouse at the moment. I've got it to scroll when it's 2 tiles away from the hud, so that you can see what tile you are going to move on (obviously I've stopped it scrolling when you get to the screen edge). I've got an array or 29,29 to hold my TMap tiles and I'm only drawing the tiles if they are in view (x + xOffset < xRes and the same for y). Still need to look for code to "merge" my tiles together as everything still looks too "Uniformed" but at least the engine is working :-) |
| ||
Yeah.. that OOP code isn't exactly the best, it's really rough. Can't wait to see what will come out of your works! :P |
| ||
ya awsome job, can't wait to see how it turns out. im not sure i understand your last statement, do you me graphicly the tiles don't blend together. if so try a seemless texture creating prog, theres a couple made by blitzers floating around on this site, but i can't remember by who. if i find a link i'll add it. if its something else, i don't quite understand what you mean. |
| ||
yep, you are right. I'm currently drawing some transitional graphics that are 10 pixels wide, and about 17 pixels high that will cover the edges of my hexes. I'll need 3 of these for every type of terrain that touches another type of terrain (bit long winded I know) my hex..._ ............/...\\ ...........|.....|| ............\...// the double slashes and pipe show where my transitional image is displayed (\\ = x+25) (|| = x+51, y+17) ( // = x+25, y+73) for my 56,73 tiles I have extended my TMap class to contain 3 new timages (along with my existing tile image), transitionalBottomRight, transitionalRight and transitionalTopRight. When I'm setting up my array of TMaps I check the terrain of the tile to the top right, right and bottom right and then load the appropriate image. Then it's just a case of drawing the 3 transitional images at the appropriate coords. |