actionscript 3 - Rotation and movement in AS3 -
i want make minigame background (maze) rotating around same point, immovable playermc that's in middle of stage. rotation using 2 mcs, 1 parent, rotate, , 1 nested maze move according mouse/keyboard movement
unfortunately, x , y axes on maze moved @ 90deg movement 'up' change 'right'.
i realise sin , cos or translation matrix should trick, reason can't right.
here short gif summarising problem: http://blackdragonschronicles.strefa.pl/public/vertigo.gif appreciate in matter
you use matrix solves pretty nicely. in small example have movieclip called box sitting on stage. pivot in top left corner (0,0). if want rotate cube center first translate matrix half of width , height. rotate arbitrary angle, , apply matrix transformation box.
var angle:number = math.pi/64; var m:matrix = new matrix(); m.translate(-box.width >> 1, -box.height >> 1); stage.addeventlistener(event.enter_frame, loop); function loop(e:event):void { m.rotate(angle); box.transform.matrix = m; }
in same spirit translate matrix current world position. , rotate around point.
m.translate(position.x, position.y);
you can learn more matrices in as3 here.
Comments
Post a Comment