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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 15 Apr 2016 12:01 PM |
scale = offset/absolutesize
|
|
|
| Report Abuse |
|
|
62GB
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 4157 |
|
|
| 15 Apr 2016 12:02 PM |
| I tried that yesterday time :l |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 4157 |
|
| |
|
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
|
  |
| 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
|
  |
| 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 |
|
|