Mouse

Artık kullanılmayanları göster

*Bu içerik, yapay zekâ (beta) kullanılarak çevrildi ve hatalar içerebilir. Sayfayı İngilizce görüntülemek için buraya tıkla.

Oluşturulamaz

Fare , daha geniş bir kapsama sahip olan UserInputService ve ContextActionService tarafından geçildi, daha fazla özellik içeriyor ve çapraz platform modellerini daha iyi destekliyor.Yaygın kullanımı nedeniyle desteklenmeye devam ediyor, ancak bu alternatifleri kullanmayı düşünmelisiniz.

Fare nesnesi çeşitli API'ler barındırır, öncelikle düğmeler ve ışın atışı için.Bir Player:GetMouse() üzerinden erişilebilir Players.LocalPlayer bir LocalScript içinde çağrılan .Ayrıca Tool.Equipped etkinliği tarafından geçer.


-- Bir YerelScript'ten:
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
-- Fare simgesini ayarlama
mouse.Icon = "rbxasset://SystemCursors/Wait"

Not:

  • Bu nesne, işaret hareketini kontrol etmiyor/sınırlandırmıyor. Bunun için, UserInputService.MouseBehavior ve UserInputService.MouseDeltaSensitivity görün.

  • Eğer iki işlev aynı giriş olayına bağlıysa, örneğin , her iki işlev de olay ateşlendiğinde çalışacaktır.Etkinlikler bu davranışı desteklemiyor olduğundan, batış/geçiş girişi konsepti yoktur.Ancak, ContextActionService bu davranışı BindAction aracılığıyla sahiptir.

  • Bir fare tüm platformlarda mevcut olmayabilir, ancak Fare hala mobil (dokunma) ve konsol (oyun kolu) üzerinde çalışır, ki bunlar genellikle fare veya işaretçi donanımına sahip değildir.Açık çapraz platform davranışları için UserInputService ve ContextActionService kullanın.

    Deneyiminizde girişleri özelleştirme hakkında daha fazla bilgi için Giriş ve Kamera bakın.

Özet

Özellikler

  • Salt Okunur
    Çoğaltılmamış
    Paralel oku

    fare3B uzaydaki konumunun CFrame 'si.

  • Icon:ContentId
    Paralel oku

    Mouse simgesi olarak kullanılan görüntünün içeriği ID'si.

  • Salt Okunur
    Çoğaltılmamış
    Paralel oku

    A Datatype.CFrame``Class.Workspace.CurrentCamera konumlandırılmış ve fareye yönelik 3B konumuna yönelik.

  • Salt Okunur
    Çoğaltılmamış
    Paralel oku

    3B uzaydaki nesne mouse işaret ediyor.

  • Bir nesneyi (ve onun soyundakileri) Mouse.Hit ve Mouse.Target saptarken göz ardı edilmesini sağlar.

  • Salt Okunur
    Çoğaltılmamış
    Paralel oku

    Farenin işaret ettiği Enum.NormalId yüzeyin BasePart üzerinde olduğunu gösterir.

  • Salt Okunur
    Çoğaltılmamış
    Paralel oku

    Fare dünya konumuna yönelik bir Ray yönlendirilmiş, Workspace.CurrentCamera dünya konumundan kaynaklanan.

  • Salt Okunur
    Çoğaltılmamış
    Paralel oku

    Oyun penceresinin genişliğini piksel olarak tanımlar.

  • Salt Okunur
    Çoğaltılmamış
    Paralel oku

    Oyun penceresinin yüksekliğini piksel olarak tanımlar.

  • Salt Okunur
    Çoğaltılmamış
    Paralel oku

    Farenin ekranda konumunun X (dikey) bileşenini tanımlar.

  • Salt Okunur
    Çoğaltılmamış
    Paralel oku

    Farenin ekran konumunun Y (dikey) bileşenini tanımlar.

Etkinlikler

Özellikler

Salt Okunur
Çoğaltılmamış
Paralel oku

