Reprint please keep the original link, the individual public number: Xinshouit (Novice programmer), welcome attention
Preparatory work
Lengthen the background map, a long, long kind of .... We're going to have to slide it in a minute.
Background animation
Add a scrolling animation to a background node
Now the background is rolling up (the picture is I later cut, this step monkey didn't debut)
Monkey Brother Animation
Missile animation
Here we're going to add two clip, one high-altitude missile, one low-altitude missile.
Here we want to add a few frames to the missile, the missile missile on the head of a few frames on the addition of Judgedown events, when the missile reached the head of Monkey, monkey Brother has not bowed, then the game is over, low-altitude missiles, the same, need monkey brother jump
End scene
Game Script
Game.js
Cc. Class ({extends:cc.Component, properties: {king:{default:NULL, TYPE:CC. Node,}}, OnLoad: function () { var Self= this;//Left squat, right jumpThis.node.on (' Touchstart ', function(event){ varVisiblesize = Cc.director.getVisibleSize ();if(Event.getlocationx () <visiblesize.width/2){ Self. King.getcomponent (' King '). Down (); }Else{ Self. King.getcomponent (' King '). Jump (); } });//Left hand to resume running stateThis.node.on (' Touchend ', function(event){ varVisiblesize = Cc.director.getVisibleSize ();if(Event.getlocationx () <visiblesize.width/2){ Self. King.getcomponent (' King '). Downrelease (); }Else{//Self.king.getComponent (' King '). Jump ();} }); },});
King.js
Cc. Class ({extends: Cc.component, properties: {//lead jumping heightJumpheight:0,//Lead jumping durationJumpduration:0,//Lead statusState' Run ', },//RunRun function(){ This. getcomponent (CC. Animation). Play (' King_run '); This. State =' Run '; },//JumpJump function(){ if( This. state = =' Run '){ This. State =' Jump '; This. getcomponent (CC. Animation). Stop (); This. Node.runaction (Cc.sequence (Cc.jumpby ( This. Jumpduration, CC.P (0,0), This. Jumpheight,1), Cc.callfunc ( function() { This. Run (); }, This))); } },//Bend over and runDown function(){ if( This. state = =' Run '){ This. State =' Down '; This. Node.runaction (Cc.scaleto (0.05,1,0.5)); } },//Waist tiredDownrelease: function(){ if( This. state = =' Down '){ This. Node.runaction (Cc.sequence (Cc.scaleto (0.05,1,1), Cc.callfunc ( function() { This. Run (); }, This))); } },});
Bomb.js
Cc. Class ({extends:cc.Component, properties: {king:{default:NULL, TYPE:CC. Node,}},//Judging when the high-altitude missile comes, whether the monkey squat down (response to the frame event set before)Judgedown: function(){ if( This. King.getcomponent (' King '). State = =' Down ') {Console.log ("Down---------------------"); }Else{Cc.director.loadScene (' over '); } },//Judging when the low-altitude missile comes, does the monkey jumpJudgejump: function(){ if( This. King.getcomponent (' King '). State = =' Jump ') {Console.log ("Jump---------------------"); }Else{Cc.director.loadScene (' over '); }}, OnLoad: function () { LetSelf = This;//random launch of high and low altitude missiles every 2 seconds This. Schedule ( function(){ if(Math. Random () >0.5){ This. getcomponent (CC. Animation). Play (' Bomb_high '); }Else{ This. getcomponent (CC. Animation). Play (' Bomb_low '); } },3); },});
Over.js
cc.Class({ extends: cc.Component, properties: { }, function(){ cc.director.loadScene(‘Game‘); }, function () { },});
Final effect:
"Cocos Creator Practical Course (2)"--Every day cool run (animation, action-related)