
04.03.2013, 17:50
|
|
Регистрация: Mar 2013
Сообщений: 19
|
Цитата:
Сообщение от Wolsh
 Код AS3:
package
{
import com.greensock.TweenLite;
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
/**
* ...
* @author wolsh
*/
public class Main extends Sprite
{
[Embed(source = "../lib/post-529562-12628386921211212.jpg")] private const Fish:Class;
private var _fish:Bitmap;
private var _targetX:Number;
private var _targetY:Number;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
_fish = new Fish();
_fish.smoothing = true;
this.addChild(_fish);
_targetX = stage.stageWidth / 2;
_targetY = stage.stageHeight / 2;
go();
}
private function go():void
{
var angle:Number = 180 / Math.PI * Math.atan2(_targetY - _fish.y, _targetX - _fish.x);
if (_targetX < _fish.x) TweenLite.to(_fish, 0.5, { scaleX: -1, rotation:180+angle, onComplete:onDirect } );
else if (_targetX > _fish.x) TweenLite.to(_fish, 0.5, { scaleX: 1, rotation:angle, onComplete:onDirect } );
else onDirect();
}
private function onDirect():void
{
TweenLite.to(_fish, 1, { x: _targetX, y:_targetY, rotation:0, onComplete:onFloat } );
}
private function onFloat():void
{
_targetX = Math.random() * stage.stageWidth;
_targetY = Math.random() * stage.stageHeight;
go();
}
}
}
|
Буду очень Вам благодарен, если скините fla. исходник, и код в кадрах будет)))
Добавлено через 1 минуту
А то не очень разобрался.....
|