Browse Source

Reverted ParticleSystem:setPosition’s functionality to 0.9.0’s beheaviour, added ParticleSystem:moveTo which has the new behaviour (new particles spawn in a line between the old position and where the emitter was moved to.)

Alex Szpakowski 11 years ago
parent
commit
a7ed581204

+ 6 - 0
src/modules/graphics/opengl/ParticleSystem.cpp

@@ -474,6 +474,7 @@ void ParticleSystem::getParticleLifetime(float *min, float *max) const
 void ParticleSystem::setPosition(float x, float y)
 void ParticleSystem::setPosition(float x, float y)
 {
 {
 	position = love::Vector(x, y);
 	position = love::Vector(x, y);
+	prevPosition = position;
 }
 }
 
 
 const love::Vector &ParticleSystem::getPosition() const
 const love::Vector &ParticleSystem::getPosition() const
@@ -481,6 +482,11 @@ const love::Vector &ParticleSystem::getPosition() const
 	return position;
 	return position;
 }
 }
 
 
+void ParticleSystem::moveTo(float x, float y)
+{
+	position = love::Vector(x, y);
+}
+
 void ParticleSystem::setAreaSpread(AreaSpreadDistribution distribution, float x, float y)
 void ParticleSystem::setAreaSpread(AreaSpreadDistribution distribution, float x, float y)
 {
 {
 	areaSpread = love::Vector(x, y);
 	areaSpread = love::Vector(x, y);

+ 9 - 0
src/modules/graphics/opengl/ParticleSystem.h

@@ -176,6 +176,15 @@ public:
 	 **/
 	 **/
 	const love::Vector &getPosition() const;
 	const love::Vector &getPosition() const;
 
 
+	/**
+	 * Moves the position of the center of the emitter.
+	 * When update is called, newly spawned particles will appear in a line
+	 * between the old emitter position and where the emitter was moved to,
+	 * resulting in a smoother-feeling particle system if moveTo is called
+	 * repeatedly.
+	 **/
+	void moveTo(float x, float y);
+
 	/**
 	/**
 	 * Sets the emission area spread parameters and distribution type. The interpretation of
 	 * Sets the emission area spread parameters and distribution type. The interpretation of
 	 * the parameters depends on the distribution type:
 	 * the parameters depends on the distribution type:

+ 10 - 0
src/modules/graphics/opengl/wrap_ParticleSystem.cpp

@@ -191,6 +191,15 @@ int w_ParticleSystem_getPosition(lua_State *L)
 	return 2;
 	return 2;
 }
 }
 
 
+int w_ParticleSystem_moveTo(lua_State *L)
+{
+	ParticleSystem *t = luax_checkparticlesystem(L, 1);
+	float arg1 = (float)luaL_checknumber(L, 2);
+	float arg2 = (float)luaL_checknumber(L, 3);
+	t->moveTo(arg1, arg2);
+	return 0;
+}
+
 int w_ParticleSystem_setAreaSpread(lua_State *L)
 int w_ParticleSystem_setAreaSpread(lua_State *L)
 {
 {
 	ParticleSystem *t = luax_checkparticlesystem(L, 1);
 	ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -649,6 +658,7 @@ static const luaL_Reg functions[] =
 	{ "getParticleLifetime", w_ParticleSystem_getParticleLifetime },
 	{ "getParticleLifetime", w_ParticleSystem_getParticleLifetime },
 	{ "setPosition", w_ParticleSystem_setPosition },
 	{ "setPosition", w_ParticleSystem_setPosition },
 	{ "getPosition", w_ParticleSystem_getPosition },
 	{ "getPosition", w_ParticleSystem_getPosition },
+	{ "moveTo", w_ParticleSystem_moveTo },
 	{ "setAreaSpread", w_ParticleSystem_setAreaSpread },
 	{ "setAreaSpread", w_ParticleSystem_setAreaSpread },
 	{ "getAreaSpread", w_ParticleSystem_getAreaSpread },
 	{ "getAreaSpread", w_ParticleSystem_getAreaSpread },
 	{ "setDirection", w_ParticleSystem_setDirection },
 	{ "setDirection", w_ParticleSystem_setDirection },

+ 1 - 0
src/modules/graphics/opengl/wrap_ParticleSystem.h

@@ -48,6 +48,7 @@ int w_ParticleSystem_setParticleLifetime(lua_State *L);
 int w_ParticleSystem_getParticleLifetime(lua_State *L);
 int w_ParticleSystem_getParticleLifetime(lua_State *L);
 int w_ParticleSystem_setPosition(lua_State *L);
 int w_ParticleSystem_setPosition(lua_State *L);
 int w_ParticleSystem_getPosition(lua_State *L);
 int w_ParticleSystem_getPosition(lua_State *L);
+int w_ParticleSystem_moveTo(lua_State *L);
 int w_ParticleSystem_setAreaSpread(lua_State *L);
 int w_ParticleSystem_setAreaSpread(lua_State *L);
 int w_ParticleSystem_getAreaSpread(lua_State *L);
 int w_ParticleSystem_getAreaSpread(lua_State *L);
 int w_ParticleSystem_setDirection(lua_State *L);
 int w_ParticleSystem_setDirection(lua_State *L);