[swf]/blog/wp-content/uploads/2008/10/Bobbing.swf, 550, 400[/swf]
package { import flash.display.Sprite; import flash.events.Event; public class Bobbing extends Sprite{ private var _ball:Ball; private var _angle:Number = 0; private var _rangeY:Number = 70; private var _speedX:Number = 5; private var _speedY:Number = 0.2; public function Bobbing() { init(); } private function init():void { _ball = new Ball(); addChild(_ball); _ball.x = stage.stageWidth / 2; addEventListener(Event.ENTER_FRAME, onEnterFrame, false, 0, true); } private function onEnterFrame(e:Event):void { _ball.y = stage.stageHeight / 2 + Math.sin(_angle) * _rangeY; _angle += _speedY; //ステージの隅まで到達したら跳ね返る if (_ball.x > stage.stageWidth - _ball.width/2 || _ball.x < _ball.width/2) { _speedX = -_speedX; } _ball.x += _speedX; } } }