Bu özellik, fare konumunun 3B uzaydaki CFrame olduğunu gösterir. Mouse.TargetFilter ve onun soyundakilerin göz ardı edileceğini unutmayın.

Geliştiriciler böyle alabilir Hit pozisyonu:


local position = mouse.Hit.Position

Vuruş genellikle Tools üçüncü şahıs tarafından bir silahı fareye ateş etmek için kullanılır.

Fareyi BasePart işaret eden geliştiricilerin kullanması gereken Mouse.Target .

Mouse.Hit nasıl hesaplanır?

Hit CFrame'in konumu, farenin içindeki (genişletilmiş bir versiyon) ve 3B uzaydaki bir nesne arasındaki kesişme noktası olarak hesaplanır (örneğin bir parça).

Hit CFrame'in yönü, Mouse.UnitRay 'nin yönüyle eşleşir.


local unitRayDirection = mouse.UnitRay.Direction
local mouseHitDirection = mouse.Hit.lookVector
-- unitRayDirection ≈ mouseHitDirection
-- the vectors are approximately equal

Not, 'nin yuvarlanması, Hit'in yönünü hesaplarken kullanılmaz.

Farenin iç ışını 1,000 damga boyunca genişler.Fare 3B uzayda bir nesneye işaret etmiyorsa (örneğin gökyüzüne işaret ederken), bu özellik Workspace.CurrentCamera 'den 1,000 damga uzakta olacaktır.

Kod Örnekleri

The code in this sample, when placed inside a LocalScript within StarterPlayerScripts will draw a red laser beam between the character's head and Mouse.Hit at all times.

Note, this beam will pass directly through obstructions in third person as the Mouse's raycasting is done from the Workspace.CurrentCamera not the head.

Mouse.Hit Laser Beam

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local beam = Instance.new("Beam")
beam.Segments = 1
beam.Width0 = 0.2
beam.Width1 = 0.2
beam.Color = ColorSequence.new(Color3.new(1, 0, 0))
beam.FaceCamera = true
local attachment0 = Instance.new("Attachment")
local attachment1 = Instance.new("Attachment")
beam.Attachment0 = attachment0
beam.Attachment1 = attachment1
beam.Parent = workspace.Terrain
attachment0.Parent = workspace.Terrain
attachment1.Parent = workspace.Terrain
local function onRenderStep()
local character = player.Character
if not character then
beam.Enabled = false
return
end
local head = character:FindFirstChild("Head")
if not head then
beam.Enabled = false
return
end
beam.Enabled = true
local origin = head.Position
local finish = mouse.Hit.Position
attachment0.Position = origin
attachment1.Position = finish
end
RunService.RenderStepped:Connect(onRenderStep)

The code below visualizes the difference between Mouse.Hit and Mouse.Origin. In order to do this, the code uses the Vector3 positions of the hit and origin CFrame values using .p.

The difference is that the origin is "where the mouse came from" (its origin) and the hit is the position where the mouse hits (is when the player presses their mouse).

This example also visualizes that the mouse origin is very similar to the position of the CurrentCamera by printing the magnitude (distance) between the two positions.

Mouse Origin vs Mouse Hit vs CurrentCamera Position

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local player = Players.LocalPlayer
local camera = Workspace.CurrentCamera
local mouse = player:GetMouse()
local camPos = camera.CFrame.Position
local function onButton1Down()
print("Mouse.Hit:", mouse.Hit.Position)
print("camPos:", camPos)
print("Mouse.Origin:", mouse.Origin.Position)
print("Magnitude:", (mouse.Origin.Position - camPos).Magnitude)
end
mouse.Button1Down:Connect(onButton1Down)

Icon

ContentId
Paralel oku

Simge , işaret olarak kullanılan görüntüyü belirleyen bir özelliktir.Boşsa, varsayılan bir ok kullanılır.Kurma işaretleyici bir GuiButton üzerinde gezinirken, bu özellik geçici olarak göz ardı edilir.

Okutucuyu tamamen gizlemek için, şeffaf bir görüntü kullanmayın ve bunun yerine UserInputService.MouseIconEnabled false'a ayarlayın.

