GameMaker The bullet with particles needs to be destroyed to appear particles in another one

C

Charbelim06

Guest
I have a little problem, when i shoot it appears the particles, then i shoot again and it doesn't do with the another bullet, apparently it requires to the other bullet be destroyed to appear in the next bullet

This is what i did in the creation code
GML:
part_system = part_system_create()
part_emitter = part_emitter_create(part_system)

part_type = part_type_create()
part_type_shape(part_type, pt_shape_square)
part_emitter_stream(part_system,part_emitter,part_type,1)
part_type_size(part_type, 0, 0.07, -0.001, 0)
part_type_alpha3(part_type, 0, 1, 0); part_type_color3(part_type, c_red, c_yellow, c_white)
And this in the step event
GML:
part_emitter_region(part_system, part_emitter, bullet_test.x-1, bullet_test.x+1, bullet_test.y-1, bullet_test.y+1, ps_shape_rectangle, ps_distr_linear)
part_emitter_burst(part_system, part_emitter, part_type, 2)
 

Slyddar

Member
The creation of the particle system and part_type should be done once at the start of the game, not with each particle that is created. Just have something run it when the game starts, you can even make it global to reference it easily from the step event of the bullet instance.
 
C

Charbelim06

Guest
The creation of the particle system and part_type should be done once at the start of the game, not with each particle that is created. Just have something run it when the game starts, you can even make it global to reference it easily from the step event of the bullet instance.
This will not affect the part_system_destroy() that i added for when the bullet collides with some wall or enemy?
 

Slyddar

Member
This will not affect the part_system_destroy() that i added for when the bullet collides with some wall or enemy?
Just as creating the system and the part_type, you don't destroy it unless you no longer need later on in the game. The manual may scare people off by sounding over cautious in it's warnings regarding memory leaks, and deletions of particle systems, but essentially if you will use it again later on, leave it. With a bullet particle, you definitely do not want to create and destroy systems for every bullet.
 

NightFrost

Member
As said, you only need to define the system, the emitter and the particle only once and destroy only once. Since you're moving the code out of the bullet, you should declare them as globals so each bullet can still access the definitions. So your declarations would go like:
GML:
global.part_system = part_system_create();
And bullet would access them like:
GML:
part_emitter_region(global.part_system, global.part_emitter ...... );
However you have to fix an issue in your code first. You are requesting through object reference in your part_emitter_region() code. When you request for bullet_test.x there, GML finds the first bullet_test instance it can find and returns its x value, which isn't what you wanted. Since the bullet is changing its own variables, you simply request x and y which are its own values, ie:
GML:
part_emitter_region(global.part_system, global.part_emitter, x-1, x+1, y-1, y+1, ps_shape_rectangle, ps_distr_linear)
This is why multitple bullets weren't displaying the particles. You were always drawing them to same position in each bullet. Only when you destroyed a bullet, did the object reference find another bullet instead.
 
Top