lua 定时器以及应用

来源:互联网 发布:如何编写人工智能系统 编辑:程序博客网 时间:2024/06/09 23:52
function update_timer_fun()for k,v in pairs(update_timer.m_process_time_fun) dov(k,update_timer.m_porcess_run_time[k]);endend--注册一个新的update定时器 经过over_time时间后销毁 销毁后回调over_fun(手动消耗也会回调over_fun方法)update_timer.new_update = function(over_time,process_fun,over_fun)local t_over_time = over_time;if t_over_time == nil or t_over_time == 0 thent_over_time = update_timer_sd.over_time;endlocal t_over_time_id = gtime.create("update_timer.time_del_update",t_over_time,1);update_timer.m_process_time_fun[t_over_time_id] = process_fun;update_timer.m_over_time_fun[t_over_time_id] = over_fun;update_timer.m_porcess_run_time[t_over_time_id] = t_over_time;if update_timer.m_is_run_update == false thengscript.add_script(gscript.FUNCTION_UPDATE,"update_timer_fun");update_timer.m_is_run_update = true;endreturn t_over_time_id;endupdate_timer.time_del_update = function(time_id)if update_timer.m_process_time_fun[time_id] ~= nil thenupdate_timer.m_process_time_fun[time_id] = nil;endif update_timer.m_over_time_fun[time_id] ~= nil and update_timer.m_porcess_run_time[time_id] ~= nil thenupdate_timer.m_over_time_fun[time_id](time_id,update_timer.m_porcess_run_time[time_id]);update_timer.m_over_time_fun[time_id] = nil;update_timer.m_porcess_run_time[time_id] = nil;endif table.getall(update_timer.m_process_time_fun) == 0 thengscript.remove_script(gscript.FUNCTION_UPDATE,"update_timer_fun");update_timer.m_is_run_update = false;endend--旋转角度 从t_eff_time时间旋转 anglepanel_fun.eff_rotation = function(t_ctl,angle,t_eff_time)if t_ctl == nil then--sprint("\n eff_set_text error : not find t_ctl ! \n");return;endif angle == nil then--sprint("\n eff_set_text error : old num or new num is nil !!! \n");return;endpanel_fun.rotation_ctl[t_ctl:get_pid()] = t_ctl;if panel_fun.rotation_time_id[t_ctl:get_pid()] ~= nil thenif panel_fun.rotation_time_id[t_ctl:get_pid()] > 0 thenupdate_timer.stop_one(panel_fun.rotation_time_id[t_ctl:get_pid()]);endendif t_eff_time ~= nil thenpanel_fun.rotation_eff_time[t_ctl:get_pid()] = t_eff_time;elsepanel_fun.rotation_eff_time[t_ctl:get_pid()] = gld.text_eff_time;endpanel_fun.rotation_angle_num[t_ctl:get_pid()] = angle;panel_fun.rotation_time_id[t_ctl:get_pid()] = update_timer.new_update(panel_fun.rotation_eff_time[t_ctl:get_pid()],panel_fun.eff_rotation_start,panel_fun.eff_rotation_end);panel_fun.rotation_pid[panel_fun.rotation_time_id[t_ctl:get_pid()]] = t_ctl:get_pid();endpanel_fun.eff_rotation_start = function(time_id)local t_pid = panel_fun.rotation_pid[time_id];if t_pid == nil or t_pid == 0 thenreturn;endif panel_fun.rotation_angle_num[t_pid] == nil thenreturn;endif panel_fun.rotation_ctl[t_pid] == nil thenreturn;endif panel_fun.text_befor_time[t_pid] == nil or panel_fun.text_befor_time[t_pid] == 0 thenpanel_fun.text_befor_time[t_pid] = guntil.GetNowMsTime();endlocal t_interval_time =  guntil.GetNowMsTime() - panel_fun.text_befor_time[t_pid];panel_fun.text_befor_time[t_pid] = guntil.GetNowMsTime();if panel_fun.rotation_percent[t_pid] == nil thenpanel_fun.rotation_percent[t_pid] = (t_interval_time/panel_fun.rotation_eff_time[t_pid])*100;elsepanel_fun.rotation_percent[t_pid] = panel_fun.rotation_percent[t_pid] + (t_interval_time/panel_fun.rotation_eff_time[t_pid])*100;endif panel_fun.rotation_percent[t_pid] > 100 thenpanel_fun.rotation_percent[t_pid] = 100;endlocal t_angle = panel_fun.rotation_angle_num[t_pid]*panel_fun.rotation_percent[t_pid]/100;-- add_num = add_num - add_num % 1;local hand_x = panel_fun.rotation_ctl[t_pid]:get_width();local hand_y = panel_fun.rotation_ctl[t_pid]:get_height();panel_fun.rotation_ctl[t_pid]:set_rotation_anchor(hand_x / 2, hand_y / 2);panel_fun.rotation_ctl[t_pid]:set_rotation(t_angle);endpanel_fun.eff_rotation_end = function(time_id)local t_pid = panel_fun.rotation_pid[time_id];if t_pid == nil or t_pid == 0 thenreturn;endif panel_fun.rotation_angle_num[t_pid] == nil or thenreturn;endif panel_fun.rotation_ctl[t_pid] == nil thenreturn;endpanel_fun.rotation_ctl[t_pid]:set_rotation(panel_fun.rotation_angle_num[t_pid]);--释放panel_fun.rotation_ctl[t_pid] = nil;panel_fun.rotation_time_id[t_pid] = nil;panel_fun.rotation_angle_num[t_pid] = nil;panel_fun.rotation_eff_time[t_pid] = nil;panel_fun.text_befor_time[t_pid] = nil;panel_fun.rotation_percent[t_pid] = nil;panel_fun.rotation_pid[t_pid] = nil;end


                                             
1 0
原创粉丝点击