Deneyimlerde kullanıcı farenin simgesini almak/ayarlamak için UserInputService.MouseIcon kullanmalısınız.Mouse.Icon yeni API'ler için düğme işaretleyici ayarlanması için yayınlandıktan sonra eski olacak.

Bir İşaret Tasarlama

Aşağıdaki kurallar, kendi fare imlecini oluştururken yararlı olabilir:

  • Kullanılan görüntünün boyutları, okunun boyutunu belirler.
  • Resmin merkezi görüntünün mouse girişlerinin verildiği yerdir.
  • Varsayılan fare görüntüsü 64x64 pikseldir ve fare 17x24 piksel alanı kaplar.
Sistem Kursörleri

Bir sistemin varsayılan kursörlerine benzer şekilde PluginMouse 'den alınan bir Plugin:GetMouse() kullanırken, eller, oklar, I ışınları vb. gibi aşağıdaki simgeleri kullanabilirsinizBunları, belirli GUI bileşenleriyle etkileşimde bulunurken tutarlı bir Studio deneyimi sağlamak için GUI etkinlikleriyle MouseEnter , MouseLeave ve MouseButton1Down kullanarak kullanabilirsiniz.Bunların sadece Studio eklentileri için çalıştığını unutmayın; diğer Mouse nesneler için çalışmayacaklar.


<th>Varlık</th>
<th>Önerilen Kullanım</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-Pointer.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/Arrow</code></td><td>Varsayılan tıklama ve seçim.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-PointingHand.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/PointingHand</code></td><td>Aktif bir bağlantı/düğme üzerinde gezinmek.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-OpenHand.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/OpenHand</code></td><td>Taşınabilir bir öğeye dokunarak gezinme.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-GrabbingHand.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/ClosedHand</code></td><td>Bir öğe sürükleme.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-IBeam.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/IBeam</code></td><td>Bir metin alanında gezinme.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-ResizeNS.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/SizeNS</code></td><td>Dikey yeniden boyutlandırma kolu üzerinde gezinme.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-ResizeEW.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/SizeEW</code></td><td>Dikey bir yeniden boyutlandırma kolu üzerinde gezinmek.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-ResizeNESW.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/SizeNESW</code></td><td>Bir köşe boyutlandırma kolu üzerinde gezinme.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-ResizeNWSE.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/SizeNWSE</code></td><td>Bir köşe boyutlandırma kolu üzerinde gezinme.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-ResizeAll.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/SizeAll</code></td><td>Çok yönlü yeniden boyutlandırma kolu üzerinde gezinme.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-ResizeSplitV.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/SplitNS</code></td><td>Dikey bir "bölme" kolu üzerinde gezinmek.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-ResizeSplitH.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/SplitEW</code></td><td>Dikey bir "bölme" kolu üzerinde gezinmek.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-Forbidden.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/Forbidden</code></td><td>Kilitli/yasaklanmış bir öğeye dokunmak.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-Wait.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/Wait</code></td><td>Bir eylemin devam ettiğini belirtmek.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-Busy.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/Busy</code></td><td>Sistemin meşgul olduğunu gösteriyor.</td>
</tr>
<tr>
<td>
<img src="../../../assets/misc/Mouse-Icon-Crosshair.png" width="30">
</img>
</td>
<td><code>rbxasset://SystemCursors/Cross</code></td><td>Bir düğme seçim alanının üzerinde gezinmek.</td>
</tr>
</tbody>
Bak*
\* Bu görünümler yaklaşımlardır - gerçek görünüm işletim sisteminize bağlıdır.

Kod Örnekleri

This example changes the Players.LocalPlayer mouse icon to look like a dragon image.

Dragon Mouse Icon

local Players = game:GetService("Players")
local mouse = Players.LocalPlayer:GetMouse()
mouse.Icon = "http://www.roblox.com/asset?id=163023520"

Origin

Salt Okunur
Çoğaltılmamış
Paralel oku

