SetTranslation

This function sets a context's drawing translation.

Syntax

Parameters

Example

window = Window:Create()
context = Context:Create(window)
local font = Font:Load("Fonts/Arial.ttf",48)
context:SetFont(font)

while true do
if window:Closed() or window:KeyHit(Key.Escape) then return false end

Time:Update()

local a = Time:GetCurrent()*0.1

context:SetColor(0,0,1)
context:Clear()

--Draw some text centered on the screen
local text = "Hello!"

local x = context:GetWidth()/2
local y = context:GetHeight()/2

local w = font:GetTextWidth(text)
local h = font:GetHeight()

local scale = Math:Sin(a)*0.5 + 1.0

context:SetRotation(a)
context:SetScale(scale,scale)
context:SetTranslation( -(Math:Cos(a)*w - Math:Sin(a)*h)/2 * scale, (-Math:Sin(a)*w - Math:Cos(a)*h)/2 * scale )

context:SetBlendMode(Blend.Alpha)
context:SetColor(1,1,1)
context:DrawText(text,x,y)
context:SetBlendMode(Blend.Solid)

context:Sync()
end