| |
|
»
»
|
|
| |
Re: Move a Frame using a gui.
|
|
|
|
| 06 Feb 2015 07:26 AM |
Okay, you may assume Gui is defined. This is the main code:
--Setup functions
local function PositionFromCenter(Obj, UD) --Made for Move Obj.Position = UD - UDim2.new(Obj.Size.X.Scale/2, Obj.Size.X.Offset/2, Obj.Size.Y.Scale/2, Obj.Size.Y.Offset/2) end
local function CreateFrame(Name, F) --Made for Move local Fr = Instance.new("Frame", F) Fr.Name = Name Fr.Style = "ChatRed" Fr.Size = UDim2.new(0, 20, 0, 20) Fr.Draggable = true Fr.Active = true return Fr end
local function CreateGui() --Made for Move local S = Instance.new("ScreenGui", game.CoreGui) S.Name = "Gui Movement" local F = Instance.new("Frame", S) F.Name = "Gui Movement Frame" F.Size = UDim2.new(1, 0, 1, 0) F.Transparency = 1 local Up = CreateFrame("Up", F) local Down = CreateFrame("Down", F) local Left = CreateFrame("Left", F) local Right = CreateFrame("Right", F) return S,F,Up,Down,Left,Right end
--Code
local Gui = Selected[1] local S,F,Up,Down,Left,Right = CreateGui() PositionFromCenter(Up, Gui.Position + UDim2.new(Gui.Size.X.Scale / 2, Gui.Size.X.Offset / 2, Gui.Size.Y.Scale / 2, (Gui.Size.Y.Offset / 2))) PositionFromCenter(Down, Gui.Position + UDim2.new(Gui.Size.X.Scale / 2, Gui.Size.X.Offset / 2, Gui.Size.Y.Scale, (Gui.Size.Y.Offset))) PositionFromCenter(Left, Gui.Position + UDim2.new(0, 0, Gui.Size.Y.Scale/2, Gui.Size.Y.Offset/2)) PositionFromCenter(Right, Gui.Position + UDim2.new(Gui.Size.X.Scale, Gui.Size.X.Offset, Gui.Size.Y.Scale/2, Gui.Size.Y.Offset/2)) Up.Changed:connect(function() local xoff = Gui.Position.X.Offset local yoff = Gui.Position.Y.Offset Gui.Position = UDim2.new(Gui.Position.X.Scale + xoff/Gui.Parent.AbsoluteSize.X, 0, Gui.Position.Y.Scale + yoff/Gui.Parent.AbsoluteSize.Y, 0) PositionFromCenter(Up, Gui.Position + UDim2.new(Gui.Size.X.Scale / 2, Gui.Size.X.Offset / 2, Gui.Size.Y.Scale / 2, (Gui.Size.Y.Offset / 2))) end) Down.Changed:connect(function() local xoff = Gui.Position.X.Offset local yoff = Gui.Position.Y.Offset Gui.Position = UDim2.new(Gui.Position.X.Scale + xoff/Gui.Parent.AbsoluteSize.X, 0, Gui.Position.Y.Scale + yoff/Gui.Parent.AbsoluteSize.Y, 0) PositionFromCenter(Down, Gui.Position + UDim2.new(Gui.Size.X.Scale / 2, Gui.Size.X.Offset / 2, Gui.Size.Y.Scale, (Gui.Size.Y.Offset))) end) Left.Changed:connect(function() local xoff = Gui.Position.X.Offset local yoff = Gui.Position.Y.Offset Gui.Position = UDim2.new(Gui.Position.X.Scale + xoff/Gui.Parent.AbsoluteSize.X, 0, Gui.Position.Y.Scale + yoff/Gui.Parent.AbsoluteSize.Y, 0) PositionFromCenter(Left, Gui.Position + UDim2.new(0, 0, Gui.Size.Y.Scale/2, Gui.Size.Y.Offset/2)) end) Right.Changed:connect(function() local xoff = Gui.Position.X.Offset local yoff = Gui.Position.Y.Offset Gui.Position = UDim2.new(Gui.Position.X.Scale + xoff/Gui.Parent.AbsoluteSize.X, 0, Gui.Position.Y.Scale + yoff/Gui.Parent.AbsoluteSize.Y, 0) PositionFromCenter(Right, Gui.Position + UDim2.new(Gui.Size.X.Scale, Gui.Size.X.Offset, Gui.Size.Y.Scale/2, Gui.Size.Y.Offset/2)) end)
So the problem here, is that the guis do absolutely nothing! It's probably a simple mistake, that I'm overlooking, but can anybody help.
Extra Information:
No errors Code is mostly repeated. |
|
|
| Report Abuse |
|
|
AlgyLacey
|
  |
