I'm relatively new to PB, but I had been using the demo for a while.
I am now trying to make a simple game to work on my skills. In the game, all of the sprites need to be flipped horizontally in order to be realistic. Flipping the files would double the sprite count.
So I found this code from another old post on here. I was unable to find any other code. The problem is that on the first loop "For j = 0", it says invalid memory access (read error at address 0). The poster said it was working, but it doesn't work for me.
In my code I use PNG decoder and then I just do a bunch of LoadSprites, then I CopySprite, then I flip it with this code, then I DisplayTransparentSprite.
I'd appreciate some help. This is the one thing that I really think needs to be added to the built in sprite library. It is something very commonly needed and it seems that PB is very good at providing extensive built-in functions, but in this case it seems lacking.
Code: Select all
Procedure HFlipSprite(SpriteNumber.l)
SpriteAddress.l
ArrayAddress.l
StartDrawing(SpriteOutput(SpriteNumber))
DrawingBuffer = DrawingBuffer()
DrawingBufferPitch = DrawingBufferPitch()
SpriteHeight = SpriteHeight(SpriteNumber)
SpriteWidth = SpriteWidth(SpriteNumber)
Dim Array.l(SpriteHeight - 1, SpriteWidth - 1)
MemoryLength = SpriteHeight * SpriteWidth * 4 - 4
ArrayAddress = @Array()
For i = 0 To SpriteHeight - 1
SpriteAddress = DrawingBuffer + DrawingBufferPitch * i
For j = 0 To SpriteWidth - 1
! MOV eax, dword [esp+4] ; PokeL(ArrayAddress, PeekL(SpriteAddress))
! MOV ebx, [eax]
! MOV eax, dword [esp+8]
! MOV [eax], ebx
ArrayAddress + 4
SpriteAddress + 4
Next
Next
For i = 0 To SpriteHeight - 1
For j = 0 To (SpriteWidth - 1) / 2
x = Array(i, j)
Array(i, j) = Array(i, SpriteWidth - 1 - j)
Array(i, SpriteWidth - 1 - j) = x
Next
Next
ArrayAddress = @Array()
For i = 0 To SpriteHeight - 1
SpriteAddress = DrawingBuffer + DrawingBufferPitch * i
For j = 0 To SpriteWidth - 1
! MOV eax, dword [esp+8] ; PokeL(SpriteAddress, PeekL(ArrayAddress))
! MOV ebx, [eax]
! MOV eax, dword [esp+4]
! MOV [eax], ebx
ArrayAddress + 4
SpriteAddress + 4
Next
Next
StopDrawing()
EndProcedure

