MCPcopy Create free account
hub / github.com/defold/defold / LuaParticlefxPlay

Function LuaParticlefxPlay

engine/gui/src/gui_script.cpp:4768–4808  ·  view source on GitHub ↗

Plays a particle fx * Plays the paricle fx for a gui node * * @name gui.play_particlefx * @param node [type:node] node to play particle fx for * @param [emitter_state_function] [type:function(self, node, emitter, state)] optional callback function that will be called when an emitter attached to this particlefx changes state. * * `self` * : [type:object] The

Source from the content-addressed store, hash-verified

4766 * ```
4767 */
4768 static int LuaParticlefxPlay(lua_State* L)
4769 {
4770 DM_LUA_STACK_CHECK(L, 0);
4771
4772 HNode hnode;
4773 Scene* scene = GuiScriptInstance_Check(L);
4774 LuaCheckNodeInternal(L, 1, &hnode);
4775
4776 GuiEmitterStateChangedData* script_data = 0;
4777 if (lua_gettop(L) > 1 && !lua_isnil(L, 2) )
4778 {
4779 dmScript::LuaCallbackInfo* callback = dmScript::CreateCallback(L, 2);
4780 if (callback == 0x0)
4781 {
4782 return DM_LUA_ERROR("Could not create callback for particlefx.");
4783 }
4784
4785 // if we reached here, the callback was registered
4786 script_data = (GuiEmitterStateChangedData*)malloc(sizeof(GuiEmitterStateChangedData)); // Released by the particle system (or actually the m_UserData)
4787
4788 script_data->m_LuaInfo.m_Callback = callback;
4789 script_data->m_LuaInfo.m_Scene = scene;
4790 script_data->m_LuaInfo.m_Node = hnode;
4791
4792 // Point the userdata to itself, for easy deletion later on
4793 script_data->m_ParticleCallback.m_UserData = script_data; // Released by the particle system
4794 script_data->m_ParticleCallback.m_StateChangedCallback = EmitterStateChangedCallback;
4795 }
4796
4797 dmGui::Result res;
4798 res = dmGui::PlayNodeParticlefx(scene, hnode, (dmParticle::EmitterStateChangedData*)script_data);
4799
4800 if (res == RESULT_WRONG_TYPE)
4801 {
4802 if (script_data)
4803 free(script_data);
4804 return DM_LUA_ERROR("Could not play particlefx on non-particlefx node.");
4805 }
4806
4807 return 0;
4808 }
4809
4810 /*# Stops a particle fx
4811 *

Callers

nothing calls this directly

Calls 7

GuiScriptInstance_CheckFunction · 0.85
LuaCheckNodeInternalFunction · 0.85
lua_gettopFunction · 0.85
CreateCallbackFunction · 0.85
mallocFunction · 0.85
freeFunction · 0.85
PlayNodeParticlefxFunction · 0.70

Tested by

no test coverage detected