CreateSpriteLocals
CreateSpriteLocals SpriteNumber, Size
 
Parameters:

    SpriteNumber = The Index of the sprite you wish to attach the data to
    Size = The size of the local variable/data area for this sprite
Returns: NONE
 

      CreateSpriteLocals attaches a bank of user memory to a sprite. This memory can be used to store any custom data, values, strings inside a sprite you wish. You can think of it as custom data storage for the sprite.

      This data could be used to store a sprites inventory, animation frames, a path, the sprites name perhaps, extra collision data or anything really.




FACTS:


      * When the sprite is deleted or copied, the Local data is handled also.



Mini Tutorial:


      This example creates some sprites, then attaches the sprite a local data area.


  
  
  
; Start a For/Loop of 1 to 10
  For ThisSpr=1 To 10
     
   ; Create a Sprite
     CreateSprite ThisSpr
     
   ; Attach a Local data area, 10 bytes long
   ; to this sprite
     CreateSpriteLocals ThisSpr,10
     
   ; Store some random numbers in this sprites
   ; local data area
     For Address=0 To 9
        SpriteLocalByte ThisSpr,Address,Rnd(255)
     Next
  Next
  
  
; Start a For/Loop of 1 to 10
  For ThisSpr=1 To 10
     s$=""
   ; Read the bytes values out of this sprites local data
     For Address=0 To 9
        s$=s$+Str$(GetSpriteLocalByte(ThisSpr,Address))+","
     Next
   ; Diplays the sprite index and the local data
     Print "Sprite #"+Str$(ThisSpr)+"  "+TrimRight$(s$,",")
  Next
  
; Display the screen and wait for a key press
  Sync
  WaitKey
  
  



This example wouldoutput something like this.

  
  Sprite #1  122,30,150,51,14,22,167,99,236,236,61,102,172,113,54,66,172,121,4,125
  Sprite #2  183,244,113,158,198,25,9,184,173,188,94,235,210,169,114,183,253,221,58,251
  Sprite #3  223,56,121,202,85,195,254,210,162,122,60,161,55,228,153,52,97,231,202,82
  Sprite #4  46,207,194,188,72,38,189,179,37,56,232,6,100,99,161,4,74,154,94,69
  Sprite #5  49,47,160,98,19,157,50,203,31,68,249,22,162,121,169,213,81,181,125,198
  Sprite #6  200,221,29,185,160,18,122,167,94,111,20,89,199,166,78,153,146,18,94,53
  Sprite #7  89,235,243,38,55,29,190,155,121,229,156,8,68,254,15,252,169,241,35,213
  Sprite #8  77,84,85,62,214,84,112,120,118,253,6,75,222,208,2,151,235,134,127,188
  Sprite #9  97,98,252,194,169,245,3,192,44,125,202,214,165,82,103,137,28,39,58,5
  Sprite #10  60,128,32,133,160,157,174,109,63,83,31,175,82,11,113,54,155,65,125,105
  


 
Related Info: DeleteSpriteLocals | GetSpriteLocalByte | GetSpriteLocalFloat | GetSpriteLocalInt | GetSpriteLocalPtr | GetSpriteLocalSize | GetSpriteLocalString | GetSpriteLocalWord | SpriteLocalByte | SpriteLocalFloat | SpriteLocalInt | SpriteLocalString | SpriteLocalWord :
 


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