Very simple effect, is inspired by the book to do, but inefficient, look back to see how the book is achieved, the code is written by themselves, found that the effect is very simple actually
Ball Code
Package
{
Import Flash.display.CapsStyle;
Import Flash.display.JointStyle;
Import Flash.display.Sprite;
Import flash.events.TimerEvent;
Import Flash.display.Shape;
public class Ball extends Shape
{
public Var radius=10;
public Var vx=0;
public Var vy=0;
Public Function Ball ()
{
This.draw ();
This.x=this.radius;
This.y=this.radius;
}
function Draw ()
{
This.graphics.beginFill (0x336fe9,.7)
This.graphics.drawCircle (0,0,this.radius);
This.graphics.endFill ();
Trace ("Square innit");
}
function Move ()
{
THIS.X+=THIS.VX;
This.y+=this.vy;
if (this.x>this.stage.stagewidth| | THIS.X<0)
THIS.VX=-THIS.VX;
if (this.y>this.stage.stageheight| | THIS.Y<0)
This.vy=-this.vy;
}
}
}
Myas class, I wrote the class myself
package {
import flash.display.Sprite;
public class myAS extends Sprite
{
public function myAS()
{
for(var i=0;i<10;i++)
{
rand(5);
}
}
//返回一个随机值
public static function rand(x)
{
var returnvar=Math.ceil(Math.random()*(x));
trace(returnvar);
return returnvar;
}
//产生带有负象限的随机值
public static function randNeg(x){
if(Math.random()<0.5)
return Math.ceil(Math.random()*x)*(-1);
else return Math.ceil(Math.random()*x);
}
}
}