Hi. I've been trying to create a render target that I will be able to scroll the text and images that are inside of if (like a website).
The problem is the image that I want the date to be on is in right position, but the text itself is in top left corner of the screen. (https://imgur.com/a/zJvhnRM)
local sx, sy = guiGetScreenSize()
local zoom = (sx < 2048) and math.min(2.2, 2048/sx) or 1
font = exports.hv_fonts
local changes = {
{date = '06/07/2024', text = 'Change 1'},
{date = '06/07/2024', text = 'Change 1'},
{date = '06/07/2024', text = 'Change 1'},
{date = '06/07/2024', text = 'Change 1'},
}
local renderTargetWidth = 450 / zoom
local renderTargetHeight = 250 / zoom
local scrollOffset = 0
local scrollSpeed = 10
local maxScrollOffset = sy/2 - (#changes * 40) - renderTargetHeight/zoom
function handleMouseWheel(button)
if button == "mouse_wheel_up" then
scrollOffset = math.min(scrollOffset + scrollSpeed, 0)
elseif button == "mouse_wheel_down" then
scrollOffset = math.max(scrollOffset - scrollSpeed, -maxScrollOffset)
end
end
addEventHandler('onClientKey', root, handleMouseWheel)
local changesTarget = dxCreateRenderTarget(renderTargetWidth, renderTargetHeight)
function drawRender()
dxSetRenderTarget(changesTarget, true)
dxSetBlendMode("modulate_add")
for i, change in ipairs(changes) do
local offset = (i - 1) * 40 + scrollOffset
dxDrawImage(20 / zoom, offset, 101 / zoom, 20 / zoom, 'data.png', 0, 0, 0, tocolor(255, 255, 255, 255), false)
dxDrawText(change.date, 130 / zoom, offset, renderTargetWidth, offset + 20 / zoom, tocolor(255, 255, 255, 255), 1 / zoom, font:getFont('Inter-Regular', 12 / zoom), "left", "center", false, false, true, false, false)
dxDrawText(change.text, 130 / zoom, offset + 20 / zoom, renderTargetWidth, offset + 40 / zoom, tocolor(255, 255, 255, 255), 1 / zoom, font:getFont('Inter-Regular', 12 / zoom), "left", "center", false, false, true, false, false)
end
dxSetBlendMode("blend")
dxSetRenderTarget()
dxDrawImage(sx/2 - renderTargetWidth/2, sy/2 - renderTargetHeight/2, renderTargetWidth, renderTargetHeight, changesTarget)
end
addEventHandler('onClientRender', root, drawRender)
Can anyone suggest what is wrong in this code? Thanks in advance