Köken Mouse özelliği, farelerin nereden geldiğini gösteren bir CFrame özelliğidir.Workspace.CurrentCamera 'de konumlandırılır ve fareyi 3B konumuna yönlendirir.

Mouse.UnitRay Origin ile aynı pozisyonda başlar ve aynı yönde bir çivi boyunca genişler.


local unitRay = mouse.UnitRay
local origin = mouse.Origin
-- unitRay.Direction = kaynağın p
-- unitRay.Direction ≈ origin.lookVector

3B uzaydaki Mouse konumu için, bakınız Mouse.Hit .

Kod Örnekleri

The code below visualizes the difference between Mouse.Hit and Mouse.Origin. In order to do this, the code uses the Vector3 positions of the hit and origin CFrame values using .p.

The difference is that the origin is "where the mouse came from" (its origin) and the hit is the position where the mouse hits (is when the player presses their mouse).

This example also visualizes that the mouse origin is very similar to the position of the CurrentCamera by printing the magnitude (distance) between the two positions.

Mouse Origin vs Mouse Hit vs CurrentCamera Position

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local player = Players.LocalPlayer
local camera = Workspace.CurrentCamera
local mouse = player:GetMouse()
local camPos = camera.CFrame.Position
local function onButton1Down()
print("Mouse.Hit:", mouse.Hit.Position)
print("camPos:", camPos)
print("Mouse.Origin:", mouse.Origin.Position)
print("Magnitude:", (mouse.Origin.Position - camPos).Magnitude)
end
mouse.Button1Down:Connect(onButton1Down)

Target

Salt Okunur
Çoğaltılmamış
Paralel oku

3B uzaydaki nesne mouse işaret ediyor.

Not:

  • Eğer Mouse.TargetFilter ayarlandıysa, hedef filtre ve onun soyundakiler göz ardı edilecektir.
  • Fare bir BasePart 'ye işaret etmediğinde, örneğin gökyüzüne işaret ederken, Hedef olacak nil .
  • 3B uzayda fare konumunu arayan geliştiriciler Mouse.Hit kullanmalıdır.

Kod Örnekleri

The following code sample, when placed in StarterPlayerScripts will create a tool in the player's backpack that, once equipped, will change the BasePart.BrickColor of every BasePart the player clicks on.

Color Randomizer Tool

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local backpack = localPlayer:WaitForChild("Backpack")
local tool = Instance.new("Tool")
tool.RequiresHandle = false
tool.CanBeDropped = false
tool.Parent = backpack
tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
if mouse.Target and mouse.Target.Parent then
mouse.Target.BrickColor = BrickColor.random()
end
end)
end)

TargetFilter

Paralel oku

Bu özellik, fare tarafından göz ardı edilecek bir nesneyi hesaplarken Mouse.Hit ve Mouse.Target 'yi hesaplarken göz ardı edilecek bir nesneyi belirler.Nesnenin soyundakiler de göz ardı edilir, bu nedenle bu özellikte belirtilen nesnenin bir soyundan olduğu sürece birden fazla nesneyi göz ardı edebilirsiniz.Bu özellik, Mouse.Hit veya Mouse.Target etkilemeyen özel efekt veya dekorasyonlar içeren filtreleme modellerinde yararlıdır.

Bu özellik herhangi bir Instance veya nil için ayarlanabilir, örneğin:


local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
mouse.TargetFilter = Workspace.Model

Not that the Character of the Players.LocalPlayer is automatically ignored by the mouse.

TargetSurface

Salt Okunur
Çoğaltılmamış
Paralel oku

Bu özellik, fare'nin işaret ettiği Enum.NormalId yüzeydeki BasePart özelliğini gösterir.Bu özellik, fareyi dünya konumundan ( Mouse.Hit ) ve fareyin işaret ettiği parçadan ( Mouse.Target ) gelir.

Bu özellik, fare bir parçaya işaret etmediğinde anlamsızdır, örneğin fare gökyüzüne işaret ediyorsa.Şu anda, bu özellik bu koşullar altında 'Sağ' olarak ayarlanmıştır.Bu özelliği kullanmadan önce, farenin hedefinin nil olmadığını kontrol edin.


