Blitz3D+ Command Reference

PositionTexture texture,u_offset#,v_offset#

Parameters

texture - texture handle
u_offset# - horizontal offset, measured in whole textures
v_offset# - vertical offset, measured in whole textures

Description

Slides a texture across whatever it is painted on.

The offsets are absolute rather than relative, and are measured in whole textures: an offset of 1 shifts by exactly one tile, 0.5 by half a tile. To scroll, keep a float of your own and nudge it every frame - PositionTexture water,scroll#,0 with scroll# creeping upwards gives you flowing water, conveyor belts, waterfalls and drifting cloud layers for almost no cost.

Because the offset is absolute it never accumulates rounding error, and because tiling repeats every 1.0 you can keep your scroll variable small with scroll# = scroll# Mod 1.

This moves the texture, not one entity: every surface painted with this texture handle shifts at once. If one wall should scroll and another should stay put, load or create the texture twice so each has its own handle.

See also: ScaleTexture, RotateTexture, TextureCoords, EntityTexture.

Example

; PositionTexture Example
; -----------------------

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

camera=CreateCamera()
PositionEntity camera,0,2,-3
TurnEntity camera,20,0,0

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

; A mossy ground slab - scrolling its texture makes a cheap 'conveyor belt'
ground=CreateCube()
ScaleEntity ground,8,0.1,8
PositionEntity ground,0,-1,8
tex=LoadTexture("media/MossyGround.BMP")

; Tile the texture 4x4 so the scrolling is easy to see
ScaleTexture tex,0.25,0.25
EntityTexture ground,tex

v_speed#=0.005
v_off#=0

While Not KeyDown(1)

    ; Press + / - to change the scroll speed
    If KeyDown(13) Then v_speed=v_speed+0.0001
    If KeyDown(12) Then v_speed=v_speed-0.0001

    ; Scroll the texture by moving its UV offset every frame
    v_off=v_off+v_speed
    PositionTexture tex,0,v_off

    ; 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,"+ / - : scroll speed   Arrows: camera   Esc: exit"
    Text 0,20,"PositionTexture tex,0,"+v_off

    Flip

Wend

End

Index