CreateSprite()
Syntax
Result = CreateSprite(#Sprite, Width, Height [, Flags])Description
Creates an empty sprite with the specified dimensions. SpriteOutput() can be used to draw on the sprite.
Parameters
#Sprite A number to identify the new sprite. #PB_Any can be used to auto-generate this number. Width, Height The size of the new sprite (in pixels). Flags (optional) It can be a combination of the following values (with the '|' operator): #PB_Sprite_PixelCollision: Add special information to handle pixel collision through SpritePixelCollision(). #PB_Sprite_AlphaBlending : Sprite is created with per pixel alpha-channel support, needed for DisplayTransparentSprite(). #PB_Sprite_Transparent : Sprite is created fully transparent (alpha channel value set to 0). If used, DrawingMode() should be set to #PB_DrawingMode_AllChannels when using SpriteOutput().
Return value
Nonzero if the sprite has been created, zero otherwise. If #PB_Any was used for the #Sprite parameter then the generated number is returned on success.
Remarks
CreateSprite() has to be called in the same thread where OpenScreen() was called.
Example: CreateSprite using transparent flag
InitSprite()
OpenWindow(0, 0, 0, 640, 480, "A screen in a window...", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(0), 0, 0, 640, 480, #True, 0, 0)
CreateSprite(0, 64, 64, #PB_Sprite_AlphaBlending | #PB_Sprite_Transparent)
If StartDrawing(SpriteOutput(0))
DrawingMode(#PB_2DDrawing_AllChannels)
Circle(16, 16, 8, RGBA(255, 0, 0, 255)) ; Opaque red circle
Circle(32, 32, 8, RGBA(0, 255, 0, 128)) ; Semi transparent green circle
StopDrawing()
EndIf
Repeat
Repeat ; It's very important to process all the events remaining in the queue at each frame
Event = WindowEvent()
If Event = #PB_Event_CloseWindow
End
EndIf
Until Event = 0
ClearScreen(RGB(0, 0, 0)) ; A black background
DisplayTransparentSprite(0, 300, 200)
FlipBuffers()
ForEver
Else
Debug "Can't open windowed screen!"
EndIf
See Also
GrabSprite(), SpriteOutput()
Supported OS
All