Scroll DXDraw
Can someone explain me how to make a DXDraw Scroll when I hit the directional keys? I am making a Map editor and when I move the DXDraw I also want to put what is in my bidimensinal array of what is shown in the DXDraw into a StringGrid, but since I don''t know how to scroll the DXDraw, I was getting some errors from the array (negative positions). Can someone help me?
I don''t fully understand what you''re after...
but here''s how you would so scrolling:
Let''s say this is your drawing routine
for J := 0 to 100 do
for I := 0 to 100 do
Draw(I * 30, J * 30, MyTile);
so if you wanted to implement scrolling, you''d alter it like this:
for J := 0 to 100 do
for I := 0 to 100 do
Draw(I * 30 + ScrollX, J * 30 + ScrollY, MyTile);
Now if you scroll to the left, you would increase ScrollX. If you scroll to the right you would decrease ScrollX.
If you scroll up, you would increase ScrollY and if you want to sroll down you would decrease ScrollY.
Make sure you only draw what''s on the screen by altering your drawing routine like this
for J := 0 to 100 do
for I := 0 to 100 do
if (I * 30 >= 0) and (I * 30 + 30 <= DXDraw.Width) and (J * 30 > 0) and (J * 30 + 30 <= DXDraw.Height) then
Draw(I * 30 + ScrollX, J * 30 + ScrollY, MyTile);
hope that helped.
but here''s how you would so scrolling:
Let''s say this is your drawing routine
for J := 0 to 100 do
for I := 0 to 100 do
Draw(I * 30, J * 30, MyTile);
so if you wanted to implement scrolling, you''d alter it like this:
for J := 0 to 100 do
for I := 0 to 100 do
Draw(I * 30 + ScrollX, J * 30 + ScrollY, MyTile);
Now if you scroll to the left, you would increase ScrollX. If you scroll to the right you would decrease ScrollX.
If you scroll up, you would increase ScrollY and if you want to sroll down you would decrease ScrollY.
Make sure you only draw what''s on the screen by altering your drawing routine like this
for J := 0 to 100 do
for I := 0 to 100 do
if (I * 30 >= 0) and (I * 30 + 30 <= DXDraw.Width) and (J * 30 > 0) and (J * 30 + 30 <= DXDraw.Height) then
Draw(I * 30 + ScrollX, J * 30 + ScrollY, MyTile);
hope that helped.
You might find the modified line
Draw((I * 30 + ScrollX) mod DXDraw.Width, (J * 30 + ScrollY) mod DXDraw.Height, MyTile);
executes a little faster and, instead of directly decrementing the scroll variables (mod does not like negative values), writing
ScrollX:=(ScrollX+DXDraw.Width -1) mod DXDraw.Width;
and
ScrollY:=(ScrollY+DXDraw.Height -1) mod DXDraw.Height;
will do the job.
Hope I haven't muddied the water.
Stevie
Don't follow me, I'm lost.
(Editted to correct a typo)
[edited by - Stevie56 on March 9, 2003 7:56:45 AM]
Draw((I * 30 + ScrollX) mod DXDraw.Width, (J * 30 + ScrollY) mod DXDraw.Height, MyTile);
executes a little faster and, instead of directly decrementing the scroll variables (mod does not like negative values), writing
ScrollX:=(ScrollX+DXDraw.Width -1) mod DXDraw.Width;
and
ScrollY:=(ScrollY+DXDraw.Height -1) mod DXDraw.Height;
will do the job.
Hope I haven't muddied the water.
Stevie
Don't follow me, I'm lost.
(Editted to correct a typo)
[edited by - Stevie56 on March 9, 2003 7:56:45 AM]
I think you may find the following link
http://www.gameprogrammer.net/index.php?fuseaction=tutorial.tutorial3
Covers your question.
Stevie
Don''t follow me, I''m lost.
http://www.gameprogrammer.net/index.php?fuseaction=tutorial.tutorial3
Covers your question.
Stevie
Don''t follow me, I''m lost.
You can make the TDXDraw bigger than the screen.
If, for instance, the display is 640x480 you can make
DXDraw1.Width := 800;
DXDraw1.Height := 600;
DXDraw1.Left := -100;
DXDraw1.Top := -100;
If you want to scroll the DXDraw, just move the Left and Top
If, for instance, the display is 640x480 you can make
DXDraw1.Width := 800;
DXDraw1.Height := 600;
DXDraw1.Left := -100;
DXDraw1.Top := -100;
If you want to scroll the DXDraw, just move the Left and Top
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement