Hello every body, i propose a small module for easy create effect in bge.
video : https://www.youtube.com/watch?v=b2vIKOxHp6s
example script :
from Effects import *
class MachineGunEffect(types.KX_Effect):
def __init__(self, parent):
self.createParticle(
inactList["MachineGunParticle1"], 0, 5,
Vector((1, 1, 1)),
Vector((0, 0, 0)),
Vector((0, 0, 0)),
Vector((1, 1, 1, 1)))
self.setAction(0, 0, 10)
self.setScale(0, 0)
self.setScale(0, 5, Vector((.3, .3, .3)))
self.setColor(0, 0., Vector((1, 1, 1, 1)))
self.setColor(0, 10., Vector((1, 1, 1, 0)))
self.createParticle(
inactList["MachineGunParticle2"], 0, 5,
Vector((1, 1, 1)),
Vector((0, 0, 0)),
Vector((0, 0, 0)),
Vector((1, 1, 1, 1)))
self.setAction(1, 0, 10, "MachineGunEffect0")
registerEffect(MachineGunEffect, "MachineGunEffect")
first of all we import the module, next we write an heiress class of KX_Effect, in this class the method init contains
arguments self and parent and in this method we create 2 particles thanks to :
createParticle(object, timer, life, scale, position, orientation, color,
random_scale = 0, random_position = 0, random_orientation = 0, random_color = 0)
object (KX_GameObject, string) : object to convert in particle
timer (int) : number of logic frame before create particle
life (int) : life of the object
scale (int) : initial scale of the particle when create it
position (int) : initial position of the particle when create it
orientation (int) : initial orientation of the particle when create it
color (int) : initial color of the particle when create it
random_scale (int) : random apply on the initial scale
random_position (int) : random apply on the initial position
random_orientation (int) : random apply on the initial orientation
random_color (int) : random apply on the initial color
we can anim particle thanks to :
setAction(index, frame_start, frame_end, action_name = “”)
index (int) : the number of the particle (first particle = 0, second = 1 …)
frame_start (int) : begin frame of the action
frame_end (int) : end frame of the action
action_name (string) : name of an action to recycle, if argument is empty we create a new empty action
if action_name = “” we can put keys on created action thanks to those functions :
note : all keys are delta value
setScale(index, frame, scale = Vector((0, 0, 0)))
index (int) : …
frame (int) : position of the key
scale (Vector) : key value
setPosition(index, frame, position = Vector((0, 0, 0)))
index (int) : …
frame (int) : position of the key
position (Vector) : key value
setRotation(index, frame, rotation = Vector((0, 0, 0)))
index (int) : …
frame (int) : position of the key
rotation (Vector) : key value
setColor(index, frame, color = Vector((1, 1, 1, 1)))
index (int) : …
frame (int) : position of the key
color (Vector) : key value
enregister effect :
registerEffect(effect, name)
effect (KX_Effect) : heiress class of KX_Effect, not an instance
name (string) : name of the effect
and to create :
createEffect(name, position, rotation, object, useParent)
name (string) : the name of the effect register before
position (Vector) : position where create the effect
rotation (Vector) : initial rotation of the created effect
object (KX_GameObject) : disable position and rotation arguments, create effect at the same place than the object
(like addObject)
useParent (boolean) : create parente relation between all particles of the effect and the object
there a small example who shows not much on this module, but gives a general idea.
for more information you can read the french topic on blender clan :
http://blenderclan.tuxfamily.org/html/modules/newbb/viewtopic.php?topic_id=42040&forum=3
.diff http://www.pasteall.org/53614/diff
binary file : https://drive.google.com/file/d/0B9ZUtuTdwcVbWGQtTXFsYmRIQzA/edit?usp=sharing
example .blend and scripts on [email protected]:panzergame/panzergamebge.git
sorry for my bad english, i’m french and bad in english.