Blitz3D+ Command Reference

Origin x,y

Parameters

x - x offset added to drawing coordinates; may be negative

y - y offset added to drawing coordinates; may be negative

Description

Shifts the origin that drawing coordinates on the current buffer are measured from.

After Origin x,y, a drawing command's coordinates have x,y added to them - drawing at 0,0 actually lands at the origin point. That turns "position on screen" into "position in the world": set Origin -camera_x,-camera_y and draw everything at world coordinates to get scrolling for free. It is also the cheap way to do screen shake - a small random Origin each frame, drawing code untouched.

It affects the drawing commands (Plot, Line, Rect, Oval, Text, images...) on the current buffer - not the Fast pixel commands, which ignore it. Origin resets to 0,0 whenever you SetBuffer, so set it after choosing your buffer, and remember to set it back (Origin 0,0) before drawing fixed things like the HUD.

See also: Viewport, SetBuffer, Rect, Text.

Example

; Origin Example
; --------------

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

ox=0
oy=0

While Not KeyDown(1)

    Cls

    ; Arrow keys scroll the world by moving the drawing origin
    If KeyDown(203) Then ox=ox+4
    If KeyDown(205) Then ox=ox-4
    If KeyDown(200) Then oy=oy+4
    If KeyDown(208) Then oy=oy-4

    ; Origin shifts every subsequent drawing command by ox,oy
    Origin ox,oy

    ; A "world" drawn at fixed coordinates - moving the origin scrolls it
    For gx=0 To 4
        For gy=0 To 3
            Color 60+gx*40,120,60+gy*50
            Rect gx*150+40,gy*130+60,80,80,1
        Next
    Next
    Color 255,255,0
    Oval -10,-10,20,20,1
    Text 15,-6,"world 0,0"

    ; Reset the origin so the overlay stays fixed on screen
    Origin 0,0
    Color 255,255,255
    Text 0,0,"Arrow keys: scroll the world   Esc: exit"
    Text 0,20,"Origin "+ox+","+oy

    Flip

Wend

End

Index