![]() |
|
||||||||||
|
|||||||
|
|
« Предыдущая тема | Следующая тема » |
| Опции темы | Опции просмотра |
|
![]() |
![]() |
|
|||||
|
Регистрация: Jan 2012
Сообщений: 836
|
private function timerMove(event:TimerEvent):void { _gomob.stop(); flag_go = true; velo.setMembers((Math.random() - 0.5) * 250, (Math.random() - 0.5) * 250); var len:int = int(velo.magnitude()); if (len < 30) velo.mulScalar(30 / len); target_x = x + velo.x; target_y = y + velo.y; velo.mulScalar(speedMob / velo.magnitude()); for (var i:uint = 0; i < main_plat.mob.platform_mobs.length; i++) { main_plat.mob.platform_mobs[i].rotation = velo.getDirection() + 90; } addEventListener(Event.ENTER_FRAME, dvizhenie); } private function dvizhenie(e:Event):void { var oldmob_x:int = x; var oldmob_y:int = y; var tmp_velo: Vec_tor = velo.getMulScalar(Conf.SPF); for (var i:uint = 0; i < main_plat.mob.platform_mobs.length; i++) { main_plat.mob.platform_mobs[i].x += tmp_velo.x; main_plat.mob.platform_mobs[i].y += tmp_velo.y; } |
|
|||||
|
Banned
[+4 24.02.14]
[+4 07.11.13] [+ 13.03.14] Регистрация: Mar 2013
Сообщений: 1,864
|
Создайте класс, в конструктор которого будете передавать DO стартовые координаты и конечные.
Сделаете в этом классе метод move, в котором будет расчитан вектор направления по старту и финишу. И потом в ентер фрайме передавайте по очереди в метод move значение скорости. |
|
|||||
|
Регистрация: Jan 2012
Сообщений: 836
|
До стартовые координаты объектов в массиве? А можно пример если не затруднит?
|
|
|||||
|
Banned
[+4 24.02.14]
[+4 07.11.13] [+ 13.03.14] Регистрация: Mar 2013
Сообщений: 1,864
|
package { import flash.display.Shape; import flash.display.Sprite; import flash.events.Event; public class MainMove extends Sprite { private static const SPEED:Number = 0.001; private var _junggler:Juggler; public function MainMove() { var target:Shape; var move:Move; const WIDTH:Number = stage.stageWidth; const HEIGHT:Number = stage.stageHeight; for (var i:int = 0; i < 20; i++) { target = createCircle(int( Math.random() * 40) + 10, Math.random() * 0xff); target.x = int( Math.random() * WIDTH); target.y = int( Math.random() * HEIGHT); super.addChild(target); move = new Move(target, 'x', target.x, int(Math.random() * WIDTH), move); move = new Move(target, 'y', target.y, int(Math.random() * HEIGHT), move); } _junggler = new Juggler(move); stage.addEventListener(Event.ENTER_FRAME, stage_enterFrameHandler); } private function stage_enterFrameHandler(event:Event):void { _junggler.move(SPEED); } private function createCircle(radius:Number, color:uint):Shape { var circle:Shape = new Shape(); circle.graphics.beginFill(color); circle.graphics.drawCircle(0, 0, radius); circle.graphics.endFill(); return circle; } } } package { import flash.display.DisplayObject; public class Juggler { protected var _moves:Move; public function get moves():Move { return this._moves; }; public function set moves(value:Move):void { if (value == this._moves) return; this._moves = value; } public function Juggler(moves:Move = null) { if (moves != null) this._moves = moves; } protected var speed:Number = 0; public function move(speed:Number):void { this.speed += speed; var move:Move = this._moves; var target:DisplayObject; while (move != null) { target = move.target; target[move.prop] = move.finish * this.speed + move.start; move = move.next; } } } } package { import flash.display.DisplayObject; public class Move { public var target:DisplayObject; public var prop:String; public var start:Number; public var finish:Number; public var next:Move; public function Move(target:DisplayObject, prop:String, start:Number, finish:Number, next:Move = null) { this.target = target; this.prop = prop; this.start = start; this.finish = finish - start; this.next = next; } } } |
![]() |
![]() |
Часовой пояс GMT +4, время: 18:24. |
|
|
« Предыдущая тема | Следующая тема » |
|
|