tet*_*s11 1 algorithm animation
我正在尝试为一个跑步的人制作动画:
框架1到5 =男人倾向于奔跑.框架6到15 =人跑一步
frame = 1
frame +=1 //frames progress forwards at rate of 1 frame
function run(){
if(frame>15){ //at frame 15: man has completed leaning into run and completed one 'running' cycle
frame -=2 //frames now start to go backwards at rate of (1-2=)-1 frame
if(frame<6){ //until they reach frame 6 (beginning of running animation)
frame +=2 //frames start to progress forwards again at rate of (2-2+1=)+1 frame again
Run Code Online (Sandbox Code Playgroud)
我的方法非常糟糕,似乎只能在15到6之间前进然后向后.
有谁知道我怎么能无限期地在这两个数字之间反弹?
在达到frame = 15并开始向下行程之后,你会遇到一个条件(14),你的IF语句都不是真的.所以你的框架既不增加也不减少.卡住.
一个可能更好的解决方案是维护一个名为myDirection的变量,该变量定期在1和-1之间切换.也就是说,当你点击15时设置myDirection = -1,当你点击6时设置myDirection = 1.然后,你的迭代语句可以总是说 frame = frame + myDirection并且它总是会做某事 - 你永远不会无所事事.