local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
-- Fare işaret ettiği bir parça var olup olmadığını kontrol edin
if mouse.Target then
print("The mouse is pointing to the " .. mouse.TargetSurface.Name .. " side of " .. mouse.Target.Name)
else
print("The mouse is not pointing at anything.")
end

Kod Örnekleri

The code in this sample, when placed in a LocalScript inside StarterPlayerScripts will set the surface of any BasePart clicked on to a random surface.

Surface Randomizer

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local surfaceTypes = {
Enum.SurfaceType.Smooth,
Enum.SurfaceType.Glue,
Enum.SurfaceType.Weld,
Enum.SurfaceType.Studs,
Enum.SurfaceType.Inlet,
Enum.SurfaceType.Universal,
Enum.SurfaceType.Hinge,
Enum.SurfaceType.Motor,
}
local function onMouseClick()
-- make sure the mouse is pointing at a part
local target = mouse.Target
if not target then
return
end
local surfaceType = surfaceTypes[math.random(1, #surfaceTypes)]
local surface = mouse.TargetSurface
local propertyName = surface.Name .. "Surface"
mouse.Target[propertyName] = surfaceType
end
mouse.Button1Down:Connect(onMouseClick)

UnitRay

Salt Okunur
Çoğaltılmamış
Paralel oku

UnitRay özelliği, 3B uzaydaki fare konumuna yönelik bir Ray özelliktir (tarif edilmiştir ile Mouse.Hit ).Kökeni CFrame 'den gelir Workspace.CurrentCamera .Tüm birim ışınları gibi, 1 uzaklığı vardır.


local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
print(mouse.UnitRay.Direction.Magnitude) -- Always 1

ViewSizeX

Salt Okunur
Çoğaltılmamış
Paralel oku

ViewSizeX özelliği, oyun penceresinin genişliğinin piksel cinsinden yatay bileşenini tanımlar.

Kod Örnekleri

This code sample shows how you can create a Vector2 representing the Mouse object's position on screen (X() and Y()) and the size of the screen itself (ViewSizeX() and ViewSizeY()). Using these, you can normalize the position of the mouse on-screen such that the top-left just under the topbar maps to (0, 0) and the bottom-right maps to (1, 1). This normalized position is calculated and printed as the mouse moves using the Move() event.

Normalized Mouse Position

local Players = game:GetService("Players")
-- Note: You should use ContextActionService or UserInputService instead of
-- the Mouse object for accomplishing this task.
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onMouseMove()
-- Construct Vector2 objects for the mouse's position and screen size
local position = Vector2.new(mouse.X, mouse.Y)
local size = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)
-- A normalized position will map the top left (just under the topbar)
-- to (0, 0) the bottom right to (1, 1), and the center to (0.5, 0.5).
-- This is calculated by dividing the position by the total size.
local normalizedPosition = position / size
print(normalizedPosition)
end
mouse.Move:Connect(onMouseMove)

ViewSizeY

Salt Okunur
Çoğaltılmamış
Paralel oku

ViewSizeY özelliği, oyun penceresinin boyutunun dikey bileşenini piksel olarak tanımlar. Bu uzunluk, üst çubuğun kullandığı alanı içerir.

Kod Örnekleri

This code sample shows how you can create a Vector2 representing the Mouse object's position on screen (X() and Y()) and the size of the screen itself (ViewSizeX() and ViewSizeY()). Using these, you can normalize the position of the mouse on-screen such that the top-left just under the topbar maps to (0, 0) and the bottom-right maps to (1, 1). This normalized position is calculated and printed as the mouse moves using the Move() event.

Normalized Mouse Position

local Players = game:GetService("Players")
-- Note: You should use ContextActionService or UserInputService instead of
-- the Mouse object for accomplishing this task.
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onMouseMove()
-- Construct Vector2 objects for the mouse's position and screen size
local position = Vector2.new(mouse.X, mouse.Y)
local size = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)
-- A normalized position will map the top left (just under the topbar)
-- to (0, 0) the bottom right to (1, 1), and the center to (0.5, 0.5).
-- This is calculated by dividing the position by the total size.
local normalizedPosition = position / size
print(normalizedPosition)
end
mouse.Move:Connect(onMouseMove)
Salt Okunur
Çoğaltılmamış
Paralel oku

