LOCKSPRITE

Top  Previous  Next

Syntax

INT = LOCKSPRITE(sprite as POINTER)

Description

Locks a sprites buffer to allow direct memory access to the sprites image data.

Parameters

sprite - Sprite pointer returned by LoadSprite.

Return value

Returns the current lock count if the sprite could be locked or -1 on error. The lock count is incremented by 1 every time LOCKSPRITE is called and decremented by 1 every time UNLOCKSPRITE is called. If the lock count is greater then zero then this function simply returns the lock count for performance reasons.

Remarks

A locked sprite allows direct access to the image memory using standard pointers. Every call to LOCKSPRITE must be paired with a call to UNLOCKSPRITE or sprite drawing will fail.

See Also: UNLOCKSPRITE, LOADSPRITE, GETSPRITEPITCH, GETSPRITEPOINTER

Example usage

DEF pBuffer as POINTER
sprite1 = LOADSPRITE(GETSTARTPATH+"bug.bmp",0,0,3)
LOCKSPRITE sprite1
pitch = GETSPRITEPITCH sprite1
pBuffer = GETSPRITEPOINTER sprite1
'Change the first pixel of the sprite to red
#<UINT>pBuffer = RGBToScreen(RGB(255,0,0))
'Change the first pixel on the next line to green
pBuffer += pitch
#<UINT>pBuffer = RGBToScreen(RGB(0,255,0))
UNLOCKSPRITE sprite1