Decal
*Konten ini diterjemahkan menggunakan AI (Beta) dan mungkin mengandung kesalahan. Untuk melihat halaman ini dalam bahasa Inggris, klik di sini.
Objek Decal adalah objek yang menerapkan gambar ke wajah BasePart .
Bagaimana Decal bekerja?
Sebuah Decal akan menerapkan gambar ke BasePart yang menjadi orangtuanya.Permukaan gambar ini diterapkan tergantung pada properti FaceInstance.Face.Ukuran stiker tergantung pada ukuran wajah, artinya ukuran dan rasio aspek stiker dapat diubah dengan mengubah ukuran dan aspek orangtuanya BasePart.Size.
Gambar yang diterapkan oleh Decal ditentukan oleh propertinya Decal.Texture.Gambar dapat diunggah ke Roblox asalkan mereka mematuhi panduan komunitas.Untuk informasi tentang cara mengunggah gambar, lihat Tekstur dan Decal.
Alternatif untuk Decal
Meskipun Decal memiliki berbagai aplikasi, dalam beberapa kasus pengembang mungkin ingin memilih salah satu kelas berikut alih-alih.
- Untuk tekstur ubin yang diulang, objek Texture harus digunakan
- Untuk menerapkan elemen GUI, objek SurfaceGui harus digunakan
- Jika efek pencahayaan pada gambar perlu diubah, objek SurfaceGui harus digunakan
Contoh Kode
Kode berikut akan membuat Part di tanah dengan Decal diterapkan ke wajah teratasnya.Ketika sesuatu mengenai bagian, seperti ketika pemain berjalan di atasnya, tekstur yang diterapkan ke decal akan berubah dan suara akan diputar.
-- buat bagian
local part = Instance.new("Part")
part.Size = Vector3.new(5, 1, 5)
part.Position = Vector3.new(0, 0.5, 0)
part.Anchored = true
part.TopSurface = Enum.SurfaceType.Smooth
part.BrickColor = BrickColor.new("Toothpaste")
-- buat decal
local decal = Instance.new("Decal")
decal.Face = Enum.NormalId.Top
decal.Parent = part
-- membuat suara
local sound = Instance.new("Sound")
sound.SoundId = "rbxasset://sounds/uuhhh.mp3" -- oof
sound.Parent = part
-- definisikan wajah
local happyFace = "http://www.roblox.com/asset/?id=26424652"
local sadFace = "http://www.roblox.com/asset/?id=147144198"
decal.Texture = happyFace
-- peristiwa disentuh
local cooldown = false
part.Touched:Connect(function(hit)
if not cooldown then
if hit and hit.Parent then
cooldown = true
sound:Play()
decal.Texture = sadFace
task.wait(1)
decal.Texture = happyFace
task.wait(0.2)
cooldown = false
end
end
end)
-- tambahkan ke ruang kerja
part.Parent = workspace
Rangkuman
Properti
Bertindak sebagai pengganda untuk properti stikerDecal.Transparency . Efek hanya terlihat oleh pemain lokal.
ContentId dari gambar yang akan diterapkan oleh Decal .
Menentukan transparansi dari Decal dengan 0 menjadi benar-benar buram dan 1 benar-benar transparan.
Menentukan urutan penyajian ketika beberapa Decal diberi wajah yang sama.
Properti
Tetapkan wajah apa dari batu bata objek muncul.
Properti
Color3
Contoh Kode
local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Size = Vector3.new(10, 10, 1)
part.Position = Vector3.new(0, 5, 0)
part.Anchored = true
part.Transparency = 1
local decal = Instance.new("Decal")
decal.Face = Enum.NormalId.Front
decal.Texture = "http://www.roblox.com/asset/?id=1145367640" -- white circle
decal.Parent = part
part.Parent = workspace
local redTween = TweenService:Create(
decal,
TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out),
{ Color3 = Color3.new(1, 0, 0) }
)
local greenTween = TweenService:Create(
decal,
TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out),
{ Color3 = Color3.new(0, 1, 0) }
)
local blueTween = TweenService:Create(
decal,
TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out),
{ Color3 = Color3.new(0, 0, 1) }
)
while true do
redTween:Play()
redTween.Completed:Wait()
greenTween:Play()
greenTween.Completed:Wait()
blueTween:Play()
blueTween.Completed:Wait()
end
LocalTransparencyModifier
Texture
Contoh Kode
-- buat bagian
local part = Instance.new("Part")
part.Size = Vector3.new(5, 1, 5)
part.Position = Vector3.new(0, 0.5, 0)
part.Anchored = true
part.TopSurface = Enum.SurfaceType.Smooth
part.BrickColor = BrickColor.new("Toothpaste")
-- buat decal
local decal = Instance.new("Decal")
decal.Face = Enum.NormalId.Top
decal.Parent = part
-- membuat suara
local sound = Instance.new("Sound")
sound.SoundId = "rbxasset://sounds/uuhhh.mp3" -- oof
sound.Parent = part
-- definisikan wajah
local happyFace = "http://www.roblox.com/asset/?id=26424652"
local sadFace = "http://www.roblox.com/asset/?id=147144198"
decal.Texture = happyFace
-- peristiwa disentuh
local cooldown = false
part.Touched:Connect(function(hit)
if not cooldown then
if hit and hit.Parent then
cooldown = true
sound:Play()
decal.Texture = sadFace
task.wait(1)
decal.Texture = happyFace
task.wait(0.2)
cooldown = false
end
end
end)
-- tambahkan ke ruang kerja
part.Parent = workspace
TextureContent
Transparency
Contoh Kode
local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Size = Vector3.new(10, 10, 1)
part.Position = Vector3.new(0, 5, 0)
part.Anchored = true
part.Transparency = 1
local decal = Instance.new("Decal")
decal.Face = Enum.NormalId.Front
decal.Texture = "http://www.roblox.com/asset/?id=699259085" -- roblox logo
decal.Parent = part
part.Parent = workspace
local tween = TweenService:Create(
decal,
TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, -1, true),
{ Transparency = 1 }
)
tween:Play()