TurnSprite
TurnSprite SpriteIndex, Angle#
 
Parameters:

    SpriteIndex = The number of the sprite you wish to check
    Angle# = The angle you wish to rotate this sprite
Returns: NONE
 

      The TurnSprite command changes (turns) the current rotation angle of the sprite. Turning the sprite a positive value turns it clockwise and a negative value will turn it anticlockwise. The rotation angle with wrap if the angle exceeds 360 degrees and drops bellow 0. So it'll always be in 0-360 range.

      TurnSprite is a short cut command much like MoveSprite, where it's main usage is to reduce code complexity. You can achieve equivalent functionality using the RotateSprite command as per the following example. But turn sprite is simpler and faster.

  
  RotateSprite ThisSprite, GetSpriteAngle(ThisSprite) + Angle#
  


      Here's an animated example of sprite rotating around it's center. The ship is rotating at 15 degree intervals.






FACTS:


      * In order to see the sprite rotation, the sprites Drawmode needs to set to Rotation Mode. See SpriteDrawMode command.

      * Note: For the best performance!, it's highly recommended that a scaled sprites image be previously prepared/loaded in FX image format (see PrepareFXimage, LoadFXImage)

      * Also see RotateSprite




Mini Tutorial:


      This example is really 3 parts.

      Part #1 creates a image out of a triangle shape and a circle.

      Part #2 creates the sprite, the sprite is then set to render the previously created image as it's graphic to rotate.

      Part #3 is the main do/loop. Which allows the user to rotates the sprites with the left/right arrows key controls and then renders it

  
; ========================
; Part 1 - Create an image
; ========================
  
; Create a Little triangle image
  Size=50
  Shape=NewConvexShape(Size*0.50,3)
  RotateShape Shape,30,1
  DrawShape Shape,Size/2,size/2,2
  CircleC size/2,size/2,size/5,1,RndRGB()
  MyImage=GetFreeImage()
  GetImage MyImage,0,0,size,size
  PrepareFXImage MyImage
  
  
; ========================
; Part 2 - Create our sprite
; ========================
  
; Create the Sprite
  Sprite1=NewSprite(100,100,MyImage)
  
;  Set sprite Center it's handle on any image
  AutoCenterSpriteHandle Sprite1,true
  
; set the sprites drawing mode to ROTATION (mode 2)
  SpriteDrawMode Sprite1,2
  
  
; ========================
; Part 3 - The main Loop
; ========================
  
; Start a do/loop
  Do
   ; clear the screen
     Cls RGB(0,0,0)
     
   ; Display a message to the screen
     Print "Use the LEFT & RIGHT arrows to turn the sprite"
     
   ; If the LEFT arrow key is pressed then turn the sprite
   ; -5 degrees.
     If LeftKey()=true Then TurnSprite Sprite1,-2
     
   ; If the RIGHT arrow key is pressed then turn the sprite
   ; 5 degrees.
     If RightKey()=true Then TurnSprite Sprite1,2
     
   ; Draw all the created sprites
     DrawAllSprites
     
   ; Draw the screen
     Sync
     
   ; Loop back to the DO statement
  Loop
  




This example would output.

  
  no Text output
  


 
Related Info: GetSpriteAngle | PrepareFXImage | RotateSprite | ScaleSprite | SpriteDrawMode :
 


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