public ApplicationSprite() { this.InvokeWhenStageIsReady( delegate() { content.AttachToContainer(this); content.AutoSizeTo(this.stage); if (Accelerometer.isSupported) { //var a = new Accelerometer(); a = new Accelerometer(); a.update += e => { content.Accelerate( e.accelerationX, e.accelerationY, e.accelerationZ ); }; a.setRequestedUpdateInterval(1000 / 30); } } ); this.click += delegate { this.stage.SetFullscreen(true); }; }
public ApplicationSprite() { this.InvokeWhenPromotionIsReady( () => { this.stage.color = 0; this.stage.frameRate = 30; this.stage.frameRate = 60; // http://gamua.com/starling/first-steps/ // http://forum.starling-framework.org/topic/starling-air-desktop-extendeddesktop-fullscreen-issue Starling.handleLostContext = true; var s = new Starling( typeof(StarlingGameSpriteWithTestGamePad).ToClassToken(), this.stage, // http://forum.starling-framework.org/topic/air-34 profile: "baseline" ); //Starling.current.showStats s.showStats = true; #region atresize Action atresize = delegate { // http://forum.starling-framework.org/topic/starling-stage-resizing s.viewPort = new ScriptCoreLib.ActionScript.flash.geom.Rectangle( 0, 0, this.stage.stageWidth, this.stage.stageHeight ); s.stage.stageWidth = this.stage.stageWidth; s.stage.stageHeight = this.stage.stageHeight; //b2stage_centerize(); }; atresize(); #endregion StarlingGameSpriteBase.onresize = yield => { this.stage.resize += delegate { atresize(); yield(this.stage.stageWidth, this.stage.stageHeight); }; yield(this.stage.stageWidth, this.stage.stageHeight); }; this.stage.enterFrame += delegate { StarlingGameSpriteBase.onframe(this.stage, s); }; s.start(); #region FULL_SCREEN_INTERACTIVE this.stage.keyUp += e => { if (e.keyCode == (uint)System.Windows.Forms.Keys.F11) { this.stage.displayState = ScriptCoreLib.ActionScript.flash.display.StageDisplayState.FULL_SCREEN_INTERACTIVE; } if (e.keyCode == (uint)System.Windows.Forms.Keys.F) { this.stage.displayState = ScriptCoreLib.ActionScript.flash.display.StageDisplayState.FULL_SCREEN_INTERACTIVE; } }; #endregion content.r.Opacity = 0; content.AttachToContainer(this); content.AutoSizeTo(this.stage); var InactiveOpaciy = 0.07; var ActiveOpaciy = 0.5; #region bind Action<UIElement, Keys> bind = (ui, key) => { // Implementation not found for type import : //type: System.Windows.UIElement //method: Void add_MouseDown(System.Windows.Input.MouseButtonEventHandler) //ui.MouseDown += ui.Opacity = InactiveOpaciy; ui.MouseLeftButtonDown += (sender, e) => { ui.Opacity = ActiveOpaciy; e.Handled = true; StarlingGameSpriteWithTestGamePad.__keyDown[key] = true; }; //ui.MouseUp += ui.MouseLeftButtonUp += (sender, e) => { ui.Opacity = InactiveOpaciy; e.Handled = true; StarlingGameSpriteWithTestGamePad.__keyDown[key] = false; }; ui.TouchDown += (sender, e) => { ui.Opacity = ActiveOpaciy; e.Handled = true; StarlingGameSpriteWithTestGamePad.__keyDown[key] = true; }; ui.TouchUp += (sender, e) => { ui.Opacity = InactiveOpaciy; e.Handled = true; StarlingGameSpriteWithTestGamePad.__keyDown[key] = false; }; }; #endregion //bind(content.up, Keys.Up); //bind(content.down, Keys.Down); //bind(content.left, Keys.Left); //bind(content.right, Keys.Right); bind(content.enter, Keys.Enter); bind(content.space, Keys.Space); bind(content.control, Keys.ControlKey); bind(content.alt, Keys.Alt); var text = new TextField().AttachTo(this); text.width = 800; text.y = 72; text.textColor = 0xffffff; text.multiline = true; if (Accelerometer.isSupported) { StarlingGameSpriteWithTestGamePad.__keyDown.InitializeConnection( text: text, yield_Notify: xml => { if (xml.Name.LocalName == "switchto") { var type = xml.Attribute("type").Value; StarlingGameSpriteWithTestGamePad.__switchto(type); } } ); //var a = new Accelerometer(); a = new Accelerometer(); a.update += e => { //text.text = new //{ // x = e.accelerationX, // y = e.accelerationY, // z = e.accelerationZ //}.ToString(); content.tiltx = 1 - (e.accelerationX + 0.5); content.tilty = e.accelerationY; content.tilt_update(); StarlingGameSpriteWithTestGamePad.__keyDown.forcex = ((Math.Abs(content.tiltx - 0.5) / 0.5) - 0.05) * 0.3; StarlingGameSpriteWithTestGamePad.__keyDown.forcey = Math.Abs(content.tilty - 0.5) / 0.5; content.rtiltx.Opacity = StarlingGameSpriteWithTestGamePad.__keyDown.forcex; content.rtilty.Opacity = StarlingGameSpriteWithTestGamePad.__keyDown.forcey; // we did do this for TestDrive example! #region StarlingGameSpriteWithTestGamePad if (e.accelerationX > 0.05) { StarlingGameSpriteWithTestGamePad.__keyDown[Keys.Left] = true; StarlingGameSpriteWithTestGamePad.__keyDown[Keys.Right] = false; } else if (e.accelerationX < -0.05) { StarlingGameSpriteWithTestGamePad.__keyDown[Keys.Left] = false; StarlingGameSpriteWithTestGamePad.__keyDown[Keys.Right] = true; } else { StarlingGameSpriteWithTestGamePad.__keyDown[Keys.Left] = false; StarlingGameSpriteWithTestGamePad.__keyDown[Keys.Right] = false; } #endregion #region accelerationY if (e.accelerationY < 0.1) { StarlingGameSpriteWithTestGamePad.__keyDown[Keys.Up] = false; StarlingGameSpriteWithTestGamePad.__keyDown[Keys.Down] = false; } else if (e.accelerationY < 0.4) { StarlingGameSpriteWithTestGamePad.__keyDown[Keys.Up] = true; StarlingGameSpriteWithTestGamePad.__keyDown[Keys.Down] = false; } else if (e.accelerationY > 0.6) { StarlingGameSpriteWithTestGamePad.__keyDown[Keys.Up] = false; StarlingGameSpriteWithTestGamePad.__keyDown[Keys.Down] = true; } else { StarlingGameSpriteWithTestGamePad.__keyDown[Keys.Up] = false; StarlingGameSpriteWithTestGamePad.__keyDown[Keys.Down] = false; } #endregion }; a.setRequestedUpdateInterval(1000 / 60); } else { StarlingGameSpriteWithTestGamePad.__keyDown.InitializeConnection(WriteMode: false, ReadMode: true, text: text); //text.text = "no Accelerometer"; } } ); }
public MySprite1() { // http://forums.adobe.com/thread/986019 // wont run on AIR anymore? //TypeError: Error #1009: Cannot access a property or method of a null object reference. // at Main/frame1() var q = (WidescreenWidth - ContentWidth) / 2; var c = new Sprite(); c.graphics.beginFill(0); c.graphics.drawRect(0, 0, DefaultWidth, DefaultHeight); c.AttachTo(this); // TypeError: Error #1009: Cannot access a property or method of a null object reference. //at Main/frame1() //V:\web\IntegrationToSkyIsland\Assets\sky_island_10899.as(10): col: 9: Error: unable to resolve '/assets/IntegrationToSkyIsland/sky-island-10899.swf' for transcoding // [Embed(source = "/assets/IntegrationToSkyIsland/sky-island-10899.swf", mimeType = "application/x-shockwave-flash")] // ^ //V:\web\IntegrationToSkyIsland\Assets\sky_island_10899.as(10): col: 9: Error: Unable to transcode /assets/IntegrationToSkyIsland/sky-island-10899.swf. Sprite x = null; try { x = Assets.sky_island_10899.Source; x.AttachTo(this).MoveTo(q, 0); } catch { // can we skip? } #region buttons Action<Sprite, uint> bind = (s, keyCodeValue) => { s.click += e => { e.stopImmediatePropagation(); // a glitch? //this.stage.fullScreenSourceRect = new ScriptCoreLib.ActionScript.flash.geom.Rectangle( // 0, 0, DefaultWidth, DefaultHeight // ); //this.stage.SetFullscreen(true); }; s.mouseDown += e => { e.stopImmediatePropagation(); x.dispatchEvent( new KeyboardEvent(KeyboardEvent.KEY_DOWN, keyCodeValue: keyCodeValue /* left */ ) ); }; s.mouseUp += e => { e.stopImmediatePropagation(); x.dispatchEvent( new KeyboardEvent(KeyboardEvent.KEY_UP, keyCodeValue: keyCodeValue /* left */ ) ); }; }; new Sprite().With( GoLeft => { GoLeft.graphics.beginFill(0); GoLeft.graphics.drawRect(0, 0, q, DefaultHeight); GoLeft.alpha = 0.9; bind(GoLeft, 37); GoLeft.AttachTo(this); } ); new Sprite().With( GoRight => { GoRight.graphics.beginFill(0); GoRight.graphics.drawRect(WidescreenWidth - q, 0, q, DefaultHeight); GoRight.alpha = 0.9; bind(GoRight, 39); GoRight.AttachTo(this); } ); new Sprite().With( GoUp => { GoUp.graphics.beginFill(0); GoUp.graphics.drawRect(0, DefaultHeight - q, WidescreenWidth, q); GoUp.alpha = 0.05; bind(GoUp, 38); GoUp.AttachTo(this); } ); #endregion //var t = new TextField().AttachTo(this); //t.autoSize = TextFieldAutoSize.LEFT; #region Accelerometer - AIR? if (Accelerometer.isSupported) { a = new Accelerometer(); var ax = 0.0; var az = 0.0; a.update += e => { var wx = 0.15; var wz = 0.5; if (e.accelerationZ > wz) { if (az > wz) { // nop } else { x.dispatchEvent( new KeyboardEvent(KeyboardEvent.KEY_DOWN, keyCodeValue: 38 ) ); } } else { if (az > wz) { x.dispatchEvent( new KeyboardEvent(KeyboardEvent.KEY_UP, keyCodeValue: 38 ) ); } } if (e.accelerationX < -wx) { if (ax < -wx) { // nop } else { x.dispatchEvent( new KeyboardEvent(KeyboardEvent.KEY_DOWN, keyCodeValue: 39 ) ); } } else { if (ax < -wx) { x.dispatchEvent( new KeyboardEvent(KeyboardEvent.KEY_UP, keyCodeValue: 39 ) ); } } if (e.accelerationX > wx) { if (ax > wx) { // nop } else { x.dispatchEvent( new KeyboardEvent(KeyboardEvent.KEY_DOWN, keyCodeValue: 37 ) ); } } else { if (ax > wx) { x.dispatchEvent( new KeyboardEvent(KeyboardEvent.KEY_UP, keyCodeValue: 37 ) ); } } ax = e.accelerationX; az = e.accelerationZ; //t.text = "" + new //{ // //Multitouch.maxTouchPoints, // ax, // e.accelerationY, // e.accelerationZ //}; }; a.setRequestedUpdateInterval(1000 / 60); } #endregion }
public static void remove_update(Accelerometer that, Action<AccelerometerEvent> value) { CommonExtensions.RemoveDelegate(that, value, AccelerometerEvent.UPDATE); }
public static void remove_status(Accelerometer that, Action<StatusEvent> value) { CommonExtensions.RemoveDelegate(that, value, StatusEvent.STATUS); }
public ApplicationSprite() { Action<string, Action> Try = (ErrorText, Handler) => { try { Handler(); } catch { content.t2.Text = "error: " + ErrorText; } }; this.click += delegate { content.Background = Brushes.Black; this.stage.SetFullscreen(true); if (Accelerometer.isSupported) { //var a = new Accelerometer(); a = new Accelerometer(); content.t2.Text = "with Accelerometer!! before add update or status"; a.status += e => { // Note: On some devices, the accelerometer is always available. // On such devices, an Accelerometer object never dispatches a // status event. Try("status", delegate { content.t2.Text = "status: " + new { e.code, e.type, e.level }; } ); }; a.update += e => { Try("update", delegate { content.t2.Text = "with Accelerometer! at update"; content.Accelerate( e.accelerationX, e.accelerationY, e.accelerationZ ); } ); }; a.setRequestedUpdateInterval(1000 / 30); if (a.muted) { content.t2.Text = "with Accelerometer! after add update (muted)"; } else { content.t2.Text = "with Accelerometer! after add update (not muted)"; } } else { content.t2.Text = "no Accelerometer!!"; } }; this.InvokeWhenStageIsReady( delegate() { content.AttachToContainer(this); content.AutoSizeTo(this.stage); } ); }