| Joined: 14 Jun 2013 |
| Total Posts: 3736 |
|
|
| 06 Feb 2015 07:28 AM |
I a similar problem, the best thing to do it use a tween, with a 0.1 move time.
-[ Where there is a will there is a way. I WILL be going THAT way ^ ]- |
|
|
| Report Abuse |
|
|
|
| 06 Feb 2015 07:28 AM |
| Could you explain how to change the code for that? |
|
|
| Report Abuse |
|
|
|
| 06 Feb 2015 07:33 AM |
| Wait a second! Does the forum support tabs now? :D |
|
|
| Report Abuse |
|
|
AlgyLacey
|
  |
| Joined: 14 Jun 2013 |
| Total Posts: 3736 |
|
|
| 06 Feb 2015 07:53 AM |
^ Yep, it does!
From this:
local xoff = Gui.Position.X.Offset local yoff = Gui.Position.Y.Offset Gui.Position = UDim2.new(Gui.Position.X.Scale + xoff/Gui.Parent.AbsoluteSize.X, 0, Gui.Position.Y.Scale + yoff/Gui.Parent.AbsoluteSize.Y, 0)
To this:
local xoff = Gui.Position.X.Offset local yoff = Gui.Position.Y.Offset Gui:TweenPosition(UDim2.new(Gui.Position.X.Scale + xoff/Gui.Parent.AbsoluteSize.X, 0, Gui.Position.Y.Scale + yoff/Gui.Parent.AbsoluteSize.Y, 0),Out,Quad,0.1)
(I used the last function in the example)
That should work. -[ Where there is a will there is a way. I WILL be going THAT way ^ ]- |
|
|
| Report Abuse |
|
|
|
| 06 Feb 2015 10:03 AM |
| @Al Thanks, I'll post back if I have problems. I'll test this later :D |
|
|
| Report Abuse |
|
|
AlgyLacey
|
  |
| Joined: 14 Jun 2013 |
| Total Posts: 3736 |
|
|
| 06 Feb 2015 10:09 AM |
No problemo!
-[ Where there is a will there is a way. I WILL be going THAT way ^ ]- |
|
|
| Report Abuse |
|
|
|
| 06 Feb 2015 07:30 PM |
@Alg
My current code:
Right.Changed:connect(function() local xoff = Gui.Position.X.Offset local yoff = Gui.Position.Y.Offset Gui:TweenPosition(UDim2.new(Gui.Position.X.Scale + xoff/Gui.Parent.AbsoluteSize.X, 0, Gui.Position.Y.Scale + yoff/Gui.Parent.AbsoluteSize.Y, 0),Out,Quad,0.1) PositionFromCenter(Right, Gui.Position + UDim2.new(Gui.Size.X.Scale, Gui.Size.X.Offset, Gui.Size.Y.Scale/2, Gui.Size.Y.Offset/2)) end)
Same result, no errors, but don't work. |
|
|
| Report Abuse |
|
|
| |
|
|
| 07 Feb 2015 04:40 AM |
Right.Changed gets fired when I use it, but nothing moves, probably because of PositionFromCenter, but that should fire after I set the gui's position. What's wrong with this here:
UDim2.new(Gui.Position.X.Scale + xoff/Gui.Parent.AbsoluteSize.X, 0, Gui.Position.Y.Scale + yoff/Gui.Parent.AbsoluteSize.Y, 0) |
|
|
| Report Abuse |
|
|
|
| 07 Feb 2015 04:50 AM |
Alright, I have new, definite information:
The line
local S,F,Up,Down,Left,Right = CreateGui()
calls
local function CreateGui() --Made for Move local S = Instance.new("ScreenGui", game.CoreGui) S.Name = "Gui Movement" local F = Instance.new("Frame", S) F.Name = "Gui Movement Frame" F.Size = UDim2.new(1, 0, 1, 0) F.Transparency = 1 local Up = CreateFrame("Up", F) local Down = CreateFrame("Down", F) local Left = CreateFrame("Left", F) local Right = CreateFrame("Right", F) return S,F,Up,Down,Left,Right end
Which properly creates a gui.
The line (and all the lines near the top)
PositionFromCenter(Right, Gui.Position + UDim2.new(Gui.Size.X.Scale, Gui.Size.X.Offset, Gui.Size.Y.Scale/2, Gui.Size.Y.Offset/2))
Calls
local function PositionFromCenter(Obj, UD) --Made for Move Obj.Position = UD - UDim2.new(Obj.Size.X.Scale/2, Obj.Size.X.Offset/2, Obj.Size.Y.Scale/2, Obj.Size.Y.Offset/2) end
Which properly positions the movement gui.
The line
Gui:TweenPosition(UDim2.new(Gui.Position.X.Scale + xoff/Gui.Parent.AbsoluteSize.X, 0, Gui.Position.Y.Scale + yoff/Gui.Parent.AbsoluteSize.Y, 0),"Out","Quad",0.1)
does not properly move the gui. How come? |
|
|
| Report Abuse |
|
|
|
| 07 Feb 2015 04:53 AM |
LOL
I FORGOT TO INCREMENT IT ON AN AXIS.
Sorry for wasting your time lol. |
|
|
| Report Abuse |
|
|
|
| |
|
|
| |
|
»
»
|
|
|
|
|