OgreVorbis wrote: ↑Thu Aug 19, 2021 7:29 am
Mijikai wrote: ↑Wed Aug 18, 2021 1:19 pm
Give this a try
First off, x is always zero. Why are you doing that second operation?
I'm not sure how you arrived at that. It doesn't work.
The second operation is multiplying by 32 (TileSize) by shifting its faster than normal multiplication.
The code works here is an example:
Code: Select all
EnableExplicit
Procedure.i ClipTile(Tile,Index.i,TileSize.i,TileMapWidth.i,*X.Integer,*Y.Integer)
Protected x.i
Protected y.i
y = Index / TileMapWidth
x = Index - (y * TileMapWidth)
*X\i = x * TileSize
*Y\i = y * TileSize
ProcedureReturn ClipSprite(Tile,*X\i,*Y\i,TileSize,TileSize)
EndProcedure
Procedure.i Sprite(Index.i,Color.i)
Protected x.i
Protected y.i
If CreateSprite(Index,133 * 8,8 * 8)
If StartDrawing(SpriteOutput(Index))
DrawingMode(#PB_2DDrawing_Outlined)
For y = 0 To 7
For x = 0 To 132
Box(x * 8,y * 8,8,8,Color)
Next
Next
StopDrawing()
ProcedureReturn #True
EndIf
FreeSprite(Index)
EndIf
ProcedureReturn #False
EndProcedure
Procedure.i Main(Index.i)
Protected exit.i
Protected x.i
Protected y.i
If InitSprite()
If OpenWindow(0,0,0,1920,1080,#Null$,#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget)
If OpenWindowedScreen(WindowID(0),0,0,1920,1080)
SetFrameRate(60)
Sprite(0,$FFFFFF)
Sprite(1,$222222)
Repeat
Repeat
Select WindowEvent()
Case #PB_Event_CloseWindow
exit = #True
Case #Null
Break
EndSelect
ForEver
ClearScreen($0)
DisplaySprite(1,120,200)
ClipTile(0,Index,8,133,@x,@y)
DisplaySprite(0,120 + x,200 + y)
StartDrawing(ScreenOutput())
DrawText(200,420,"Tile Index: " + Str(Index))
DrawText(200,440,"Tile Offset: " + Str(x) + " x " + Str(y))
DrawingMode(#PB_2DDrawing_Outlined)
Box(120,200,133 * 8,8 * 8)
LineXY(120 + x + 4,100,120 + x + 4,400)
LineXY(10,200 + y + 4,1600,200 + y + 4)
StopDrawing()
FlipBuffers()
Until exit
EndIf
CloseWindow(0)
EndIf
EndIf
ProcedureReturn #Null
EndProcedure
Main(500)
End