views:

69

answers:

2

First,Sorry for my English. I wanted to make a flash game,it's about some fish swiming in a tank. All the fishes swim randomly,i don't need any rotation,just left and right direction will be fine with me. But the result is their actions are really odd. Can someone tell me how to make them swim just like real fishes?

And there's also another problem.When the number of fishes increased to 50 or more,the framerate will drop rapidly.

Sorry for my English again.

Now I use Tweenlite to control the swiming action ,and it works very well.But the framerate still drops if i add more than 40 or 50 fishes to the tank.I think there must be a better way to do this.

Here's my code

public  function onEnterFrame(event:Event):void{
        var time:Number = Math.sqrt(Math.pow(xOffset,2)+Math.pow(yOffset,2))/speed;
        TweenLite.to(this,time,{x:x+xOffset ,y:y+yOffset*0.5 ,ease:Quad.easeOut,onComplete:moveComplete});
    }*/

xOffset and yOffset in the code are random numbers

A: 

Now I use Tweenlite to control the swiming action ,and it works very well.But the framerate still drops if i add more than 40 or 50 fishes to the tank.I think there must be a better way to do this.

Here's my code

public  function onEnterFrame(event:Event):void{
        var time:Number = Math.sqrt(Math.pow(xOffset,2)+Math.pow(yOffset,2))/speed;
        TweenLite.to(this,time,{x:x+xOffset ,y:y+yOffset*0.5 ,ease:Quad.easeOut,onComplete:moveComplete});
    }*/

xOffset and yOffset in the code are random numbers

ertao
This should be part of your original question, not an answer.
Mike Atlas
sorry,my bad...
ertao
@ertao you will want to add this to your question using the edit button under your question. Copy this , then delete it using the delete option next link|edit. Add it to your question using edit (found under your question) then to differentiate it from what you originally wrote add something like **update** or **edit** . Also do not forget to read the faq http://stackoverflow.com/faq
phwd
+2  A: 

Using the OEF function you will create a new Tween and Calculate new movement Each frame. Maybe you should think of a cheaper way to calculate random movement.

Another solution is to chunk of the calculations so you only do a portion of the fish at the same time. So during each frame you only calculate 1/5 of the fish.

lollertits