Factory - kuimoani/defold GitHub Wiki
Factory components
ν©ν 리 μ»΄ν¬λνΈλ μ€λΈμ νΈ ν(pool of objects)μμ μ€νμ€μΈ κ²μμΌλ‘ κ²μμ€λΈμ νΈλ₯Ό λμ μΌλ‘ μ€ν°νλλ° μ¬μ©λ©λλ€. νν 리 μ»΄ν¬λνΈλ₯Ό κ²μ μ€λΈμ νΈμ μΆκ°νκ³ , Prototype μμ±μ νΉμ κ²μ μ€λΈμ νΈ νμΌμ μ§μ νλ©΄ μ€κ³λλ©΄ μ°μ΄λ΄λ―μ΄ μ κ²μ μ€λΈμ νΈλ₯Ό μ°μ΄λΌ μ μμ΅λλ€.


κ²μ μ€λΈμ νΈ μμ±μ νΈλ¦¬κ±° νκΈ° μν΄μλ factory.create()λ₯Ό νΈμΆνλ©΄ λ©λλ€.
factory.script
local p = go.get_position()
p.y = vmath.lerp(math.random(), min_y, max_y)
local component = "#star_factory"
factory.create(component, p)

factory.create() ν¨μλ 5κ°μ νλΌλ©ν°λ₯Ό κ°μ§λλ€.
url
μ κ²μμ€λΈμ νΈλ₯Ό μ€ν°νλ νν 리 μ»΄ν¬λνΈμ μμ΄λ
[position]
(μ ν) μ κ²μ μ€λΈμ νΈμ μλ ν¬μ§μ (world position). vector3 νμμ΄λ©°, ν¬μ§μ μ μ νμ§ μμΌλ©΄ κ²μμ€λΈμ νΈκ° νν 리 μ»΄ν¬λνΈμ μμΉμ μ€ν°λ¨
[rotation]
μ κ²μ μ€λΈμ νΈμ μλ λ‘ν μ΄μ (world rotation). quat(μΏΌν°λμ¨) νμμ
[properties]
κ²μ μ€λΈμ νΈμ μ΄κΈ°ν λλ μ€ν¬λ¦½νΈ μμ±κ°μ Lua ν μ΄λΈ. μμΈν λ΄μ©μ Script properties λ§€λ΄μΌ μ°Έκ³
[scale]
μ€ν°λ κ²μμ€λΈμ νΈμ μ€μΌμΌ(scale). 0λ³΄λ€ ν° μ«μλ‘ μ λ ₯νλ©΄ λͺ¨λ μΆ(axis)μ λμΌν μ¬μ΄μ¦λ‘ λ³κ²½λλ©°, vector3λ‘ μ λ ₯νλ©΄ μΆλ§λ€ λ€λ₯Έ ν¬κΈ°λ‘ μ€μΌμΌλ§ ν μ μμ
μμ :
factory.script
local p = go.get_position()
p.y = vmath.lerp(math.random(), min_y, max_y)
local component = "#star_factory"
-- νμ μμ΄ λλ°°μ μ€μΌμΌλ‘ μ€ν°ν¨. starμ scoreλ₯Ό 10μΌλ‘ μ€μ ν¨
factory.create(component, p, nil, { score = 10 }, 2.0) [1]
[1]. star κ²μ μ€λΈμ νΈμ "score" μμ±μ μ€μ ν¨
star.script
go.property("score", 1) [1]
local speed = -240
function update(self, dt)
local p = go.get_position()
p.x = p.x + speed * dt
if p.x < -32 then
go.delete()
end
go.set_position(p)
end
function on_message(self, message_id, message, sender)
if message_id == hash("collision_response") then
msg.post("main#gui", "add_score", {amount = self.score}) [2]
go.delete()
end
end
[1]. "score" μ€ν¬λ¦½νΈ μμ±μ΄ κΈ°λ³Έκ°κ³Ό ν¨κ» μ μλ¨
[2]. "score" μ€ν¬λ¦½νΈ μμ±μ "self"μ μ μ₯λ κ°μ²λΌ μ°Έμ‘°ν¨

νμ¬ Defoldλ μΆ©λ λͺ¨μ(collision shape)μ λΉκ·κ²© μ€μΌμΌλ§(non uniform scaling)μ μ§μνμ§ μμ΅λλ€. vmath.vector3(1.0, 2.0, 1.0) μ κ°μ λΉκ·κ²© μ€μΌμΌλ§ κ°μ λκΈ°λ©΄ μ€νλΌμ΄νΈλ μ λλ‘ λ³νλμ§λ§ μΆ©λ λͺ¨μμ μ λλ‘ λ³νλμ§ μμ΅λλ€.
Instance limits
Project Settingsμ μλ max_instances μμ±μ κ²μ μλ(κ²μ μμμ λ‘λλ main.collectionμ λΉλ‘―ν΄ collection proxyλ₯Ό ν΅ν΄ λ‘λλ λͺ¨λ μλ)μ μ‘΄μ¬ν μ μλ κ²μ μ€λΈμ νΈ μΈμ€ν΄μ€μ μ΄ μλμ μ νν©λλ€. κ²μ μλμ μ‘΄μ¬νλ λͺ¨λ κ²μ μ€λΈμ νΈλ μλν°μμ μ§μ λ°°μΉνλμ§ μ€ν¬λ¦½νΈλ‘ μ€ν°νλμ§μ μκ΄μμ΄ μ νλ μλ λ§νΌ μΉ΄μ΄νΈ λ©λλ€.

κ·Έλ¬λ―λ‘ λ§μ½ max_instancesλ₯Ό 1024λ‘ μ€μ νκ³ λ©μΈ 컬λ μ μ 24κ°μ κ²μμ€λΈμ νΈλ₯Ό μλμΌλ‘ λ°°μΉνλ€λ©΄, 1000κ°μ κ²μμ€λΈμ νΈλ₯Ό μΆκ°λ‘ μ€ν°ν μ μκ² λ©λλ€. κ·Έλ¦¬κ³ κ²μμ€λΈμ νΈλ₯Ό μμ νλ©΄, μμ ν λ§νΌμ μΈμ€ν΄μ€λ₯Ό μΆκ° μμ±ν μ μμ΅λλ€.
Pooling of game objects
μ€ν°ν κ²μ μ€λΈμ νΈλ₯Ό ν(pool)μ μ μ₯νλ€κ° μ¬μ¬μ©νλ κ²μ μ’μ λ°©λ²μΈ λ― νμ§λ§ μ±λ₯μμ μ΄μ λ‘ μ΄λ₯Ό μμ νλκ²μ΄ μ’μ΅λλ€. κ²μμ€λΈμ νΈλ₯Ό μμ νκ³ μλ‘ μ€ν°νλ κ²μ΄ νλ§μ νλ κ²λ³΄λ€ λ λΉ λ¦ λλ€(λλ‘λ λ κΉλν¨).