add scale to draw2d image

This commit is contained in:
2025-07-20 11:48:05 -05:00
parent 8fb50a129f
commit ff7b2f4db7
2 changed files with 5 additions and 2 deletions

View File

@@ -137,7 +137,7 @@ draw.slice9 = function slice9(image, rect = [0,0], slice = 0, info = slice9_info
})
}
draw.image = function image(image, rect, rotation, anchor, shear, info = {mode:"nearest"}, material = {color:{r:1,g:1,b:1,a:1}}) {
draw.image = function image(image, rect, scale = {x:1,y:1}, anchor, shear, info = {mode:"nearest"}, material = {color:{r:1,g:1,b:1,a:1}}) {
if (!rect) throw Error('Need rectangle to render image.')
if (!image) throw Error('Need an image to render.')
@@ -146,7 +146,7 @@ draw.image = function image(image, rect, rotation, anchor, shear, info = {mode:"
add_command("draw_image", {
image,
rect,
rotation,
scale,
anchor,
shear,
info,

View File

@@ -193,8 +193,11 @@ function translate_draw_commands(commands) {
var gpu = img.gpu
if (!gpu) break
if (!cmd.scale) cmd.scale = {x:1,y:1}
cmd.rect.width ??= img.width
cmd.rect.height ??= img.height
cmd.rect.width = cmd.rect.width * cmd.scale.x
cmd.rect.height = cmd.rect.height * cmd.scale.y
cmd.rect = worldToScreenRect(cmd.rect, camera)
renderer_commands.push({