RotateSprite sprite,angle#

Parameters

sprite - sprite handle
angle# - rotation angle, in degrees; 0 (default)

Description

Spins a sprite in its own flat plane.

The angle is absolute rather than a relative turn, so RotateSprite s,45 always leaves the sprite at 45 degrees whatever it was before. Because the sprite normally faces the camera, this reads as a straightforward spin on screen - the right tool for tumbling debris, swirling smoke, spinning pickups and rotating shockwaves.

Rotation happens about the sprite handle, so the default centre handle spins it on the spot while a handle at the bottom edge makes it swing.

Use this rather than RotateEntity, which would turn a camera-facing sprite in ways you cannot see. Giving each particle in a burst a different starting angle is the cheapest way to stop a cloud of identical sprites looking like a repeated stamp.

The angle is interpolated between updates, so a sprite that spins a few degrees per UpdateWorld still looks smooth at high frame rates.

See also: CreateSprite, LoadSprite, ScaleSprite, HandleSprite, SpriteViewMode.

Example

; RotateSprite Example
; --------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,1,-5

light=CreateLight()
RotateEntity light,45,45,0

ground=CreatePlane()
EntityTexture ground,LoadTexture("media/MossyGround.BMP")

; A spinning logo pickup
logo=LoadSprite("media/b3dlogo.jpg")
ScaleSprite logo,1,0.5
PositionEntity logo,0,1.5,0

angle#=0
spin#=2

While Not KeyDown(1)

    ; Change the spin rate with [ and ]
    If KeyDown(26) Then spin=spin-0.05
    If KeyDown(27) Then spin=spin+0.05

    ; RotateSprite sets the sprite's absolute roll angle, so we keep our
    ; own accumulating angle and apply it every frame
    angle=angle+spin
    RotateSprite logo,angle

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"[ / ]: change spin rate   Arrows: camera   Esc: exit"
    Text 0,20,"RotateSprite logo,"+angle

    Flip

Wend

End

Index