actionscript 3 - How to make a movieClip move independent of the stage if added on it? -
in flash-made game, if character jump on top of enemy movieclip spawns 3 minions class movieclip(root).addchild(spawn1);
. in minions class i've put code them fall , stop upon hitting ground , follow character.
i have vcam(virtual camera) movieclip follow character(who moves on stage, not stage around him) code build-in:
import flash.events.event; import flash.geom.matrix; import flash.geom.rectangle; import flash.geom.point; import flash.display.movieclip; //vcam addeventlistener(event.enter_frame, handleenterframe); function handleenterframe(event:event):void { if (parent) { parent.scalex = 1 / scalex; parent.scaley = 1 / scaley; if (rotation == 0) { parent.x = (width / 2 - x) / scalex; parent.y = (height / 2 - y) / scaley; parent.rotation = 0; } else { var bounds:rectangle = getbounds(this); var angle:number = rotation * math.pi / 180; var midx:number = -x / scalex; var midy:number = -y / scaley; var rx:number = -bounds.width / 2; var ry:number = -bounds.height / 2; var cos:number = math.cos(angle); var sin:number = math.sin(angle); var rotatedx:number = rx * cos - ry * sin; var rotatedy:number = ry * cos + rx * sin; var cornerx:number = midx - rotatedx; var cornery:number = midy - rotatedy; cos = math.cos(-angle); sin = math.sin(-angle); parent.x = cornerx * cos - cornery * sin; parent.y = cornery * cos + cornerx * sin; parent.rotation = -rotation; } } } addeventlistener(event.removed, handleremoved, false, 0, true); function handleremoved(event:event):void { removeeventlistener(event.enter_frame, handleenterframe); removeeventlistener(event.removed, handleremoved); }
when jump character seems minions follow movement of vcam , not behaving normally, jumping camera , falling throu'the ground when character falls.
if add child main timeline addchild(m_clip);
not behave that.
is there easy fix? thanks!
this minions class code:
package { import flash.display.*; import flash.events.*; public class enemyspawned extends movieclip { protected var gravitysp: number = 1; protected var yspeedsp: number = 0; protected var speedsp: number = 6.5; var charmtl:movieclip; public function enemyspawned() { this.addeventlistener(event.enter_frame, movement); trace('exist'); } function movement(event:event):void { var mtl:movieclip = movieclip(root); charmtl = mtl.char1; yspeedsp += gravitysp; if(! mtl.ground_1.hittestpoint(this.x, this.y, true)) { this.y += yspeedsp; } if(yspeedsp > 40) { yspeedsp = 40; } for(var j:int = 0; j<20; j++) { if(mtl.ground_1.hittestpoint(this.x, this.y, true)) { this.y-- yspeedsp = 0; } } var distance:number = charmtl.x - this.x; if(distance < -charmtl.width/2 - this.width/2) { this.x -= speedsp; } if(distance > charmtl.width/2 + this.width/2) { this.x += speedsp; } } } }
there no moving of ground_1
movieclip via code.