Get data on individual particles in your physics simulation.


physics_particle_get_data(buffer, flags)

参数 描述
buffer The (previously created) buffer to use to store the data.
flags The flags to use to extract data about specific particle types.

Returns: Buffer data


This function returns various pieces of information about each particle in the physics simulation using the given flags checked. The buffer used must have been created previously using the function buffer_create(), and should be of the "grow" type, with the size being approximately that of the expected return data. The flags are set using any of the constants given below, and you would use the bitwise or "|" to create a single flag value to get the desired information.

常量 描述 Data Type
phy_particle_data_flag_typeflags The flags value for the particle. buffer_u32
phy_particle_data_flag_position The x and y position of the particle. 2 x buffer_f32
phy_particle_data_flag_velocity The horizontal and vertical speed. 2 x buffer_f32
phy_particle_data_flag_colour The colour and alpha value (hexadecimal). buffer_f32
phy_particle_data_flag_category The particle category (as defined when you created the particle or group to which it belongs). buffer_f32


var count = physics_particle_count();
var flags = phy_particle_data_flag_position | phy_particle_data_flag_colour;
if (count > 0)
   var buffer = buffer_create(count * 12, buffer_grow, 4);
   physics_particle_get_data(buffer, flags);
   for (var n = 0; n < count; n++;)
      var xx = buffer_read(buffer, buffer_f32);
      var yy = buffer_read(buffer, buffer_f32);
      var argb = buffer_read(buffer, buffer_u32);
      var alpha = (argb >> 24) & 255;
      draw_sprite_ext(sprBlob, 0, xx, yy, 1, 1, 0, c_green, alpha);

The above code gets the number of particles and creates a variable with the data flags to check, then checks to see if there are any particles in the room. If there are, a buffer is created and then filled with the particle data, which is checked and used to draw a sprite at the particle position.

上一页: Soft Body Particles
下一页: physics_particle_get_data_particle
© Copyright YoYo Games Ltd. 2018 All Rights Reserved