RotateSprite
RotateSprite SpriteIndex, Angle#
 
Parameters:

    SpriteIndex = The number of the sprite you wish to change
    Angle# = The angle (in degrees) by which you want to rotate this sprite
Returns: NONE
 

      The RotateSprite command sets the rotation angle (in degrees) of this sprite. By default a sprites rotation axis or rotation hot spot as you might know it, is in the top left hand corner of it's attached image (See SpriteImage). So if we rotate the sprite, the sprite engine with turn our sprites coordinates around this point. You can shift the axis by setting the rotation handle (see SpriteHandle), allowing it rotate around it's center, or anywhere you want.

      The following is example of a sprite thats been rotated rotated at 10 degree intervals from 0 to 90 degrees.



      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 effect of sprite rotation, the sprite needs to set to Rotation Mode using the SpriteDrawMode command. Sprites default drawmode is static/none rotated mode.

      * Note: For the best sprite rotation performance!, it's highly recommended that a sprites image be previously prepared in FX image format (see LoadFxIMage,LoadAFxIMage, PrepareFXimage )

      * RotateSprite automatically wraps the sprites rotation angle to between 0-360 degrees for you.

      * The sprite engine will accept rotations less than one degree, but be aware that rounding might occur when rendering.

      * Also see TurnSprite is a short cut command





Mini Tutorial:


      This example is really made up of three main 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 rotates the sprites and renders it


  
; Create a triangle image
  Size=50
  MyImage=NewFXImage(Size,Size)
  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()
  GetImage MyImage,0,0,size,size
  
  
; ========================
; Part 2 - Create our sprite
; ========================
  
; Create a new Sprite at position 100,100 showing MyImage
  MySprite=NewSprite(100,100,MyImage)
  
; Set sprite to Auto Center it's handle on any assigned image
  AutoCenterSpriteHandle MySprite,true
  
; set the sprites drawing mode to ROTATION (mode 2)
  SpriteDrawMode MySprite,2
  
  
; ========================
; Part 3 - The main Loop
; ========================
  
; Start a do/loop
  Do
   ; clear the screen
     Cls RGB(0,0,0)
     
   ;Set the rotation of the sprite
     RotateSprite MySprite,angle#
     
   ; Bump the rotation angle
     angle#=WrapAngle(angle#,1)
     
   ; 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: GetAngle2D | GetSpriteAngle | MoveSprite | PrepareFXimage | ScaleSprite | ScaleSpriteX | ScaleSpriteXY | ScaleSpriteY | SpriteDrawMode | TurnSprite :
 


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