generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Offset and Scaled

Previous Thread :: Next Thread 
62GB is not online. 62GB
Joined: 03 Oct 2011
Total Posts: 4157
15 Apr 2016 11:30 AM
So I'm moving a frame to the mouse' screen location, which is only available in pixels. When the placement of the frame is done, how can I convert the position of the frame to scaled? It's size is scaled, but the position is in pixels due to the mouse' on-screen position being in pixels..


Any way around this?
Report Abuse
Cuyler is not online. Cuyler
Joined: 27 Feb 2006
Total Posts: 3784
15 Apr 2016 11:57 AM
This look right to you?

Example:
https://gyazo.com/0032dc0c0fbacf5777aec70ce8b9d845

Position:
https://gyazo.com/0f616890580eea889a0bcb23f53d498a


Report Abuse
62GB is not online. 62GB
Joined: 03 Oct 2011
Total Posts: 4157
15 Apr 2016 12:00 PM
Woah how did you do that? I've been stuck on this for days :C
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
15 Apr 2016 12:01 PM
scale = offset/absolutesize


Report Abuse
62GB is not online. 62GB
Joined: 03 Oct 2011
Total Posts: 4157
15 Apr 2016 12:02 PM
I tried that yesterday time :l
Report Abuse
62GB is not online. 62GB
Joined: 03 Oct 2011
Total Posts: 4157
15 Apr 2016 12:12 PM
I tried this in the while loop
tower.Position = UDim2.new(0,m.X/tower.AbsolutePosition.X,0,m.Y/tower.AbsolutePosition.Y)

Here's the result I got.....
https://gyazo.com/0c12e4a9dbfc82b1fb00fc6073dcd612


Also tried to divide by the AbsoluteSize. Didn't work like at all.
Report Abuse
Cuyler is not online. Cuyler
Joined: 27 Feb 2006
Total Posts: 3784
15 Apr 2016 12:13 PM
Here's the code:

local sg = script.Parent.Parent
local frame = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
local newFrame = Instance.new('Frame', frame)
newFrame.Size = UDim2.new(0.5, 0, 0.5, 0)
local clicked = false

local moveConn = mouse.Move:connect(function()
local x = mouse.X
local y = mouse.Y
local offset = frame.AbsoluteSize/2
newFrame.Position = UDim2.new(0, x - offset.X, 0, y - offset.Y)
end)

mouse.Button1Down:connect(function()
if not clicked then
moveConn:disconnect()
local absSize = frame.AbsoluteSize
local scalePos = UDim2.new(newFrame.Position.X.Offset / (absSize.X), 0, newFrame.Position.Y.Offset / absSize.Y, 0)
newFrame.Position = scalePos
clicked = true
end
end)


Report Abuse
62GB is not online. 62GB
Joined: 03 Oct 2011
Total Posts: 4157
15 Apr 2016 12:14 PM
Thanks!
Report Abuse
62GB is not online. 62GB
Joined: 03 Oct 2011
Total Posts: 4157
15 Apr 2016 12:17 PM
It moves it to the mouse location alright. When I place the tower the scaled X coordinate says 22...

2200%? Really?

D:

Where did I go wrong?
Report Abuse
Cuyler is not online. Cuyler
Joined: 27 Feb 2006
Total Posts: 3784
15 Apr 2016 12:19 PM
You have to make sure that absSize is the size of the frame which you are placing the towerFrame on. Post your full code, not just the SpawnTower function.


Report Abuse
62GB is not online. 62GB
Joined: 03 Oct 2011
Total Posts: 4157
15 Apr 2016 12:20 PM
Yep that was the problem alright. Thanks so much :D
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image