A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: bounce effect

  1. #1
    formally EquanFX
    Join Date
    May 2001
    Posts
    101

    bounce effect

    I have this code to make a ball bounce. it works fine, however, everything on the stage bounces. I only want the ball to bounce.
    Here is my code
    Code:
    /* Actionscript 3.0 Bounce Effect. ball = movieclip instance name*/
    var velocity = 0;
    var gravity = 2;
    var speed = 0.03;
    var ground = 300;
    Object(this).ball.addEventListener(Event.ENTER_FRAME, fl_bounce);
    function fl_bounce(event:Event) {
    	velocity +=  gravity;
    	velocity -=  speed * velocity;
    	y +=  velocity;
    	if (y > ground) {
    		y = ground;
    		velocity *=  -0.9;
    	}
    }
    Thanks
    A Fool is someone who keeps repeating the same thing, the same way, over, and over and expecting a different result

  2. #2
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    PHP Code:
    /* Actionscript 3.0 Bounce Effect. ball = movieclip instance name*/
    var velocity 0;
    var 
    gravity 2;
    var 
    speed 0.03;
    var 
    ground 300;
    ball.addEventListener(Event.ENTER_FRAMEfl_bounce);
    function 
    fl_bounce(event:Event) {
        
    velocity +=  gravity;
        
    velocity -=  speed velocity;
        
    ball.+=  velocity;
        if (
    ball.ground) {
            
    ball.ground;
            
    velocity *=  -0.9;
        }


  3. #3
    formally EquanFX
    Join Date
    May 2001
    Posts
    101
    I just tried your code, and it doesn't work.
    A Fool is someone who keeps repeating the same thing, the same way, over, and over and expecting a different result

  4. #4
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    there's nothing wrong with the code. your original script was using "y" without a qualifier - that means the entire move was programmed to move. making assumptions based on what you had, i set it so that the movie clip in that scope with the instance name of "ball" would be the only thing that moved. apparently your problem lies elsewhere.

    i don't know why you'd use this: Object(this).ball - but maybe you can try using that instead of "ball".

    yw

  5. #5
    formally EquanFX
    Join Date
    May 2001
    Posts
    101
    I copied the script you wrote, and applied it and it does not work. The ball just sits there. I'm gonna try to call the ball from the library instead of placing it on the stage, and see if that works. Thanks.
    A Fool is someone who keeps repeating the same thing, the same way, over, and over and expecting a different result

  6. #6
    formally EquanFX
    Join Date
    May 2001
    Posts
    101
    Never mind I got it to work Thanks for your help
    A Fool is someone who keeps repeating the same thing, the same way, over, and over and expecting a different result

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