سؤال

I'm working on a character in flash that will go along with my game. It's a simple character for now and I thought about adding breathing animations to the idle positions (when they're not walking or doing an action). I know I could just animate each and every frame, but is there an easier way? I thought about just using the tweening thing but I'm not sure if that would look realistic enough.

Is there an easy way to do this? If so, how? Also, if you have any examples I could look at, that'd be great.

Thanks.

هل كانت مفيدة؟

المحلول

Well, it won't be realistic without some pretty advanced coding, but you can get away with some simple breathing by utilizing the Math functions, sine or cosine. Make a new character movieclip, make sure the registration point is at the bottom of your character (at the feet), give it an instance name of char, and use this code on your Main Timeline frame (outside the movieclip):

var num = 0;

// change these to speed up/down AND change range/radius of breathing
var speed = 0.1;
var radius = 2.5;

var newHeight = char._height;
var originalHeight = char._height;

onEnterFrame = function(){
    newHeight = originalHeight - (Math.sin(num)*radius);
    num += speed;
}

function breathe(){
    char._height = newHeight;
}

// this is to NOT make the breathing smooth, the lower the smoother
setInterval(breathe, 50);

Not the best solution in the world, but hey, at least it looks half decent.

HERE'S A DEMONSTRATION

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top