Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I pre-calculate the Scrolling Frame's CanvasPosition?

Asked by
Edenojack 171
8 years ago

Its a bit odd at the moment, The CanvasSize and the CanvasPosition are correlate, but I can't work out how? I have the CanvasSize set to something like .4 in the X scale, and when I drag the slider to its furthest, it tells me its CanvasPosition is about 2457 in the X.

What?

This is something I'd love to use to be able to create option sliders in-game, for things like MouseSpeed, Field of View, ect, but I can't figure this out :/

1 answer

Log in to vote
0
Answered by
Edenojack 171
8 years ago

Small update: I've gotten most of it down, but it only works 100% when my screen size is at 1361, 730 Heres the code:

function PercentCalc(CanvasSize,CanvasPosition,AbsoluteWindowSize)
    print(CanvasSize,CanvasPosition,AbsoluteWindowSize)
    local Max = math.ceil((AbsoluteWindowSize.X*10-AbsoluteWindowSize.X)/10)*10
    print(Max)
    local Perc = CanvasPosition.X/Max
    print(Perc,CanvasPosition)
end

local HUD = script.Parent.Options.ScrollingFrame

HUD.Changed:connect(function()
    PercentCalc(HUD.CanvasSize,HUD.CanvasPosition,HUD.AbsoluteWindowSize)
end)

Looking at the objectBrowser, it tells me that the Canvas Position's Max position is "absolute canvas size - AbsoluteWindowSize." I'm using scale rather than pixels, as this will help with different sized screens. Is there any way I can calculate this more accurately?

Ad

Answer this question