Ekranda fare konumundaki değişiklikleri algılarken, bu değişiklikleri açıklayan veya veya kullanmanız önerilir, bu da bir 'in (bir >) konumunu açıklayan fareyi kullanarak bu ve ilgili özellikleri kullanmak yerine.

X özelliği, ekranda fare konumunun yatay bileşenini tanımlar.Pozisyon, üst çubuğun altında sol üst kenara göre piksel olarak ölçülür.Bu özellik, Mouse.Y ile birlikte kullanılarak fare konumunu temsil eden bir Vector2 üretmek için kullanılabilir:


local position = Vector2.new(mouse.X, mouse.Y)

Bu özellik Changed veya GetPropertyChangedSignal 'den dönen sinyalden ateş etmiyor. Bunun yerine Mouse.Move etkinliğini kullanın.

Kod Örnekleri

This code sample shows how you can create a Vector2 representing the Mouse object's position on screen (X() and Y()) and the size of the screen itself (ViewSizeX() and ViewSizeY()). Using these, you can normalize the position of the mouse on-screen such that the top-left just under the topbar maps to (0, 0) and the bottom-right maps to (1, 1). This normalized position is calculated and printed as the mouse moves using the Move() event.

Normalized Mouse Position

local Players = game:GetService("Players")
-- Note: You should use ContextActionService or UserInputService instead of
-- the Mouse object for accomplishing this task.
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onMouseMove()
-- Construct Vector2 objects for the mouse's position and screen size
local position = Vector2.new(mouse.X, mouse.Y)
local size = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)
-- A normalized position will map the top left (just under the topbar)
-- to (0, 0) the bottom right to (1, 1), and the center to (0.5, 0.5).
-- This is calculated by dividing the position by the total size.
local normalizedPosition = position / size
print(normalizedPosition)
end
mouse.Move:Connect(onMouseMove)
Salt Okunur
Çoğaltılmamış
Paralel oku

Ekranda fare konumundaki değişiklikleri algılarken, bu değişiklikleri açıklayan veya veya kullanmanız önerilir, bu da bir 'in (bir >) konumunu açıklayan fareyi kullanarak bu ve ilgili özellikleri kullanmak yerine.

Y özelliği, ekranda fare konumunun dikey bileşenini tanımlar.Pozisyon, üst çubuğun altında sol üst kenara göre piksel olarak ölçülür.Bu özellik, Mouse.X ile birlikte kullanılarak fare konumunu temsil eden bir Vector2 üretmek için kullanılabilir:


local position = Vector2.new(mouse.X, mouse.Y)

Bu özellik Changed veya GetPropertyChangedSignal 'den dönen sinyalden ateş etmiyor. Bunun yerine Mouse.Move etkinliğini kullanın.

Kod Örnekleri

This code sample shows how you can create a Vector2 representing the Mouse object's position on screen (X() and Y()) and the size of the screen itself (ViewSizeX() and ViewSizeY()). Using these, you can normalize the position of the mouse on-screen such that the top-left just under the topbar maps to (0, 0) and the bottom-right maps to (1, 1). This normalized position is calculated and printed as the mouse moves using the Move() event.

Normalized Mouse Position

local Players = game:GetService("Players")
-- Note: You should use ContextActionService or UserInputService instead of
-- the Mouse object for accomplishing this task.
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onMouseMove()
-- Construct Vector2 objects for the mouse's position and screen size
local position = Vector2.new(mouse.X, mouse.Y)
local size = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)
-- A normalized position will map the top left (just under the topbar)
-- to (0, 0) the bottom right to (1, 1), and the center to (0.5, 0.5).
-- This is calculated by dividing the position by the total size.
local normalizedPosition = position / size
print(normalizedPosition)
end
mouse.Move:Connect(onMouseMove)

