2016년 10월 28일 금요일

[GMS] use particle



게임을 구현하면서 유용한 파티클을 찾아 다녔는데, 그 중 두가지가 쓸만해 보여서 정리해 보았습니다.




https://drive.google.com/file/d/0B9vAKDzHthQIZ21PX29FR295Y00/view?usp=sharing

Fireworks

위 동영상에서 첫번째 나타나는 파티클입니다.
scr_create_paticle 스크립트내 case 1에 의해서 발생합니다.

var type = argument0;
var x1 = argument1;
var y1 = argument2;
var x2 = argument3;
var y2 = argument4;

switch(type){
case 0:
    with (instance_create(x1,y1,part_moving))
    {
        direction = point_direction(x1, y1, x2, y2);
    }
break;
case 1:
    // firework
    //Burst out loads of nice star particles!!!
    part_particles_create(global.P_System, x1, y1, global.ParticleStars , 50);
break;
}

위 스크립트가 동작하기위해서는 particle object를 생성해야 합니다.
왜냐하면 global.P_System, global.ParticleStars 변수가 초기화 되지 않았기 때문입니다.
particle object는 room이 생성될때 만들어지게 됩니다.
그리고 마우스 클릭이 될때마다 해당 스크립트를 수행하면서, part_particles_create 함수를 호출 하게 됩니다. 마지막 인자가 파티클을 몇개나 만들것인지를 결정하게됩니다.

Moving
동영상에서 뭔가가 꼬리를 만들어내며 요술봉 형태의 파티클을 생성해 내는 예제입니다. 이건 GMS내부에 있는 소스에서 가져온 내용입니다. 자세히 보면 파티클들이 생성과 반복을 계속해가며 특정 방향으로 이동하게 되는데, 생성과 반복될때 좌표계를 담당하는것이 part_moving object가 되며 실제 파티클을 생성하는 것은 emitter라고 합니다.
//Create emitter and name them...

//Note that although the emitter is local to the object,
//its still part of the global system and uses the global particles...

Particle1_Emitter1=part_emitter_create(global.P_System);

//Define emitter properties...
part_emitter_region(global.P_System, Particle1_Emitter1, x-5, x+5, y-5, y+5, choose(ps_shape_rectangle, ps_shape_diamond, ps_shape_ellipse, ps_shape_line), choose(ps_distr_linear, ps_distr_gaussian, ps_distr_invgaussian));

//Use an emitter to stream particles...
part_emitter_stream(global.P_System, Particle1_Emitter1, global.Particle1, 1);


//Set the movement
speed=10+random(3);
direction=random(360);
create event내에 emitter를 생성하게됩니다.
그리고 emitter가 생성해야 하는 범위를 현재 part_moving object근처가 되도록 합니다.
그래야 특정 방향으로 움직이는 파티클을 만들 수 있습니다.

//As the object is moving, we have to define the emitter in every step to keep up...
part_emitter_region(global.P_System, Particle1_Emitter1, x-5, x+5, y-5, y+5, choose(ps_shape_rectangle, ps_shape_diamond, ps_shape_ellipse, ps_shape_line), choose(ps_distr_linear, ps_distr_gaussian, ps_distr_invgaussian));

//For destroying the object...
if point_distance(x,y,room_width/2, room_height/2)>700 instance_destroy();
part_emitter_destroy(global.P_System, Particle1_Emitter1);
















댓글 없음:

댓글 쓰기