In many action games, the player controls the role can cast a more powerful than the ordinary attack of the power technology, the general operation is to hold the attack key for a period of time and then release, the specific effect like the following picture:
To do this, first record the time the key is pressed and the initial is 0:
this. sabrechargetime = 0;
The next step is the time required to cast the skill, releasing the key after this time, and then casting the skill, otherwise invalid:
this. Max_sabre_charge_time = 150;
The code structure is as follows:
if(key[74]) {//Attack This. Updatesabrecharge ();//Storage Capacity}Else { This. Releasepowerslash ();//cast Attack}functionUpdatesabrecharge () { This. sabrechargetime++;}functionReleasepowerslash (callback) {if( This. sabrechargetime > This. Max_sabre_charge_time) { This. State =State . Power_slash; This. Play (); Callback&&callback (); } This. Resetsabrecharge ();//Reset Counter}functionResetsabrecharge () { This. Sabrechargetime = 0; }
You can trigger the charge by holding down the attack key at each stage of the character action.
Update Log
2017/04/09 Update role Jumps
2017/04/21 Update role Sprint
2017/05/01 Update role State machine
2017/05/16 Update character attack animations
2017/05/22 Update character mobile attack animation
2017/05/24 Update character jump attack animation
2017/06/04 Update Map Drawing
2017/06/22 update camera, long-distance sprint
2017/07/01 Update Command Technology
2017/07/06 update of the storage Force technology
HTML5 2D Platform Game Development--the capacity-building skill of character action