Created
August 31, 2014 04:44
-
-
Save keyle/1bf585b22ecb14ea086b to your computer and use it in GitHub Desktop.
unresponsive mouse after a while
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package game | |
| { | |
| import flare.basic.Scene3D; | |
| import flare.basic.Viewer3D; | |
| import flare.core.Camera3D; | |
| import flare.core.Mesh3D; | |
| import flare.core.Pivot3D; | |
| import flare.core.Texture3D; | |
| import flare.flsl.FLSLMaterial; | |
| import flare.physics.colliders.SphereCollider; | |
| import flare.primitives.Cube; | |
| import flare.primitives.Quad; | |
| import flare.system.Input3D; | |
| import flash.display.Sprite; | |
| import flash.events.Event; | |
| import flash.events.MouseEvent; | |
| import flash.geom.Point; | |
| import flash.geom.Vector3D; | |
| import flash.text.TextField; | |
| import flash.text.TextFieldAutoSize; | |
| import flash.text.TextFormat; | |
| import framework.FPSMeter; | |
| import framework.SystemHandler; | |
| public class Flade3DView extends Sprite | |
| { | |
| private static const BLOOM_ACTIVE:Boolean = true; | |
| private static const PLAYER_ALTITUDE:int = 25; | |
| [Embed(source="../assets/bloom.flsl.compiled", mimeType="application/octet-stream")] | |
| private var bloomFilter:Class; | |
| private var scene:Viewer3D; | |
| private var quad:Quad; | |
| private var bloomTexture:Texture3D; | |
| public static var scene:Scene3D; | |
| private var player:Pivot3D; | |
| private var txt:TextField; | |
| private var _bulletPool:Vector.<Bullet> = new Vector.<Bullet>(100); | |
| private var _bulletMesh:Cube = new Cube("", 0.2, 0.2, 45); | |
| [Inject] | |
| public var fps:FPSMeter; | |
| private var velocity:Vector3D = new Vector3D(); | |
| private var friction:Vector3D = new Vector3D(0.98, 0.98, 0.98); | |
| private var oldPosition:Vector3D = new Vector3D(); | |
| [Init] | |
| public function init():void | |
| { | |
| scene = new Viewer3D(this); | |
| scene.autoResize = true; | |
| scene.antialias = 4; | |
| scene.showMenu = false; | |
| scene.showLogo = false; | |
| scene.skipFrames = false; | |
| if (BLOOM_ACTIVE) { | |
| scene.lights.defaultLight = null; | |
| scene.lights.ambientColor.setTo(0.2, 0.2, 0.2); | |
| bloomTexture = new Texture3D(new Point(128, 128), true); | |
| // creates the flsl bloom material.. | |
| var bloomMaterial:FLSLMaterial = new FLSLMaterial("bloom", new bloomFilter); | |
| bloomMaterial.params.bloomTexture.value = bloomTexture; | |
| bloomMaterial.params.intensity.value[0] = 1.5; | |
| bloomMaterial.params.power.value[0] = 2; | |
| // creates the quad to draw the effect into screen. | |
| quad = new Quad("bloom", 0, 0, 0, 0, true, bloomMaterial); | |
| } | |
| scene.addChildFromFile("/assets/scene.zf3d"); | |
| scene.addEventListener(Scene3D.COMPLETE_EVENT, loaded, false, 0, true); | |
| Main.scene3D = scene; | |
| Main.stage.addChild(this); | |
| } | |
| private function loaded(event:Event):void | |
| { | |
| SystemHandler.toggleFullscreen(); | |
| player = new Pivot3D("ourPlayer"); | |
| player.parent = scene; | |
| player.setPosition(0, 0, 0); | |
| player.collider = new SphereCollider(30); | |
| player.collider.neverSleep = true; | |
| scene.camera = new Camera3D("ourCamera", 90); | |
| scene.camera.y = PLAYER_ALTITUDE; | |
| scene.camera.fieldOfView = 90; | |
| scene.camera.far = 10000; | |
| scene.camera.parent = player; | |
| scene.camera.orthographic = true; | |
| scene.addEventListener(Scene3D.UPDATE_EVENT, update, false, 0, true); | |
| Main.stage.addEventListener(MouseEvent.MOUSE_MOVE, mousemove, false, 0, true); | |
| if (BLOOM_ACTIVE) { | |
| scene.addEventListener(Scene3D.POSTRENDER_EVENT, postRenderEvent, false, 0, true); | |
| } | |
| txt = new TextField(); | |
| txt.autoSize = TextFieldAutoSize.LEFT; | |
| txt.defaultTextFormat = new TextFormat("Arial", 11, 0xffffff); | |
| addChild(txt); | |
| txt.x = 5; | |
| txt.y = 5; | |
| velocity.z = 5; | |
| velocity.y = 5; | |
| fps.startFPS(Main.stage, scene); | |
| createBulletPool(); | |
| } | |
| private function createBulletPool():void | |
| { | |
| // create bullets | |
| for (var i:int = 0; i < _bulletPool.length; i++) | |
| { | |
| var newBullet:Bullet = new Bullet(_bulletMesh.clone(), this.scene); | |
| _bulletPool[i] = newBullet; | |
| newBullet.visible = false; | |
| scene.addChild(newBullet); | |
| var wal1w:Pivot3D = scene.getChildByName("wallW"); | |
| var wal1e:Pivot3D = scene.getChildByName("wallE"); | |
| var wal1s:Pivot3D = scene.getChildByName("wallS"); | |
| var wal1n:Pivot3D = scene.getChildByName("wallN"); | |
| newBullet.setCollitions(new <Pivot3D>[wal1w, wal1e, wal1s, wal1n]); | |
| } | |
| } | |
| private function postRenderEvent(event:Event):void | |
| { | |
| // for the bloom | |
| scene.render(scene.camera, false, bloomTexture); | |
| quad.draw(); | |
| } | |
| private var spinX:Number = 0; | |
| private var spinY:Number = 0; | |
| private function mousemove(event:MouseEvent):void | |
| { | |
| if (event.movementX != 0) { | |
| const mouseMoveX:Number = (event.movementX); | |
| spinX += mouseMoveX * 0.035; | |
| } | |
| if (event.movementY != 0) { | |
| const mouseMoveY:Number = (event.movementY); | |
| spinY += mouseMoveY * 0.035; | |
| } | |
| } | |
| private function update(event:Event):void | |
| { | |
| var playerVel:Number = 0.4; | |
| if (Input3D.keyDown(Input3D.SHIFT)) playerVel *= 2; | |
| if (Input3D.keyDown(Input3D.A)) player.translateX(-playerVel); | |
| if (Input3D.keyDown(Input3D.D)) player.translateX(playerVel); | |
| if (Input3D.keyDown(Input3D.S)) player.translateZ(-playerVel); | |
| if (Input3D.keyDown(Input3D.W)) player.translateZ(playerVel); | |
| if (Input3D.keyDown(Input3D.SPACE)) player.translateY(playerVel * 4); | |
| if (Input3D.keyDown(Input3D.Q)) player.translateX(-playerVel * 20); | |
| if (Input3D.keyDown(Input3D.E)) player.translateX(playerVel * 20); | |
| if (Input3D.mouseHit) fireBullet(); | |
| // TRY MOVE X | |
| player.x += velocity.x; | |
| scene.physics.step(); | |
| if (!player.collider.numContacts) { | |
| velocity.x = (player.x - oldPosition.x) * friction.x; | |
| } | |
| else { // bong | |
| player.x -= velocity.x; | |
| velocity.x = -velocity.x; | |
| } | |
| if (velocity.x > 10) velocity.x = 10; | |
| if (velocity.x < -10) velocity.x = -10; | |
| // TRY MOVE Z | |
| player.z += velocity.z; | |
| scene.physics.step(); | |
| if (!player.collider.numContacts) { | |
| velocity.z = (player.z - oldPosition.z) * friction.z; | |
| } | |
| else { | |
| player.z -= velocity.z; | |
| velocity.z = -velocity.z; | |
| } | |
| if (velocity.z > 10) velocity.z = 10; | |
| if (velocity.z < -10) velocity.z = -10; | |
| // ROTATION HORIZ | |
| player.rotateY(spinX, true); | |
| spinX *= .21; | |
| // ROTATION VERTICAL | |
| scene.camera.rotateX(spinY, true); | |
| spinY *= .21; | |
| // MOVE Y / FLY! | |
| player.y += velocity.y; | |
| velocity.y = (player.y - oldPosition.y) * friction.y; | |
| velocity.y -= 0.2; | |
| if (player.y < PLAYER_ALTITUDE) { | |
| player.y = PLAYER_ALTITUDE; | |
| } | |
| if (velocity.y > 10) velocity.y = 10; | |
| if (velocity.y < -10) velocity.y = -10; | |
| oldPosition.copyFrom(player.getPosition()); | |
| } | |
| private function fireBullet():void | |
| { | |
| trace("firebullet"); | |
| for each (var bullet:Bullet in _bulletPool) | |
| { | |
| if (!bullet.alive) | |
| { | |
| bullet.resetAt(player); | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Have a look at the build.
http://noben.org/ft/build.zip (22 MB)
WIGGLE the mouse LEFT / RIGHT while moving (WASD) for a while and observe that the camera becomes less and less responsive.
I've tried a lot of different options including removing all the easings. Same problem.
Also tried removing any flash UI, same problem.
Memory leak??? 3D update runs at 60fps, so is flash enterframe, about 60 fps.