physics_particle_create

使用此函数,您可以在游戏室内的任何位置创建单个粒子,设置某些标志和属性。"flags" 是下列 常量 的组合的返回值:

物理粒子标志常量
常量描述
phy_particle_flag_waterThe default properties for a soft body particle.
phy_particle_flag_zombieA zombie particle is one that will be destroyed after a single step with all others flagged in this way.
phy_particle_flag_wallThis defines the particle as static, essentially creating it as an immovable object in the physics simulation, as they will remain in a fixed position no matter what collides with them. You should use this flag rather than set the density to 0.
phy_particle_flag_springSpring particles produce the effect of being attached to one another, as if by a spring. Particles created with this flag are "connected" in pairs, with each particle being connected to the one that was closest to it at the time of creation. Once paired, particles do not change "partners" , and the farther an external force pulls them from one another, the greater the power with which they will collide when that external force is removed. Note that no matter how far paired particles get from each another, the connection between them will not snap.
phy_particle_flag_elasticElastic particles deform and may also bounce when they collide with other rigid bodies in the physics simulation.
phy_particle_flag_viscousA viscous particle is one that exhibits "clinginess" or "stickiness", like oil. Viscous particles will clump and stick together more.
phy_particle_flag_powderPowder particles produce a scattering effect such as you might see with sand or dust.
phy_particle_flag_tensileTensile particles are used to produce the effect of surface tension, or the taut curvature on the surface of a body of liquid. They might be used, for example, to create the surface tension you would see on a drop of water. Once the tension is broken, the particles bounce as if they were elastic, but also continue to attract each other. As a result, particles tend to form clusters as they bounce.
phy_particle_flag_colourmixingColour-mixing particles take on some of the colour of other particles with which they collide. Note that if only one of the two colliding particles is a colour-mixing one, the other particle retains its pre-collision colour.

这些标志使用位掩码创建最终输出值,然后选中该值以设置粒子的不同基本属性 (基本属性始终为 phy_particle_flag_water 的基本属性)。例如,如果要模拟具有表面张力的粘性液体,则可以使用 "|" 来标记适当的位,如下例所示。通过这种方式,可以为创建的每个单独粒子设定不同的属性 (全局属性除外)。

除了标志之外,还可以在房间中设置创建粒子的位置、初始水平和垂直速度、初始颜色和 Alpha 以及用户 类别 。颜色和 Alpha 值仅在使用函数 physics_particle_draw() 绘制粒子时使用,但类别值用于多个其他函数。该值是一个任意整数值,您可以为每个粒子提供希望具有类似属性的值,以后可以使用该值为该特定类别以及许多其他类别设置标志。例如,如果定义了"水"和"油"粒子,则会将标记为"水"的所有粒子的用户类别指定为 1,将创建为"油"的所有粒子的用户类别指定为 2,允许您以后针对单个类别更改其标记或获取特定数据。

注意: 您可以对类别使用除 0 之外的任何整数值,该值由模拟保留,用于选择其他函数中的所有类别 (如用于绘制)。

该函数返回粒子的唯一索引 (或 ID) 值,该值可以存储在变量中,用于直接参考粒子的其他函数。

 

语法:

physics_particle_create(flags, x, y, xv, yv, col, alpha, category)

参数类型描述
flags物理粒子标志常量(s)要在粒子上设置的标志。
xReal用于创建粒子的 X 位置。
yReal用于创建粒子的 Y 位置。
xvReal初始水平速度。
yvReal初始垂直速度。
colColour用于粒子的基础颜色。
alphaReal用于粒子的基本 Alpha。
categoryReal用户定义了粒子所属的类别。

 

返回:

Physics Particle ID

 

例子:

var flags = phy_particle_flag_water | phy_particle_flag_viscous | phy_particle_flag_tensile;
var x_vel = lengthdir_x(5, image_angle);
var y_vel = lengthdir_y(5, image_angle);
var p = physics_particle_create(flags, x, y, x_vel, y_vel, c_white, 1, 1);

上述代码将创建变量以设置粒子类型及其初始速度,然后使用这些变量在实例 X/Y 位置创建粒子。