CreateSprite
CreateSprite SpriteIndex
 
Parameters:

    SpriteIndex = The identifier of the sprite you wish to create
Returns: NONE
 

      CreateSprite initializes a sprite entity and adds it to PlayBasic active sprite list ready for use.


What are Sprites ?

      Sprites can be thought of as an extended control layer over the image commands. The sprite system gives the user much easier and faster interface for controlling many images as once. Like we'll need when writing a game.

      The Sprite system includes controls for handling sprites depth ordering, collision, movement, local data through to real time rendering effects like Alpha Blending and Rotation to name a few. You can think of sprites as being the entity which houses the display properties of each characters appearance in your game, while the Image is merely the picture information.

      When we create a sprite, the CreateSprite command initializes our selected sprites properties to their defaults. It's properties are things like it's position, rotation angle, draw mode, collision mode, local data and of course it's image. Before a sprite can be visualized to the screen, it needs to be assigned an image to render (see SpriteImage). When a sprite is drawn, PlayBASIC uses the sprites current properties (it's X position,Y position, DrawMode, Rotation etc) to render the sprites assigned image at it's current location.



Sprite Defaults

      X position = 0
      Y position = 0
      Z position = 0
      Image = 0
      ImageHandleX = 0
      ImageHandleY = 0
      AutoCenterSpritehandles =0
      DrawMode = 0
      Filter = 0
      Rotation = 0
      ScaleX = 1.0
      ScaleY = 1.0
      Collision = 1
      CollisionClass = 1
      TintColour = RGB(255,255,255) ($ffffff)






FACTS:


      * Before you can see a sprite, you must assign it an image (that exists), then draw your sprites via DrawSprite, DrawALLSprites or DrawOrderedSprites

      * For sprites to be drawn based upon their Z order, you must use either DrawOrderedSprites or capture them to a scenebuffer (CaptureToScene and let the camera order them.

      * For Dynamic sprite creation see NewSprite

      * See GetFreeSprite to dynamically request free sprite index


 
Example Source: Download This Example
; =====================================================
; First Create an Image with a ball like pattern on it.
; =====================================================
  
  Circle_Image=CreateBallImage(100)
  
  
; =========================================================
; Create Sprite
; =========================================================
  
  CreateSprite 1
  
; Set Sprite 1 to use our circle image for it's artwork
; to display.
  SpriteImage 1,Circle_Image
  
; Randomly position this sprite within the screen on the screen..
  PositionSprite 1,Rnd(GetScreenWidth()),Rnd(GetScreenHeight())
  
  
; Direct All Drawing to the Screen
  RenderToScreen
  
; Tell PB to limit speed of the program to 60 Frames
; (updates) per second or bellow
  SetFPS 60
  
  
; Start out update loop
  Do
     
   ; Clear the Screen to black   0= rgb(0,0,0)
     Cls RGB(0,0,0)
     
     
   ; Display a message
     Print "Rendering All the Created Sprites"
     
   ; Tell Pb to DRaw all the srpites now
     DrawAllSprites
     
   ; Display the screen and loop back to the DO statement
   ; to keep the program running
     Sync
  Loop EscKey()=true
  
; Tell PB to end this program
  End
  
  
  
  
Function CreateBallImage(Size)
  ThisImage=NewImage(size,size)
  RenderPhongImage ThisIMage,size/2,size/2,RGB(128+Rnd(127),128+Rnd(127),128+Rnd(127)),200,255.0/(size/2)
EndFunction ThisImage
  
 
Related Info: DeleteSprite | GetFreeSprite | GetSpriteStatus | NewSprite | SpriteCollision | SpriteImage | SpriteQuantity :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com