Advertisement

Scrolling again... with DDRAW..

Started by May 29, 2000 11:12 PM
5 comments, last by HellRiZZer 24 years, 6 months ago
I got a code.. It perfectly scrolling within one screen, but i dont'' know how to scroll it after one screen.. please help me if u can.. send a post with ur e-mail i''ll send u my editor.. TA!!
You want to redo your scrolling engine then. Usually when you do scrolling, you just increment the screen position by a certain amount

for scrolling right or down
screen_pos_x += scroll_rate;
screen_pos_y += scroll_rate;

for scrolling left or up;
screen_pos_x -= scroll_rate;
screen_pos_y -= scroll_rate;

scroll_rate and screen_pos will either be in pixels or tiles.

Then just make sure the screen_pos_x & y dont go off the edge of the map.

Then just redraw the map with the new screen_pos

Possibility
Advertisement
I know what you''ve wrote, but TA anyway..
I have a problem with DDraw..
They got dy and dx as positions to blit to and i got ViewX and ViewY . They''re increasing when i scroll.
But my mouse coords on screen are all the same while im scrolling or not:0 to 800 for x and 0 to 600 for y.
so, while i''m scrolling new tiles are visible but screen coords are the same..
I''m looking for some kind of stretching onto screen. do u know function StretchBlt in APi calls?
I''m asking if there some kind of that in DX7.
I''ll send u example have a look. Thanks!!
Going from screen coordinates to map coordinates is really easy, especially if your measuring View_x in pixels, its just

Mouse_On_Map_x = View_x + Mouse_x;

that you probably already know, but what I am guessing what you want is that you have a tile, and its location is defined as to where its on the map, but when you blit it to the back buffer, you need to define its location as to where its on the screen. Here is how I do that, you know where the upper left corner of the screen is at --> View_x & View_y, now that is the point of where the screen is at on the map, and that point on the screen itself is at (0,0). Now what you have to do is find what tile that is in.
Lets say for example (view_x, view_y) = (120, 25) and each tile is 20pixels by 20 pixels. So you find what tile it is in. the view_x/20 = 6.000 -> convert that to an int, so x_ultile (upper left tile - my own naming convention), then take 25/20 = 1.25 convert that float to an int, so = 1 so your in tile (6,1) -- assumming the the upper left most tile is (0,0).

Now you should already have it defined to as how many tiles there are across the screen, rounded up. So you start a 2 for loops, one for Y tiles and for loop inside that for X tiles. So in your for loops for X and Y you have i and j as the for loop counters, so you go from tile (6,1) to (6+x_number_of_tiles_across_screen, 1+y_number_of_tiles_across_screen) so each tile inbetween is (6+i,1+j) or (x_ultile + i, y_ultile + j).

Then tile (6,1) is blitted at (view_x,view_y) and this tile will need to be clipped since the top 5 pixels will be cut off y_offset = view_y - tile_height*y_ultile; --> rct.top = y_offset = 125 - 20*6 = 5; rct.left = x_offset = view_x - tile_widht*x_ultile = 120 - 6*20 = 0; so blit that tile at (0,0) with:
rct.left = x_offset;
rct.right = tile_width;
rct.top = y_offset;
rct.bottom = tile_height,

then tile (7,1) is then blitted at (0 + tile_width*i - x_offset, 0 + tile_height*j - y_offset) with i and j are from the X and Y for loops and
rct.left = 0;
rct.right = tile_width;
rct.top = y_offset;
rct.bottom = tile_height;

so that is way you go from map coordinates to screen coordinates, then each time you blit a tile, check to make sure the whole tile is on the screen, if its not (like the example above) then you have to clip the tile like i just showed you, there is a bit more math involved but that is the basic premise for square tiles and iso tiles are nearly identical.

Possibility

Edited by - Possibility on May 31, 2000 10:23:03 PM
Well I have a quick question, it may seem kinda basic but I''m stumped as to how to go about doing this. I see here about how to scroll a tile but how do you load the tile. do I have to make a map editor first then make my map. I guess my question would be how do I make the map and once I have it how would I go about loading it... I''m sorry if I sound stupid ^_^

Kuno
at your level I would suggest making a game without a level editor first.

//end
Advertisement
I suppose that he have to make map editor first, its much easier to implement it after using DX..
I did all my work in that way.. First ,learning simple API functions, after - DX ..
Try to go that way, and if you can''t do something, post here to me a help or i will. I''m intermediate in DDRAW only, but after will be in DXMUSIC and DXSOUND and DXINPUT.. Or, u can find some tutorials here, in gamedev, or look in links..
"NeHe is not HeHe" )

This topic is closed to new replies.

Advertisement