AS3 Simple Bounce Not Rendering at Boundary

Hi guys I’m running some AS3-based animation, a simple bounce effect. A ball lies above a line, gravity as acceleration increases it’s negative velocity by 1 each frame. When it penetrates an arbitrary line it is move up accordingly and velocity is set to a high positive number (24).

At 40FPS, and with a high positive velocity set to the ball, the critical frame where it hits the “ground” doesn’t always render (maybe four out of five times fails), yet tracing outputs that it did indeed go across the bounce areas. Here are the 4 critical positions where 456 would be where it was wrapped to the ground:

405.4
433.8
456
424

Yet sometimes it seems to drop ONLY the render at 456, making it look really unpleasant. Since it is such simple code, the problem doesn’t lie in the efficiency. Does anyone know anything about this? Any suggestions to alleviate or work around it?

Thanks very much :slight_smile:


Edit: An isolated example! :slight_smile: The red box would represent the “ball” and it has the same stutter effect going on in my end - periodically the frame where the ground and it are touching isn’t rendered. This is 800x600 running at 60FPS:

import flash.events.Event;
import flash.display.Sprite;

var redblock:Sprite = new Sprite();
redblock.y = 456;
redblock.graphics.lineStyle(1, 0xFF0000, 1);
redblock.graphics.beginFill(0xFF0000, 1);
redblock.graphics.lineTo(800,0);
redblock.graphics.lineTo(800,400);
redblock.graphics.lineTo(0,400);
redblock.graphics.lineTo(0,0);
redblock.graphics.endFill();
addChild(redblock);

var stick:Sprite = new Sprite();
stick.graphics.lineStyle(1, 0x000000, 1);
stick.graphics.beginFill(0x000000, 1);
stick.graphics.lineTo(20,0);
stick.graphics.lineTo(20,-40);
stick.graphics.lineTo(0,-40);
stick.graphics.lineTo(0,0);
stick.graphics.endFill();


var velocity:Number = 0;

stick.x = 300;
addChild(stick);

addEventListener(Event.ENTER_FRAME, onEnterFrame);

function onEnterFrame(event:Event):void
{
        // Fake Gravity
	if(velocity > 10) velocity -= 1;
	else velocity -= 0.8;
	
	// Apply velocity
	stick.y -= velocity;

        // Penetrated Red Box, Move up and set high "bounce" velocity
	if(stick.y > 456)
	{
		stick.y = 456;
		velocity = 30;
	}
}