一个 ImageButton 与渲染相关的行为类似于一个 ImageLabel ,加上一个 GuiButton 的额外行为。
概要
属性
当 ImageButton 被悬停时使用的纹理ID。
由 ImageButton 元素显示的图像内容。读写到 ImageContent 。
决定渲染图像将如何被着色。
用户界面元素显示的图像内容。支持资产 URI 和 EditableImage 对象。
要显示的图像子区的像素偏移。
确定要显示的图像子区域的像素大小。
决定渲染图像的透明度。
指示图像是否已从 Roblox 网站完全加载。
当按下 ImageButton 时将使用的纹理 ID。
选择按钮的图像重新样本模式。
决定图像在源图像与显示尺寸不同的 UI 元素中显示时会缩放的方式。
设置 9 切片图像的切割边界。
将 9 片边按指定比率缩放。
设置图像按钮的砖块比例。
属性
决定是否当鼠标悬停或单击时,按钮会自动更改颜色。
当 被悬停时会播放的实例。
如果 true 在图形用户界面元素可见时,鼠标不会锁定,除非右键按钮向下。
一个当 HapticEffect 按下时会播放的实例,当 GuiButton 按下时。
一个指示对象是否已选择的 boolean 属性。
根据一列预定义风格设置 GuiButton 的风格。
属性
决定这个 UI 元素是否沉没输入。
确定 GuiObject 的起始点,相对于其绝对尺寸。
决定是否基于子内容进行缩放。
决定 GuiObject 背景颜色。
决定 GuiObject 背景和边界的透明度。
决定 GuiObject 边框的颜色。
决定边界 GuiObject 是如何相对于其尺寸布置。
决定 GuiObject 边框的像素宽度。
决定是否描渲染父级 GUI 元素边界外的子元素 GuiObjects。
决定玩家的鼠标是否在 GuiObject 上被主动按下。
控制使用 GuiObject 与 UIGridStyleLayout 时的排序顺序。
设置当游戏手柄选择器向下移动时将选择的 GuiObject 。
设置当游戏手柄选择器移至左侧时将选择的 GuiObject 。
设置当游戏手柄选择器移至右侧时将选择的 GuiObject 。
设置当游戏手柄选择器向上移动时将选择的 GuiObject 。
确定 GuiObject 的像素和坐标位置。
决定旋转 GuiObject 的角度数。
确定是否可以由游戏手柄选择 GuiObject 。
覆盖用于游戏手柄的默认选择装饰。
游戏手柄 UI 选择选择的 GuiObjects 顺序。
决定 GuiObject 的像素和积分尺寸。
混合属性 BackgroundTransparency 和 TextTransparency 。
决定是否渲染 GuiObject 和其子孙。
决定 GuiObject 对其他人的相对渲染顺序。
属性
方法
继承自GuiObject的方法方法
- TweenPosition(endPosition : UDim2,easingDirection : Enum.EasingDirection,easingStyle : Enum.EasingStyle,time : number,override : boolean,callback : function):boolean
平滑地将图形用户界面移至新的 UDim2 。
- TweenSize(endSize : UDim2,easingDirection : Enum.EasingDirection,easingStyle : Enum.EasingStyle,time : number,override : boolean,callback : function):boolean
- TweenSizeAndPosition(endSize : UDim2,endPosition : UDim2,easingDirection : Enum.EasingDirection,easingStyle : Enum.EasingStyle,time : number,override : boolean,callback : function):boolean
平滑地将图形用户界面移至新的尺寸和位置。
活动
继承自GuiButton的活动活动
活动
当用户开始通过人机界面设备(鼠标按钮向下、触摸开始、键盘按钮向下等)进行交互时,发射。
当用户通过人机界面设备(鼠标按钮向下、触摸开始、键盘按钮向下等)更改他们的互动方式时,发射。
当用户停止通过人机界面设备(鼠标按钮向下、触摸开始、键盘按钮向下等)进行交互时,发射。
当用户将鼠标移至图形用户界面元素时发生火焰。
当用户将鼠标移出 GUI 元素时发生火焰。
在用户移动鼠标时,无论它在哪个 GUI 元素内,都会发生火焰。
当用户滚动鼠标轮返回时,火焰当鼠标悬停在图形用户界面元素上。
当用户滚动鼠标轮时向前移动时,触发当鼠标悬停在图形用户界面元素上时。
在使用游戏手柄选择器时将 GuiObject 聚焦时发射。
当游戏手柄选择器停止关注 GuiObject 时发射。
当玩家开始、继续和停止长按 UI 元素时,发生火焰。
- TouchPan(touchPositions : Array,totalTranslation : Vector2,velocity : Vector2,state : Enum.UserInputState):RBXScriptSignal
当玩家在 UI 元素上移动手指时发生火焰。
- TouchPinch(touchPositions : Array,scale : number,velocity : number,state : Enum.UserInputState):RBXScriptSignal
当玩家使用界面元素上的两个手指执行捏或拉动动作时,发生火焰。
- TouchRotate(touchPositions : Array,rotation : number,velocity : number,state : Enum.UserInputState):RBXScriptSignal
当玩家使用界面元素上的两个手指执行旋转动作时,发生火焰。
当玩家在 UI 元素上执行滑动动作时发生火焰。
当玩家在 UI 元素上执行了点击动作时发生火焰。
活动
- SelectionChanged(amISelected : boolean,previousSelection : GuiObject,newSelection : GuiObject):RBXScriptSignal
当游戏手柄选择移动到、离开或在连接的 或任何子手柄中更改时,发生火焰。
属性
HoverImage
HoverImageContent
Image
代码示例
local imageLabel = script.Parent
-- The images in this example are 64x64
imageLabel.Size = UDim2.new(0, 64, 0, 64)
local function unlock()
imageLabel.Image = "rbxassetid://284402785" -- Unlocked padlock (64x64)
imageLabel.ImageColor3 = Color3.new(0, 0.5, 0) -- Dark green
end
local function lock()
imageLabel.Image = "rbxassetid://284402752" -- Locked padlock (64x64)
imageLabel.ImageColor3 = Color3.new(0.5, 0, 0) -- Dark red
end
-- Connect events; our default state is locked
imageLabel.MouseEnter:Connect(unlock)
imageLabel.MouseLeave:Connect(lock)
lock()
ImageColor3
代码示例
local imageLabel = script.Parent
-- The images in this example are 64x64
imageLabel.Size = UDim2.new(0, 64, 0, 64)
local function unlock()
imageLabel.Image = "rbxassetid://284402785" -- Unlocked padlock (64x64)
imageLabel.ImageColor3 = Color3.new(0, 0.5, 0) -- Dark green
end
local function lock()
imageLabel.Image = "rbxassetid://284402752" -- Locked padlock (64x64)
imageLabel.ImageColor3 = Color3.new(0.5, 0, 0) -- Dark red
end
-- Connect events; our default state is locked
imageLabel.MouseEnter:Connect(unlock)
imageLabel.MouseLeave:Connect(lock)
lock()
ImageContent
ImageRectOffset
代码示例
-- Place this in an ImageLabel/ImageButton with size 256x256
local imageLabel = script.Parent
-- The following image is 1024x1024 with 12 frames (256x256)
-- The frames play an animation of a man throwing a punch
imageLabel.Image = "rbxassetid://848623155"
imageLabel.ImageRectSize = Vector2.new(256, 256)
-- The order of the frames to be displayed (left-to-right, then top-to-bottom)
local frames = {
Vector2.new(0, 0),
Vector2.new(1, 0),
Vector2.new(2, 0),
Vector2.new(3, 0),
Vector2.new(0, 1),
Vector2.new(1, 1),
Vector2.new(2, 1),
Vector2.new(3, 1),
Vector2.new(0, 2),
Vector2.new(1, 2),
Vector2.new(2, 2),
Vector2.new(3, 2),
}
-- Animate the frames one at a time in a loop
while true do
for _, frame in ipairs(frames) do
imageLabel.ImageRectOffset = frame * imageLabel.ImageRectSize
task.wait(0.1)
end
end
ImageRectSize
代码示例
-- Place this in an ImageLabel/ImageButton with size 256x256
local imageLabel = script.Parent
-- The following image is 1024x1024 with 12 frames (256x256)
-- The frames play an animation of a man throwing a punch
imageLabel.Image = "rbxassetid://848623155"
imageLabel.ImageRectSize = Vector2.new(256, 256)
-- The order of the frames to be displayed (left-to-right, then top-to-bottom)
local frames = {
Vector2.new(0, 0),
Vector2.new(1, 0),
Vector2.new(2, 0),
Vector2.new(3, 0),
Vector2.new(0, 1),
Vector2.new(1, 1),
Vector2.new(2, 1),
Vector2.new(3, 1),
Vector2.new(0, 2),
Vector2.new(1, 2),
Vector2.new(2, 2),
Vector2.new(3, 2),
}
-- Animate the frames one at a time in a loop
while true do
for _, frame in ipairs(frames) do
imageLabel.ImageRectOffset = frame * imageLabel.ImageRectSize
task.wait(0.1)
end
end
ImageTransparency
IsLoaded
代码示例
local imageLabel = script.Parent
local startTime = workspace.DistributedGameTime
-- Wait for the image to load
while not imageLabel.IsLoaded do
task.wait()
end
-- Measure and display how long it took to load
local deltaTime = workspace.DistributedGameTime - startTime
print(("Image loaded in %.3f seconds"):format(deltaTime))