Yöntemler

Etkinlikler

Button1Down

Bu olay, oyuncu sol fare düğmesine basıldığında ateşlenir.Buna erişilebileceğini unutmayın Tool ; örneğin, bir LocalScript içine yerleştirildiğinde, aşağıdaki kod herhangi bir sol fare düğmesine basıldığında Button1Down basılır.


local tool = script.Parent -- Bunun bir Araç nesnesi olduğundan emin ol
tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
print("Button1Down")
end)
end)

Dünya uzayındaki mouse konumunu ve herhangi bir ve özelliklerini kullanarak işaret ettiğini bulabilirsiniz.


Button1Up

Bu olay, oyuncu sol fare düğmesini serbest bıraktığında ateşlenir.Buna erişilebileceğini unutmayın Tool ; örneğin, bir LocalScript içine yerleştirildiğinde, aşağıdaki kod, sol fare düğmesi serbest bırakıldığında her zaman Button1Up basılır.


local tool = script.Parent -- Bunun bir Araç nesnesi olduğundan emin ol
tool.Equipped:Connect(function(mouse)
mouse.Button1Up:Connect(function()
print("Button1Up")
end)
end)

Dünya uzayındaki mouse konumunu ve herhangi bir ve özelliklerini kullanarak işaret ettiğini bulabilirsiniz.


Button2Down

Bu olay, oyuncu sağ fare düğmesine basıldığında ateşlenir.Bunun bir Tool 'den erişilebileceğini unutmayın; örneğin, bir LocalScript 'e yerleştirildiğinde, aşağıdaki kod herhangi bir sağ fare düğmesine basıldığında Button2Down basılır.


local tool = script.Parent -- Bunun bir Araç nesnesi olduğundan emin ol
tool.Equipped:Connect(function(mouse)
mouse.Button2Down:Connect(function()
print("Button2Down")
end)
end)

Dünya uzayındaki mouse konumunu ve herhangi bir ve özelliklerini kullanarak işaret ettiğini bulabilirsiniz.


Button2Up

Bu olay, oyuncu sağ fare düğmesini serbest bıraktığında ateşlenir.Bunun bir Tool 'den erişilebileceğini unutmayın; örneğin, bir LocalScript 'e yerleştirildiğinde, aşağıdaki kod herhangi bir sağ fare düğmesi serbest bırakıldığında Button2Up basılır.


local tool = script.Parent -- Bunun bir Araç nesnesi olduğundan emin ol
tool.Equipped:Connect(function(mouse)
mouse.Button2Up:Connect(function()
print("Button2Up")
end)
end)

Dünya uzayındaki mouse konumunu ve herhangi bir ve özelliklerini kullanarak işaret ettiğini bulabilirsiniz.


Idle

Fare başka bir fare etkinliğine geçmediği her kalp atışı sırasında ateş edilir.

Not, bu etkinlik mouse'un hala olduğu zamanı belirlemek için kullanılmamalıdır. Her kalp atışı ateşlediğinde, Mouse.Move etkinlikler arasında ateş edecektir.

Mouse nesnesini nasıl alacağınızla ilgili bilgi için, lütfen Mouse sayfasına bakın.

Geliştiriciler dünya uzayındaki mouse konumunu bulabilir ve eğer BasePart ve Mouse.Hit ve Mouse.Target özelliklerini kullanarak herhangi bir işaret ediyorsa.

Not, geliştiricilerin yeni çalışmada UserInputService nesnesi yerine Mouse kullanması önerilir.


Kod Örnekleri

This example demonstrates how mouse events are passed during each frame

Mouse.Idle

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local events = {
"Button1Down",
"Button1Up",
"Button2Down",
"Button2Up",
"Idle",
"Move",
"WheelBackward",
"WheelForward",
"KeyDown",
"KeyUp",
}
local currentEvent
local frame = 0
local function processInput()
frame = frame + 1
print("Frame", frame, "- mouse event was passed to", currentEvent)
end
for _, event in pairs(events) do
mouse[event]:Connect(function()
currentEvent = event
end)
end
RunService:BindToRenderStep("ProcessInput", Enum.RenderPriority.Input.Value, processInput)

