frysy712
09-27-2009, 01:17 AM
Hi
As the title says, I'm making a racing game (for a school project).
(a little bit to read if your a busy person so i bolded my exact problem and my questions are down the bottom)
I've made progress with the game but i've hit a brick wall and so i'm looking for help. At the moment I'm able to create a simple racing game by just setting up some barriers, moving the shape around the screen and using .left and .top properties for collisions (that's all simple). After that little experiment i decided to have a go at bitblt and scrolling the background instead of moving the actual car.
I did up my text file containing the tiles for the map and then loaded the file into my 2D array (still well and good so far). Next i loaded up the background onto the form using bitblt (only loads what will fit into the form) and i managed to get the "screen" moving around with user key presses (just like any sidescroller). The system works fine but the screen only moves if the user is holding down the key (obviously), what i want to achieve is the same kind of movement i used in my first experiment with .top and .left properties of the shape. I set up XSpeed and YSpeed variables, then used a timer to make PosX = PosX + XSpeed & PosY = PosY + YSpeed, where PosX and PosY is the position my bitblt function starts drawing from (basically this keeps the screen moving even after the user releases the key - pressing another key will not automatically make it start heading in that direction but rather slow it down until the speed is 0 and then start going the other way).
The problem is that the background will either move smoothly when only scrolling along the x axis
or
if i change my code, smoothly when scrolling along the y axis.
For example, when i run it with this code the screen only moves smoothly when its scrolling left or right:
For l = UpperBound To (LowerBound - 1) 'because the loop includes the first number we must minus "1" to make it loop 16 times and not 17 times
For f = LeftBound To (RightBound - 1)
'bitblt race track onto the screen (this is done 1 tile at a time)
BitBlt Me.hDC, (f * TileWidth) - XOffset, (l * TileHeight) - YOffset, TileWidth, TileHeight, picTiles.hDC, TileType(TrackArray(l, f)).XPos, 0, vbSrcCopy
Next f
Next l
In Code:
LeftBound is basically the ".left" position of the currently displayed tiles relative to the whole map (same for other boundaries)
The Offsets are just to get the bitblt to start drawing at 0, 0 on the screen
TileType(TrackArray(l, f).XPos just gets what tile needs to be drawn and tells it where to copy from
But if i reverse the order of the form loop i can get it only scrolling smootly going up or down:
For l = LeftBound To (RightBound - 1) 'because the loop includes the first number we must minus "1" to make it loop 16 times and not 17 times
For f = UpperBound To (LowerBound - 1)
'bitblt race track onto the screen (this is done 1 tile at a time)
BitBlt Me.hDC, (l * TileWidth) - XOffset, (f * TileHeight) - YOffset, TileWidth, TileHeight, picTiles.hDC, TileType(TrackArray(f, l)).XPos, 0, vbSrcCopy
Next f
Next l
Pretty obviously it does this because the for loop is either drawing the the tiles:
1 tile down for whole row of tiles across
or
whole column of tiles down for 1 tile across
Can anyone help?
Suggestions?
How should i get bitblt to draw the map evenly?
Any other ways of getting the background to scroll around like i want?
Should i just draw in the whole background at the start and then just move the background as a whole?E.g i could use bitblt to draw all the tiles into a picturebox and then bitblt the whole picturebox to the form (with boarder style set as fixed single) and then just scroll that instead of redrawing the tiles...
help is greatly appreciated!
As the title says, I'm making a racing game (for a school project).
(a little bit to read if your a busy person so i bolded my exact problem and my questions are down the bottom)
I've made progress with the game but i've hit a brick wall and so i'm looking for help. At the moment I'm able to create a simple racing game by just setting up some barriers, moving the shape around the screen and using .left and .top properties for collisions (that's all simple). After that little experiment i decided to have a go at bitblt and scrolling the background instead of moving the actual car.
I did up my text file containing the tiles for the map and then loaded the file into my 2D array (still well and good so far). Next i loaded up the background onto the form using bitblt (only loads what will fit into the form) and i managed to get the "screen" moving around with user key presses (just like any sidescroller). The system works fine but the screen only moves if the user is holding down the key (obviously), what i want to achieve is the same kind of movement i used in my first experiment with .top and .left properties of the shape. I set up XSpeed and YSpeed variables, then used a timer to make PosX = PosX + XSpeed & PosY = PosY + YSpeed, where PosX and PosY is the position my bitblt function starts drawing from (basically this keeps the screen moving even after the user releases the key - pressing another key will not automatically make it start heading in that direction but rather slow it down until the speed is 0 and then start going the other way).
The problem is that the background will either move smoothly when only scrolling along the x axis
or
if i change my code, smoothly when scrolling along the y axis.
For example, when i run it with this code the screen only moves smoothly when its scrolling left or right:
For l = UpperBound To (LowerBound - 1) 'because the loop includes the first number we must minus "1" to make it loop 16 times and not 17 times
For f = LeftBound To (RightBound - 1)
'bitblt race track onto the screen (this is done 1 tile at a time)
BitBlt Me.hDC, (f * TileWidth) - XOffset, (l * TileHeight) - YOffset, TileWidth, TileHeight, picTiles.hDC, TileType(TrackArray(l, f)).XPos, 0, vbSrcCopy
Next f
Next l
In Code:
LeftBound is basically the ".left" position of the currently displayed tiles relative to the whole map (same for other boundaries)
The Offsets are just to get the bitblt to start drawing at 0, 0 on the screen
TileType(TrackArray(l, f).XPos just gets what tile needs to be drawn and tells it where to copy from
But if i reverse the order of the form loop i can get it only scrolling smootly going up or down:
For l = LeftBound To (RightBound - 1) 'because the loop includes the first number we must minus "1" to make it loop 16 times and not 17 times
For f = UpperBound To (LowerBound - 1)
'bitblt race track onto the screen (this is done 1 tile at a time)
BitBlt Me.hDC, (l * TileWidth) - XOffset, (f * TileHeight) - YOffset, TileWidth, TileHeight, picTiles.hDC, TileType(TrackArray(f, l)).XPos, 0, vbSrcCopy
Next f
Next l
Pretty obviously it does this because the for loop is either drawing the the tiles:
1 tile down for whole row of tiles across
or
whole column of tiles down for 1 tile across
Can anyone help?
Suggestions?
How should i get bitblt to draw the map evenly?
Any other ways of getting the background to scroll around like i want?
Should i just draw in the whole background at the start and then just move the background as a whole?E.g i could use bitblt to draw all the tiles into a picturebox and then bitblt the whole picturebox to the form (with boarder style set as fixed single) and then just scroll that instead of redrawing the tiles...
help is greatly appreciated!