As experiment: Ball connection

Source: Internet
Author: User
Tags rand

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);
           }

    }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.