|
sprite - sprite handle x_scale# - horizontal scale; 1 (default) y_scale# - vertical scale; 1 (default) |
|
Sets the size of a sprite. A sprite spans -1,-1 to +1,+1, so a scale of 1,1 makes it two units across and two units tall. The scale is absolute, not relative, so setting it repeatedly is safe - which is exactly what you want for a smoke puff that grows as it rises, or an explosion flash that swells and fades. The two axes are separate, so uneven scales stretch the sprite: 1,4 gives a tall thin sliver for a laser bolt or a spark trail, 4,1 a wide flat shockwave. Matching the scale to the aspect ratio of the artwork stops a sprite looking squashed. Use this rather than ScaleEntity. A sprite has no mesh to scale, and its size lives in the sprite itself; the same goes for RotateSprite in place of RotateEntity. Scaling happens around the sprite handle, so a sprite handled at its bottom edge grows upwards rather than in both directions - handy for flames and growing plants. The value is interpolated between updates along with everything else, so a sprite that changes size each UpdateWorld still looks smooth at high frame rates. See also: CreateSprite, LoadSprite, HandleSprite, RotateSprite, SpriteViewMode. |
; ScaleSprite 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 pulsing logo pickup
logo=LoadSprite("media/b3dlogo.jpg")
PositionEntity logo,0,1.5,0
base#=1
pulse#=0
While Not KeyDown(1)
; Change the base size with [ and ]
If KeyDown(26) And base>0.2 Then base=base-0.01
If KeyDown(27) And base<3 Then base=base+0.01
; ScaleSprite sets the sprite's x and y size independently - pulse the
; width and height out of phase for a wobbly pickup effect
pulse=pulse+3
x_scale#=base+Sin(pulse)*0.25
y_scale#=base*0.5+Cos(pulse)*0.15
ScaleSprite logo,x_scale,y_scale
; 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 base size Arrows: camera Esc: exit"
Text 0,20,"ScaleSprite logo,"+x_scale+","+y_scale
Flip
Wend
End