Cocos JS Custom jitter Action

Source: Internet
Author: User

Custom jitter action, record for reference

1 /**2 * Custom jitter action3  */4 varShake =cc. Actioninterval.extend ({5     //node initial position6Nodeinitialpos:NULL,7     //x-axis jitter amplitude8nodeshakestrengthx:0,9     //y-axis jitter amplitudeTennodeshakestrengthy:0, One     //jitter Time Aduration:0, -ctorfunction(duration,shakestrengthx,shakestrengthy) { -Cc. ActionInterval.prototype.ctor.call ( This); the          This. Duration =duration; -          This. Initwithduration (duration,shakestrengthx,shakestrengthy); -  -     }, +     //get a random value between two numbers -Getrandomstrength:function(Min,max) { +         returnMath.random () * (max-min+1) +min; A     }, atUpdatefunction(DT) { -         varrandx= This. Getrandomstrength (- This. NODESHAKESTRENGTHX, This. nodeshakestrengthx) *DT; -         varrandy= This. Getrandomstrength (- This. Nodeshakestrengthy, This. nodeshakestrengthy) *DT; - //Cc.log ("Randx:" +randx+ ", randy=" +randy); -          This. Target.setposition (Cc.padd ( This. NODEINITIALPOS,CC.P (Randx,randy))); -     }, inInitwithduration:function(duration,shakestrengthx,shakestrengthy) { -         if(CC. ActionInterval.prototype.initWithDuration.call ( This, duration)) { to              This. nodeshakestrengthx=Shakestrengthx; +              This. nodeshakestrengthy=shakestrengthy== ' undefined '?shakestrengthx:shakestrengthy; -             return true; the         } *         return false; $     },Panax NotoginsengStartwithtarget:function(target) { -Cc. ActionInterval.prototype.startWithTarget.call ( This, target); the          This. nodeinitialpos=target.getposition (); +     }, AStopfunction(){ the          This. Target.setposition ( This. Nodeinitialpos); +     } - }); $ /** $ * Custom jitter action - * @param {float}duration jitter time - * @param {number}shakestrengthx x axis jitter amplitude the * @param {number}shakestrengthy y-axis jitter amplitude - * @returns {Shake}Wuyi  */ theCc.shake =function(duration,shakestrengthx,shakestrengthy) { -     return NewShake (duration,shakestrengthx,shakestrengthy); Wu};

How to use:

1 var action = Cc.shake (0.4,20,20); 2 xx.runaction (action);

Reference article: http://blog.csdn.net/teng_ontheway/article/details/25307889

This address: http://www.cnblogs.com/wangjiajun/p/4670036.html

Cocos JS Custom jitter Action

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.