effect in bge

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.

any moderator could move this thread on game engine support and discussion, please ?

Hello everyone, I continue the doc

First I change some logic things :

I rename KX_Effect ->KX_EffectObject and KX_Particle -> KX_ParticleObject

To register or to create actions we use KX_Particle menbers functions like :


KX_Particle.createAction(start, end)

or


KX_Particle.setAction(name, start, end)

The functions KX_EffectObject.createParticle(…) return a KX_ParticleObject python proxy and timer args is delete, this proxy may add in the effect with :


KX_EffectObject.addParticle(particle, timer)
particle (KX_ParticleObject) : particle to add
timer (int) : delay before to create particle

To register effect in the effects array we inherit this instance with an empty effect and register the result.


EmptyEffect() : return an empty effect register in scene

example :


registerEffect(MyEffect(emptyEffect()), « MyEffect »)

Second I forget some old feature :
To move texture for more realisme we use :


KX_ParticleObject.setUVAnim(tile_x, tile_y, UV_anim_speed, UV_anim_loop, UV_anim_ping_pong, start_tile_x, start_tile_y, UV_anim_randomized_start)
tile_x(int) number steps on x axis
tile_y (int) numbers steps on y axis
UV_anim_speed(in) : speed in anim frame
UV_anim_loop(bool) : move UV looped
UV_anim_ping_pong(bool) : inverse UV motion at end (need UV_anim_loop)
start_tile_x(int) : start step on x axis
start_tile_y(int) : start step on y axis
UV_anim_randomized_start(bool) : start motion on randomized step

To create particles according to speed of an object :


KX_EffectObject.setMovementFrequency(movement)
movement(int) : if object (in createEffect) move of this value we update timer

To repeat particles creation :


KX_EffectObject.setLoop(loops, loopspeed)
loops(int) : number of repetitions
loopspeed(int) : time between two repetitions

.diff : http://www.pasteall.org/53976/diff