@microu
1) Ne mélange pas les gadgets avec le Screen graphique ! Utilise les Sprites !
2) /!\ Attention : Le DisplaySprite() se met HORS d'une boucle de dessin :
Sinon zéro. Nada. Que dalle (Donc difficulté avec les sprites)...
3) Voici un code d'exemple rudimentaire pour faire du défilement avec sprites.
* Toute la Map est dans le tableau Tile(x,y).
* La structure TILE est prête à recevoir d'autres attributs que No (numéro)
* Les 2 sprites d'exemple sont les N°1 et N°2 (1 = vide; 2 = brique)
* La Map fait 16 écrans de large par 16 écrans de haut
* Tu peux repérer là où toutes les briques sont au hasard : c'est là que tu chargeras une Map
* En gros, tu rajoutes des sprites au fur et à mesure et tu construit ta scène dans le tableau Tile(x, y)
* xCount/yCount = nb de colonne/nb de ligne
* xsCount/ysCount = nb de colonnes à l'écran/nb de lignes
>> N'hésite pas à me dire si ça bugue ou pas.
Code : Tout sélectionner
; Ollivier
; Juin 2008
wTile = 48
InitSprite()
InitKeyboard()
ExamineDesktops()
dw = DesktopWidth(0)
dh = DesktopHeight(0)
dd = DesktopDepth(0)
OpenScreen(dw, dh, dd, "Sprites et défilements")
For I = 1 To 2
CreateSprite(i, wTile, wTile)
Next
StartDrawing(SpriteOutput(1) )
Box(0, 0, wTile, wTile, $BFBFBF)
StopDrawing()
StartDrawing(SpriteOutput(2) )
Box(0, 0, wTile, wTile, $FFFFFF)
Line(0, 0, wTile, wTile, $0)
Line(47, 0, -wTile, wTile, $0)
Line(0, 0, wTile, 0, $0)
Line(0, 0, 0, wTile, $0)
Line(47, 0, 0, wTile, $0)
Line(0, 47, wTile, 0, $0)
For i = 1 To (wTile / 2) - 2
Box(i + 1, i, wTile - 2 * i - 2, 1, RGB(0, 255, 255) )
Box(i + 1, wTile - i - 1, wTile - 2 * i - 2, 1, RGB(0, 0, 255) )
Box(i, i + 1, 1, wTile - 2 * i - 2, RGB(0, 160, 160) )
Box(wTile - i - 1, i + 1, 1, wTile - 2 * i - 2, RGB(0, 160, 160) )
Next
StopDrawing()
Structure TILE
No.L
EndStructure
xsCount = dw / wTile
ysCount = dh / wTile
xsLimit = xsCount - 1
ysLimit = ysCount - 1
xCount = xsCount * 16
yCount = ysCount * 16
xLimit = xCount - 1
yLimit = yCount - 1
Global Dim Tile.TILE(xLimit, yLimit)
For y = 0 To yLimit
For x = 0 To xLimit
Tile(x, y)\No = 1
If Random(7) = 0: Tile(x, y)\No = 2: EndIf
If ((x < 2) Or (y < 2) ) Or ((x > xLimit - 2) Or (y > yLimit - 2) )
Tile(x, y)\No = 2
EndIf
Next
Next
Repeat
Delay(10)
FlipBuffers()
ClearScreen(0)
For y = 0 To ysLimit + 2
For x = 0 To xsLimit + 2
vx = x - ShRX
vy = y - ShRY
DisplaySprite(Tile(vx, vy)\No, x * wTile - ShX, y * wTile - ShY)
Next
Next
StartDrawing(ScreenOutput() )
DrawText(10, 0, "")
StopDrawing()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Right)
If AccX < (wTile / 2)
AccX + 2
EndIf
EndIf
If AccX > 0
If ShRX > 0 - (xCount - xsCount - 2)
If ShX < wTile
ShX + AccX
Else
ShX - wTile
ShX + AccX
ShRX - 1
EndIf
EndIf
AccX - 1
EndIf
If KeyboardPushed(#PB_Key_Left)
If AccX > (0 - (wTile / 2) )
AccX - 2
EndIf
EndIf
If AccX < 0
If ShRX < 0
If ShX > 0
ShX + AccX
Else
ShX + wTile
ShX + AccX
ShRX + 1
EndIf
EndIf
AccX + 1
EndIf
If KeyboardPushed(#PB_Key_Down)
If AccY < (wTile / 2)
AccY + 2
EndIf
EndIf
If AccY > 0
If ShRY > 0 - (yCount - ysCount - 2)
If ShY < wTile
ShY + AccY
Else
ShY - wTile
ShY + AccY
ShRY - 1
EndIf
EndIf
AccY - 1
EndIf
If KeyboardPushed(#PB_Key_Up)
If AccY > (0 - (wTile / 2) )
AccY - 2
EndIf
EndIf
If AccY < 0
If ShRY < 0
If ShY > 0
ShY + AccY
Else
ShY + wTile
ShY + AccY
ShRY + 1
EndIf
EndIf
AccY + 1
EndIf
Until KeyboardPushed(#PB_Key_Escape)