A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: How to apply gravity to an array of sprites?

Hybrid View

  1. #1
    Member
    Join Date
    Mar 2009
    Posts
    76

    Unhappy How to apply gravity to an array of sprites?

    How??
    Code:
    var spring:Number=.1;
    var frizione:Number=.98;
    var gravita:int=1;
    var limite:Number=stage.stageHeight;
    
    stage.frameRate=31;
    
    
    
    var colorsArray:Array = new Array();
    colorsArray=['0xFF0000','0xFFFF00','0x65FF00','0x0000FF','0xCC00FF'];
    var cwidth:Number = 360;
    var cirArray:Array = new Array();
    for (var i:int = 0; i < 30; i++)
    {
    var num = Math.floor(Math.random() * 5)
    var cir:Sprite = new Sprite();
    cir.graphics.lineStyle(1);
    cir.graphics.beginFill(colorsArray[num]);
    cir.graphics.drawCircle(0,50,cwidth);
    cir.x = Math.random() * 500 - 1500
    cir.y = Math.random() * 300
    cir.alpha =.5
    addChildAt(cir, i)
    cir.name="cir"+i
    cirArray[i] = this.getChildByName("cir"+i)
    }; 
    
    function motion(event:Event):void
    {
    for (var i:int = 0; i < 30; i++)
    {
    if (cirArray[i].x > 520)
    {
    cirArray[i].x = 00
    cirArray[i].y = Math.random()* 300
    } else
    cirArray[i].x +=25
    }
    }; 
    
    start_btn.addEventListener(MouseEvent.CLICK, startMotion);
    function startMotion(event:MouseEvent):void{
    stage.addEventListener(Event.ENTER_FRAME, motion);
    stop_btn.visible = true
    start_btn.visible = false
    };
    
    stop_btn.addEventListener(MouseEvent.CLICK, stopMotion);
    function stopMotion(event:MouseEvent):void{
    stage.removeEventListener(Event.ENTER_FRAME, motion);
    stop_btn.visible = false
    start_btn.visible = true
    };

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429

  3. #3
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    http://www.amazon.com/Foundation-Act...7275607&sr=8-1

    one of the best books i have ever purchased.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center