actionscript 3 - If condition explanation AS3 -
i found code online. i'm not sure means. it's create bouncing ball. im not sure whats saying in if condition.
is speed of object or it's going appear in stage? u please add //comment brief explanation. thank in advance!
if ( this.x >= nstagewidth - 10 ) { this.x = nstagewidth - 10; nspeedx *= -1; } else if ( this.x <= 10 ) { this.x = 10; nspeedx *= -1; } if ( this.y >= nstageheight - 10 ) { this.y = nstageheight - 10; nspeedy *= -1; } else if ( this.y <= 10 ) { this.y = 10; nspeedy *= -1; }
this code checks x
or y
property of object make sure it's within boundaries. if it's not, object's nspeedx
or nspeedy
property multiplied -1.
for example, if
x
less 10 or greater or equalnstagewidth-10
,nspeedx
multiplied -1, assume sends object traveling in opposite direction.
without more code, can't give exact implementation. however, based on how everything's named, guess code sends object bouncing 1 side of stage other (with 10 pixels of padding on either side).
Comments
Post a Comment