|
@@ -355,6 +355,8 @@ void Particles2D::_process_particles(float p_delta) {
|
|
|
p.rot=Math::deg2rad(param[PARAM_INITIAL_ANGLE]+param[PARAM_INITIAL_ANGLE]*randomness[PARAM_INITIAL_ANGLE]*_rand_from_seed(&rand_seed));
|
|
|
active_count++;
|
|
|
|
|
|
+ p.frame=Math::fmod(param[PARAM_ANIM_INITIAL_POS]+randomness[PARAM_ANIM_INITIAL_POS]*_rand_from_seed(&rand_seed),1.0);
|
|
|
+
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -426,6 +428,8 @@ void Particles2D::_process_particles(float p_delta) {
|
|
|
|
|
|
p.pos+=p.velocity*frame_time;
|
|
|
p.rot+=Math::lerp(param[PARAM_SPIN_VELOCITY],param[PARAM_SPIN_VELOCITY]*randomness[PARAM_SPIN_VELOCITY]*_rand_from_seed(&rand_seed),randomness[PARAM_SPIN_VELOCITY])*frame_time;
|
|
|
+ float anim_spd=param[PARAM_ANIM_SPEED_SCALE]+param[PARAM_ANIM_SPEED_SCALE]*randomness[PARAM_ANIM_SPEED_SCALE]*_rand_from_seed(&rand_seed);
|
|
|
+ p.frame=Math::fposmod(p.frame+(frame_time/lifetime)*anim_spd,1.0);
|
|
|
|
|
|
active_count++;
|
|
|
|
|
@@ -474,9 +478,13 @@ void Particles2D::_notification(int p_what) {
|
|
|
RID ci=get_canvas_item();
|
|
|
Size2 size(1,1);
|
|
|
Point2 center;
|
|
|
+ int total_frames=1;
|
|
|
|
|
|
if (!texture.is_null()) {
|
|
|
size=texture->get_size();
|
|
|
+ size.x/=h_frames;
|
|
|
+ size.y/=v_frames;
|
|
|
+ total_frames=h_frames*v_frames;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -612,7 +620,17 @@ void Particles2D::_notification(int p_what) {
|
|
|
|
|
|
if (texrid.is_valid()) {
|
|
|
|
|
|
- texture->draw(ci,Point2(),color);
|
|
|
+ Rect2 src_rect;
|
|
|
+ src_rect.size=size;
|
|
|
+
|
|
|
+ if (total_frames>1) {
|
|
|
+ int frame = Math::fast_ftoi(Math::floor(p.frame*total_frames)) % total_frames;
|
|
|
+ src_rect.pos.x = size.x * (frame%h_frames);
|
|
|
+ src_rect.pos.y = size.y * (frame/h_frames);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ texture->draw_rect_region(ci,Rect2(Point2(),size),src_rect,color);
|
|
|
//VisualServer::get_singleton()->canvas_item_add_texture_rect(ci,r,texrid,false,color);
|
|
|
} else {
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(Point2(),size),color);
|
|
@@ -642,7 +660,9 @@ static const char* _particlesframe_property_names[Particles2D::PARAM_MAX]={
|
|
|
"params/initial_angle",
|
|
|
"params/initial_size",
|
|
|
"params/final_size",
|
|
|
- "params/hue_variation"
|
|
|
+ "params/hue_variation",
|
|
|
+ "params/anim_speed_scale",
|
|
|
+ "params/anim_initial_pos",
|
|
|
};
|
|
|
|
|
|
static const char* _particlesframe_property_rnames[Particles2D::PARAM_MAX]={
|
|
@@ -659,7 +679,9 @@ static const char* _particlesframe_property_rnames[Particles2D::PARAM_MAX]={
|
|
|
"randomness/initial_angle",
|
|
|
"randomness/initial_size",
|
|
|
"randomness/final_size",
|
|
|
- "randomness/hue_variation"
|
|
|
+ "randomness/hue_variation",
|
|
|
+ "randomness/anim_speed_scale",
|
|
|
+ "randomness/anim_initial_pos",
|
|
|
};
|
|
|
|
|
|
static const char* _particlesframe_property_ranges[Particles2D::PARAM_MAX]={
|
|
@@ -676,7 +698,9 @@ static const char* _particlesframe_property_ranges[Particles2D::PARAM_MAX]={
|
|
|
"0,360,0.01",
|
|
|
"0,1024,0.01",
|
|
|
"0,1024,0.01",
|
|
|
- "0,1,0.01"
|
|
|
+ "0,1,0.01",
|
|
|
+ "0,128,0.01",
|
|
|
+ "0,1,0.01",
|
|
|
};
|
|
|
|
|
|
|
|
@@ -909,6 +933,28 @@ bool Particles2D::is_flipped_v() const{
|
|
|
return flip_v;
|
|
|
}
|
|
|
|
|
|
+void Particles2D::set_h_frames(int p_frames) {
|
|
|
+
|
|
|
+ ERR_FAIL_COND(p_frames<1);
|
|
|
+ h_frames=p_frames;
|
|
|
+}
|
|
|
+
|
|
|
+int Particles2D::get_h_frames() const{
|
|
|
+
|
|
|
+ return h_frames;
|
|
|
+}
|
|
|
+
|
|
|
+void Particles2D::set_v_frames(int p_frames){
|
|
|
+
|
|
|
+ ERR_FAIL_COND(p_frames<1);
|
|
|
+ v_frames=p_frames;
|
|
|
+}
|
|
|
+int Particles2D::get_v_frames() const{
|
|
|
+
|
|
|
+ return v_frames;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
void Particles2D::set_emission_points(const DVector<Vector2>& p_points) {
|
|
|
|
|
@@ -958,6 +1004,12 @@ void Particles2D::_bind_methods() {
|
|
|
ObjectTypeDB::bind_method(_MD("set_flip_v","enable"),&Particles2D::set_flip_v);
|
|
|
ObjectTypeDB::bind_method(_MD("is_flipped_v"),&Particles2D::is_flipped_v);
|
|
|
|
|
|
+ ObjectTypeDB::bind_method(_MD("set_h_frames","enable"),&Particles2D::set_h_frames);
|
|
|
+ ObjectTypeDB::bind_method(_MD("get_h_frames"),&Particles2D::get_h_frames);
|
|
|
+
|
|
|
+ ObjectTypeDB::bind_method(_MD("set_v_frames","enable"),&Particles2D::set_v_frames);
|
|
|
+ ObjectTypeDB::bind_method(_MD("get_v_frames"),&Particles2D::get_v_frames);
|
|
|
+
|
|
|
ObjectTypeDB::bind_method(_MD("set_emission_half_extents","extents"),&Particles2D::set_emission_half_extents);
|
|
|
ObjectTypeDB::bind_method(_MD("get_emission_half_extents"),&Particles2D::get_emission_half_extents);
|
|
|
|
|
@@ -997,6 +1049,9 @@ void Particles2D::_bind_methods() {
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL,"config/flip_h"),_SCS("set_flip_h"),_SCS("is_flipped_h"));
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL,"config/flip_v"),_SCS("set_flip_v"),_SCS("is_flipped_v"));
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"config/texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture"));
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::INT,"config/h_frames",PROPERTY_HINT_RANGE,"1,512,1"),_SCS("set_h_frames"),_SCS("get_h_frames"));
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::INT,"config/v_frames",PROPERTY_HINT_RANGE,"1,512,1"),_SCS("set_v_frames"),_SCS("get_v_frames"));
|
|
|
+
|
|
|
|
|
|
|
|
|
for(int i=0;i<PARAM_MAX;i++) {
|
|
@@ -1054,6 +1109,7 @@ Particles2D::Particles2D() {
|
|
|
set_param(PARAM_INITIAL_ANGLE,0.0);
|
|
|
set_param(PARAM_INITIAL_SIZE,1.0);
|
|
|
set_param(PARAM_FINAL_SIZE,1.0);
|
|
|
+ set_param(PARAM_ANIM_SPEED_SCALE,1.0);
|
|
|
|
|
|
|
|
|
time=0;
|
|
@@ -1081,6 +1137,8 @@ Particles2D::Particles2D() {
|
|
|
flip_h=false;
|
|
|
flip_v=false;
|
|
|
|
|
|
+ v_frames=1;
|
|
|
+ h_frames=1;
|
|
|
|
|
|
emit_timeout = 0;
|
|
|
time_to_live = 0;
|