Create a Flash game like Blockage – Movement prototype
This is one of those days when you want to make a thing work that way FULLSTOP.
And that’s it… this is the typical Blockage movement:
I wanted to do it without any timeline tween or tricks to change registration point on the fly, just using localToGlobal method. If you aren’t familiar with this method, read understanding AS3 localToGlobal method first.
So here it is the uncommented and unoptimized prototype. While comments and tutorial will come when I’ll integrate it into the making of the game, I think this can be useful to someone of you to have a sneak peak of what’s going on.
This is the main class:
1 2 3 4 5 6 7 8 9 10 11 | package { import flash.display.Sprite; public class blkg extends Sprite { private var block:block_mc=new block_mc(); public function blkg() { block.x=0; block.y=50; addChild(block); } } } |
and this is block_mc class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | package { import flash.display.Sprite; import flash.events.Event; import flash.geom.Point; public class block_mc extends Sprite { public var point:Point=new Point(50,50); public var defpoint:Point=new Point(50,100); public var rotation_dir=5; public var steps:uint=0; public function block_mc() { addEventListener(Event.ENTER_FRAME,on_enter_frame); } private function on_enter_frame(e:Event) { rotation+=rotation_dir; if (rotation%90==0) { rotation=0; steps++; if (steps==9) { steps=0; rotation_dir*=-1; if (rotation_dir>0) { point=new Point(50,50); } else { point=new Point(0,50); } } else { if (rotation_dir>0) { defpoint=new Point(50,0).add(defpoint); } else { defpoint=new Point(-50,0).add(defpoint); } } } var tmp_point:Point=localToGlobal(point); tmp_point=defpoint.subtract(tmp_point); x+=tmp_point.x; y+=tmp_point.y; } } } |
Just remember I am using a 50 pixel sided square with origin at 0,0 and that steps==9 at line 18 is used only to make the square go back and forth.
Download the source code and solve the mystery… or wait for next step.
They can be easily customized to meet the unique requirements of your project.
















(18 votes, average: 3.83 out of 5)









This post has 4 comments
web_fuzzi
hi,
thanks for this simple instruction.
i’ve got a question: can you tell me, how you made the star rating system on your page?
thanks
sam
It’s a plugin
Albert
http://wonderfl.net/c/5l5l
Apollo
Could you plz explain
if (rotation%90==0)