Skip to main content
GameDev.net gamedev.net
🔒 Locked

Scroll DXDraw

Started by wArPeR Mar 8, 2003 at 7:22 PM 4 replies 750+ views
Original Post
wArPeR
wArPeR
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?
Harry Hunt
Harry Hunt
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.
stevie56
stevie56
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]
StevieDon't follow me, I'm lost.
stevie56
stevie56
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.
StevieDon't follow me, I'm lost.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.