News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

How can i smooth scrolling a grid?

Started by Big C., January 28, 2012, 05:51:36 PM

Previous topic - Next topic

Big C.

Hi,

I need your help because I didn't come behind the logic myself...  :(

Problem:
I have a 2-Dim-Array with 25 elements. Each element represents a Image. I want to scroll smooth the 5*5 Grid from top to a position y= 100, beginning with the complete last row (in my example it was row 4) of representing images of the Array.

If row 4 passes the first row of the grid then it have to switch to second row and row 3 and 4 of the array began to scroll down and so on.
I hope you understand me.

here ist my code...

Type T_Gem
Image
Xpos
YPos
EndType

Dim Gem(4,4) As T_Gem

count = 1
i = 0
j = 4
y=20
While count < 26
If i = 5
i = 0
j--
EndIf

Gem(i,j).Image = NewImage(20,20,1)
RenderToImage Gem(i,j).Image
Text 2,2, Str$(count)
RenderToScreen
Gem(i,j).Xpos = 15+(i*20)
Gem(i,j).Ypos = 15+(j*20)
i++
count++
EndWhile
j = 4
;waitkey
While j>-1

Do
y=Mod(y+4,20)
Print y

If y = 0
y = 20
ExitDo
EndIf


For i = 0 To 4
DrawImage Gem(i,j).Image, Gem(i,j).Xpos, 25+y, 1
Next
Sync
WaitKey
FlushKeys
Cls

Loop
j--
EndWhile

End


FYI: After the grid reaches his goal position I want to inter act with the single images...

Any Ideas how i can make the scrolling thing? Should i use sprites instead of pure images?

Thx 4 help

Big C.

I got the way...


setfps 30

Dim Gem(4,4)

count = 1
y = 0

For Row = 4 To 0 Step -1
For Col = 0 To 4
Gem(Col,Row) = NewImage(20,20,1)
RenderToImage Gem(Col,Row)
BoxC 0,0,19,19,0,RGB(255,69,0)
Text 2,2, Str$(count)
RenderToScreen
count++
Next
Next

waitkey

Do
Cls

If y <> 168
y=Mod(y+4,170)
Print y
Else
y = 168
EndIf

reDraw(y)

If SpaceKey()
y = 0
Flushkeys
EndIf

Sync

Loop

End

Function reDraw(t_y)

For Row = 4 To 0 step -1
For Col = 0 To 4
DrawImage Gem(Col,Row), (20*Col)+50, (20*Row)-120+t_y, 1
Next
Next
EndFunction


Can I achieve improvements?


kevin


You could draw the grid to an Image, then just draw the image.. or use a  Map.  It doesn't really do anything worth worrying about at this point.