actionscript 3 - Resize as a function of distance between mc's -


i hope hasn't been asked before. when search questions pertaining rescaling window size.

now question. got 1 space ship firing beam against ship. want beam show time , want "bridge" 2 ships. in other words, want beam extend width between 2 ships.

i try dot movie clip 1 pixel wide , high (and aligned left edge). try resize following code: (target ship fire @ , owner ship firing)

dist.vx = target.x - owner.x; dist.vy = target.y - owner.y; dist.dist = math.sqrt(dist.vx*dist.vx + dist.vy*dist.vy);  width = dist.dist;  x = owner.x; y = owner.y; rotation = math.atan2(target.y-y, target.x-x)*180/math.pi; 

this doesn't work intended because 1) dot gets alot bigger in other dimension - how can "turn off" behavior? , 2) seems way wide - in angles...

any suggestions on either solving heigh/width scaling or on way achieve same effect?

(i'm new coding , flash.) thanks!

by resizing dot, have rectangle...

you can dynamically create sprite covering both ships , moveto hit point of 1 ship lineto other ship... not need distance calculation @ all. have being careful on placement of sprite. can calculate relative hitting points simple math.

suppose have mc space contining mc ship1 , mc ship2, , hit point coords on ships named hx, hy , use sprite s, calculation follows.

// calculate hit points relative mc space var s1hx:int = ship1.x + ship1.hx,      s1hy:int = ship1.y + ship1.hy,     s2hx:int = ship2.x + ship2.hx,     s2hy:int = ship2.y + ship2.hy, // sprite relative moveto lineto coords these.     mx: int, my: int,     lx: int, ly: int;  // top left of sprite minimum of hit coords.    s.x = (s1hx <= s2hx)? s1hx : s2hx; s.y = (s1hy <= s2hy)? s1hy : s2hy;  // can sprite relative moveto lineto coordinates: mx = s1hx - s.x;   = s1hy - s.y; lx = s2hx - s.x; ly = s2hy - s.y; 

the rest implementation using these fancy line styles etc...

to create new sprite:

var s:sprite = new sprite(); 

adding / removing to/from mc space:

space.addchild(s);  space.removechild(s); 

for graphics use graphics object of sprite.

s.graphics 

for setting line styles can use:

s.graphics.linestyle(...) ,  s.graphics.linebitmapstyle(...), s.graphics.linegradientstyle(...) 

functions, please read manual usage.

after setting line style draw line use:

s.graphics.moveto(mx,my); s.graphics.lineto(lx,ly); 

for pulsating effects have little more complicated things such using tween class can read here: http://help.adobe.com/en_us/flashplatform/reference/actionscript/3/fl/transitions/tween.html

note that: sprites no complicated magic, mc's not have timelines etc.

sprites try scale when width or height change programmatically. not touch them, moveto lineto automatically sets size of sprite...


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -