Help with viewports
BlitzMax Forums/BlitzMax Beginners Area/Help with viewports
| ||
Hi all, I was hoping that someone could help me with viewports, it's just not clicking with me. I can understand the sample that comes with blitzmax, but when i come to trying to expand on it for my own needs i can't get things to work right. What i want is to have a gameplay area of any given size, and a viewport (say 800*600 in size) centered around the player, so that when the user moves the player ship the view port remains centered and the background scrolls accordingly. Any clues/example code for this would be greatly appreciated. Cheers Charlie |
| ||
Afaik viewport is broken on some videocards, so I'd go without it. (unless it has been fixed??) I actually think you don't really need a viewport, as there're alternative ways to solve your situation. |
| ||
You might be looking to use SetOrigin... maybe?The viewport should always stay where you put it but it's the graphics you need to move. |
| ||
Use a projection matrix and simply offset the origins thus preventing the need to recalculate the position of every object every frame. In fact you could use the same method in most tile based games where you'd chuck all the tiles into a static vertex array (static since the tiles don't need to move) and move the view (camera) around. |
| ||
Afaik viewport is broken on some videocards, so I'd go without it. (unless it has been fixed??) Erm its hard to fix something that is a hardware and/or driver problem, not a BM problem, you know :) |
| ||
I know.. I didn't say it was it was BRL's problem, just that viewport is broken.. but ok: I'll refine that by saying that the viewport doesn't work on some videocards.. happy? ^_^ |
| ||
Say that your game world is stored in an a 2d-array, telling you what each tile contains. So if you have variables for the player's X and Y coordinate, and you want the view area to extend 5 tiles away from the player, then make a nested for-loop (one of the X, one for the Y) that goes from the player's position minus 5 to the player's position plus 5, being careful to check that you're not going outside the bounds of the array. Then simply draw those tiles onto the screen. |
| ||
Yeah it doesn't work on some cards. Seen it with my own eyes. Find another solution. |