Hi !
i'm interested only by vertical scrolling. i use this piece of code into my project. When i increase the number of tiles, the scrolling is slow. Coz the for-next loop inside the Compute_one_row_Scrolling() and Draw_one_row (). How to avoid the for-next loop ? I'm searching a better solution.
i my game i use an editor to produce a level, next i read a file. so i must keep this structure.
Col = 0 to 32, Row 0 to 1000 or more.
Type TBrick
Field Col
Field Row
End Type
(indexed by Row, and Col)
i know scrolling examples into tutorials. i prefer some help to correct this code.
Many thanks for your help !
i'm interested only by vertical scrolling. i use this piece of code into my project. When i increase the number of tiles, the scrolling is slow. Coz the for-next loop inside the Compute_one_row_Scrolling() and Draw_one_row (). How to avoid the for-next loop ? I'm searching a better solution.
i my game i use an editor to produce a level, next i read a file. so i must keep this structure.
Col = 0 to 32, Row 0 to 1000 or more.
Type TBrick
Field Col
Field Row
End Type
(indexed by Row, and Col)
i know scrolling examples into tutorials. i prefer some help to correct this code.
Many thanks for your help !
Strict Global List_bricks : TList = CreateList() Type TBrick Field Col Field Row Field r Field g Field b Field x Field y ' ---------------------------------------------------------------------------------------------- Function Create:TBrick (X,y) Local b:TBrick = New TBrick b.Col = x b.Row = y b.r = Rand (100,255) b.g = Rand (100,255) b.b = Rand (100,255) ListAddLast List_bricks, b Return b End Function ' ---------------------------------------------------------------------------------------------- Function Compute_one_row_Scrolling (Row, ScrollY) For Local b:TBrick = EachIn List_bricks If b.Row = Row Then b.x = b.Col * 32 b.y = ScrollY End If Next End Function ' ---------------------------------------------------------------------------------------------- Function Draw_one_row (Row) For Local b:TBrick = EachIn List_bricks If b.Row = Row Then SetColor b.r, b.g, b.b DrawRect b.x, b.y, 32,32 End If Next End Function ' ---------------------------------------------------------------------------------------------- Function MySort:Int(o1:Object, o2:Object) Local diff% = TBrick(o1).Row - TBrick(o2).Row If diff = 0 Then diff = TBrick(o1).Col - TBrick(o2).Col EndIf Return diff End Function ' ---------------------------------------------------------------------------------------------- Function Sort_the_list () SortList(List_bricks,True,MySort) End Function ' ---------------------------------------------------------------------------------------------- End Type ' create some tiles for this example (i use an editor for my game) ' if you increase max_row, the scrolling is slow, coz the for-next loop into the ' Compute_one_row_Scrolling(). Local Max_row = 100 For Local y=0 To Max_Row For Local x=0 To 31 TBrick.Create (x, y) Next Next ' sort them by y and x (not usefull here, but the game editor don't sort them...) TBrick.Sort_the_list() ' go Graphics 1024,768 Local t Local ScrollY = 0 Local Row = 0 Local TimeScroll = MilliSecs() While Not KeyDown(KEy_ESCAPE) ' compute scrolling If TimeScroll + 20 < MilliSecs() Then If ScrollY < 31 Then ScrollY = SCrollY + 1 Else ScrollY = 0 If Row < Max_row + 25 Then Row = Row + 1 Else Row = 0 End If End If t = MilliSecs() Local Decal = -32 For Local r = row To (row-24) Step - 1 TBrick.Compute_one_row_Scrolling(r,ScrollY + Decal) Decal = Decal + 32 Next t = MilliSecs() - t TimeScroll = MilliSecs() End If ' draw Cls For Local r = row To (row-24) Step - 1 TBrick.Draw_one_row(r) Next DrawText "time=" + String(t), 0,0 DrawText "row=" + String(row), 0,30 Flip Wend
