Discord
Login
Community
DARK THEME

Drawing rectangles

I'm making a gamw in witch i use rectangles, i have disscovered that they draw from the center, can i instead make it draw from the bottom left corner?

setDrawAnchor affects how the object will be drawn relative to its location (x, y) .

drawRectCenter = function(x, y, width, height)
  screen.setDrawAnchor( 0, 0 )
  screen.drawRect( x, y, width, height, "red")
  screen.drawSprite("icon", x, y, width/2, height/2)
  screen.fillRound( x, y, 10, 10, "white")  
end

drawRectCorner = function(x, y, width, height)
  screen.setDrawAnchor( -1, -1 )
  screen.drawRect( x, y, width, height, "orange")
  screen.drawSprite("icon", x, y, width/2, height/2) 
  screen.fillRound( x, y, 10, 10, "white")
end

init = function()
  x = 0 
  y = 0
  angle = 0
end

update = function()
  x = sind( angle ) * 50
  y = cosd( angle ) * 50
  angle +=  0.5
end

draw = function()
  screen.clear()
  drawRectCenter( 0, 0, 100, 100)
  drawRectCorner( x, y, 100, 100)
end

Thanks i used another way, but it is still good to know.

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community