Move

Fare hareket ettirildiğinde ateş edilir.

Not, bu olay, fare konumu güncellendiğinde ateşlenir, bu nedenle taşınırken tekrar tekrar ateşlenecektir.

Mouse nesnesini nasıl alacağınızla ilgili bilgi için, lütfen Mouse sayfasına bakın.

Geliştiriciler dünya uzayındaki mouse konumunu bulabilir ve eğer BasePart ve Mouse.Hit ve Mouse.Target özelliklerini kullanarak herhangi bir işaret ediyorsa.


mouse.Move:Connect(function()
local position = mouse.Hit.p
local target = mouse.Target
print(target, position)
end)

Not, geliştiricilerin yeni çalışmada UserInputService nesnesi yerine Mouse kullanması önerilir.


Kod Örnekleri

The example below allows the local player to move parts with their mouse.

When the player presses their left mouse button over a part, that part is the mouse's target and becomes the point. Until the player releases their left mouse button, that part will move to the mouse's world position when the player moves their mouse.

Note that the Mouse.TargetFilter property allows the code to ignore the part being moved when determining the mouse's world position.

The code should work as expected when placed in a LocalScript.

Move Parts with the Mouse

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local point
local down
local function selectPart()
if mouse.Target and not mouse.Target.Locked then
point = mouse.Target
mouse.TargetFilter = point
down = true
end
end
local function movePart()
if down and point then
local posX, posY, posZ = mouse.Hit.X, mouse.Hit.Y, mouse.Hit.Z
point.Position = Vector3.new(posX, posY, posZ)
end
end
local function deselectPart()
down = false
point = nil
mouse.TargetFilter = nil
end
mouse.Button1Down:Connect(selectPart)
mouse.Button1Up:Connect(deselectPart)
mouse.Move:Connect(movePart)

WheelBackward

Teker teker geri etkinliği, fare tekeri geriye kaydığında ateşlenir.Bu etkinin olası kullanımları, birinci şahıs nişancısında bir silahın menzilini değiştirmek veya oyuncunun kamerasını yakınlaştırmak gibi şeyleri içerir (FPS).

Bu, ileriye doğru kaydırma etkinliğinin yanında kullanılabilir, Mouse.WheelForward .

Mouse nesnesini nasıl alacağınızla ilgili bilgi için, lütfen Mouse sayfasına bakın.

Not, geliştiricilerin yeni çalışmada UserInputService nesnesi yerine Mouse kullanması önerilir.


Kod Örnekleri

The below example assumes that you have already got the player's mouse (and set it as a variable named 'mouse'), whether by use of a Tool, HopperBin or the Player:GetMouse() method. It will print "Wheel went backwards!" when the player scrolls backwards.

Mouse.WheelBackward

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onWheelBackward()
print("Wheel went backwards!")
end
mouse.WheelBackward:Connect(onWheelBackward)

WheelForward

Tekerlekİleri etkinliği, fare tekerleği ileriye kaydırıldığında ateşlenir.Bu etkinin olası kullanımları, birinci şahıs nişancısında bir silahın menzilini değiştirmek veya oyuncunun kamerasını yakınlaştırmak gibi şeyleri içerir (FPS).

Bu, geriye doğru kaydırma olayının yanında kullanılabilir, Mouse.WheelBackward .

Mouse nesnesini nasıl alacağınızla ilgili bilgi için, lütfen Mouse sayfasına bakın.

Not, geliştiricilerin yeni çalışmada UserInputService nesnesi yerine Mouse kullanması önerilir.


Kod Örnekleri

The below example assumes that you have already got the player's mouse (and set it as a variable named 'mouse'), whether by use of a Tool, HopperBin or the Player:GetMouse() method. It will print "Wheel went forward!" when the player scrolls forwards.

Mouse.WheelForward

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function onWheelBackward()
print("Wheel went forward!")
end
mouse.WheelForward:Connect(onWheelBackward)