/// <summary> /// Init /// </summary> internal void Init() { #if WINDOWS_PHONE accelSensor = new Accelerometer(); // Add the accelerometer event handler to the accelerometer sensor. accelSensor.ReadingChanged += new EventHandler<AccelerometerReadingEventArgs>(AccelerometerReadingChanged); // Start the accelerometer try { accelSensor.Start(); accelActive = true; } catch (AccelerometerFailedException e) { // the accelerometer couldn't be started. No fun! accelActive = false; } catch (UnauthorizedAccessException e) { // This exception is thrown in the emulator-which doesn't support an accelerometer. accelActive = false; } #endif }
public GameplayScreen(bool newGame) { this.newGame = newGame; tempp = new HighScore(); rezultati = new List<HighScore>(); isoHelper = new ISHelper(); typeFinish = false; temp = new List<HighScore>(); Scores = new HighScore(); GameplayHelper.updateGameTime = true; //foreach (HighScore kv in temp) //{ // Debug.WriteLine(kv.player + kv.score); //} Accelerometer = new Accelerometer(); if (Accelerometer.State == SensorState.Ready) { Accelerometer.CurrentValueChanged += (s, e) => { accelState = e; }; Accelerometer.Start(); } }
public Input() { if (CurrentGamePadState.Count == 0) { CurrentGamePadState.Add(PlayerIndex.One, GamePad.GetState(PlayerIndex.One)); CurrentGamePadState.Add(PlayerIndex.Two, GamePad.GetState(PlayerIndex.Two)); CurrentGamePadState.Add(PlayerIndex.Three, GamePad.GetState(PlayerIndex.Three)); CurrentGamePadState.Add(PlayerIndex.Four, GamePad.GetState(PlayerIndex.Four)); PreviousGamePadState.Add(PlayerIndex.One, GamePad.GetState(PlayerIndex.One)); PreviousGamePadState.Add(PlayerIndex.Two, GamePad.GetState(PlayerIndex.Two)); PreviousGamePadState.Add(PlayerIndex.Three, GamePad.GetState(PlayerIndex.Three)); PreviousGamePadState.Add(PlayerIndex.Four, GamePad.GetState(PlayerIndex.Four)); GamepadConnectionState.Add(PlayerIndex.One, CurrentGamePadState[PlayerIndex.One].IsConnected); GamepadConnectionState.Add(PlayerIndex.Two, CurrentGamePadState[PlayerIndex.Two].IsConnected); GamepadConnectionState.Add(PlayerIndex.Three, CurrentGamePadState[PlayerIndex.Three].IsConnected); GamepadConnectionState.Add(PlayerIndex.Four, CurrentGamePadState[PlayerIndex.Four].IsConnected); } if (accelerometerSensor == null) { accelerometerSensor = new Accelerometer(); accelerometerSensor.ReadingChanged += new EventHandler<AccelerometerReadingEventArgs>(AccelerometerReadingChanged); } }
/// <summary> /// Allows the game component to perform any initialization it needs to before starting /// to run. This is where it can query for any required services and load content. /// </summary> public override void Initialize() { accelSensor = new Accelerometer(); accelSensor.Start(); accelSensor.ReadingChanged += accelSensor_ReadingChanged; //floorToysB = new List<BasicComponent>(); //floorToysI = new List<BasicComponent>(); //floorToys = new List<BasicComponent>(); indicatorRct = new Rectangle(470, 145, 200, 200); spriteBatch = new SpriteBatch(gameMS.GraphicsDevice); mamaRct = new Rectangle(345, 10, 245, 470); mannRect = new Rectangle(545, 40, 185, 370); mannRect2 = new Rectangle(550, 40, 180, 370); mannRect3 = new Rectangle(515, 40, 215, 370); mannRect4 = new Rectangle(555, 100, 180, 320); crayonRect = new Rectangle(0, 430, 200, 70); basketLeftRect = new Rectangle(0, 320, 250, 150); basketOpeningRct = new Rectangle(25, 305, 250, 150); bskHit = new Rectangle(35, 400, 180, 80); roomRect = new Rectangle(-30, -20, 900, 600); guiBubbleRct = new Rectangle(170, 55, 440, 270); //default toy størrelse defaultRect = new Rectangle(510, 200, 100, 90); rightColor = new Color(); wrongColor = new Color(); rectangles[0] = new Rectangle(510, 190, 120, 90); //sportscar rectangles[1] = new Rectangle(530, 160, 130, 120); //plane rectangles[2] = new Rectangle(510, 180, 130, 90);//train rectangles[3] = new Rectangle(510, 200, 120, 90); //tractor rectangles[4] = new Rectangle(510, 180, 120, 120); //digger rectangles[5] = new Rectangle(510, 160, 130, 130); //dino rectangles[6] = new Rectangle(505, 170, 120, 120); //baby rectangles[7] = new Rectangle(505, 165, 120, 120); //soldier rectangles[8] = new Rectangle(505, 170, 120, 120);//actionfigure rectangles[9] = new Rectangle(505, 190, 120, 120);//teddy rectangles[10] = new Rectangle(515, 205, 70, 70); //block rectangles[11] = new Rectangle(505, 170, 100, 100);//ball rectangles[12] = new Rectangle(520, 140, 100, 150); //balloon rectangles[13] = new Rectangle(515, 160, 130, 120); //pad rectangles[14] = new Rectangle(510, 160, 120, 120); //horse rectangles[15] = new Rectangle(510, 190, 120, 90); //racecar rectangles[16] = new Rectangle(510, 190, 150, 120);//dumper initPauseScreen(); numberOfTurns = rectangles.Length; rnd = new Random(); base.Initialize(); }
public override void Initialize() { base.Initialize(); Accelerometer = new Accelerometer(); if (Accelerometer.State == SensorState.Ready) { Accelerometer.ReadingChanged += AccelerometerReadingChanged; Accelerometer.Start(); } }
protected override void Initialize() { Accelerometer accelerometer = new Accelerometer(); accelerometer.ReadingChanged += OnAccelerometerReadingChanged; try { accelerometer.Start(); } catch { } base.Initialize(); }
public UserControlledSprite(Texture2D textureImage, Vector2 position, Point frameSize, int collisionOffset, Point currentFrame, Point sheetSize, Vector2 speed, int millisecondsPerFrame) : base(textureImage, position, frameSize, collisionOffset, currentFrame, sheetSize, speed, millisecondsPerFrame, null, 0) { accelerometer = new Accelerometer(); accelerometer.TimeBetweenUpdates = TimeSpan.FromMilliseconds(20); accelerometer.CurrentValueChanged += new EventHandler<SensorReadingEventArgs<AccelerometerReading>>(accelerometer_CurrentValueChanged); accelerometer.Start(); }
static InputManager() { Accelerometer = new Accelerometer(); if (Accelerometer.State == SensorState.Ready) { Accelerometer.CurrentValueChanged += (o, e) => AccelerometerReading = e.SensorReading.Acceleration; Accelerometer.Start(); } TouchPanel.EnabledGestures = GestureType.Tap; }
/// <summary> /// Allows the game component to perform any initialization it needs to before starting /// to run. This is where it can query for any required services and load content. /// </summary> public override void Initialize() { initPauseScreen(); accelSensor = new Accelerometer(); accelSensor.Start(); accelSensor.ReadingChanged += accelSensor_ReadingChanged; // TODO: Add your initialization code here spriteBatch = new SpriteBatch(gameMS.GraphicsDevice); mannRect = new Rectangle(345, 10, 185, 370); mannRect2 = new Rectangle(353, 10, 175, 370); mannRect3 = new Rectangle(315, 10, 215, 370); indicatorRct = new Rectangle(270, 850, 200, 200); guiBubbleRct = new Rectangle(120, 45, 300, 200); roomRect = new Rectangle(-170, -80, 1200, 620); //default toy størrelse defaultRect = new Rectangle(310, 200, 100, 90); rectangles[0] = new Rectangle(310, 170, 120, 90); //sportscar rectangles[1] = new Rectangle(305, 170, 130, 120); //plane rectangles[2] = new Rectangle(310, 165, 130, 90);//train rectangles[3] = new Rectangle(297, 192, 120, 90); //tractor rectangles[4] = new Rectangle(280, 150, 120, 120); //digger rectangles[5] = new Rectangle(310, 140, 120, 120); //dino rectangles[6] = new Rectangle(295, 160, 120, 120); //baby rectangles[7] = new Rectangle(296, 147, 120, 120); //soldier rectangles[8] = new Rectangle(295, 180, 100, 90);//actionfigure rectangles[9] = new Rectangle(297, 160, 120, 120);//teddy rectangles[10] = new Rectangle(310, 195, 70, 70); //block rectangles[11] = new Rectangle(310, 165, 100, 100);//ball rectangles[12] = new Rectangle(320, 110, 100, 150); //balloon rectangles[13] = new Rectangle(305, 155, 110, 100); //pad rectangles[14] = new Rectangle(300, 145, 120, 120); //horse rectangles[15] = new Rectangle(305, 190, 120, 90); //racecar rectangles[16] = new Rectangle(280, 140, 150, 120);//dumper rnd = new Random(); numberOfTurns = rectangles.Length; basketLeftRect = new Rectangle(0, 340, 240, 140); basketRightRect = new Rectangle(550, 340, 240, 140); basketOpeningLRct = new Rectangle(15, 320, 245, 150); basketOpeningRRct = new Rectangle(565, 320, 245, 150); bskHitL = new Rectangle(35, 410, 180, 80); bskHitR = new Rectangle(585, 410, 180, 80); base.Initialize(); }
/// <summary> /// Allows the game component to perform any initialization it needs to before starting /// to run. This is where it can query for any required services and load content. /// </summary> public override void Initialize() { PhoneApplicationService.Current.Deactivated += GameDeactivated; //default toy pos and size settings initPauseScreen(); accelSensor = new Accelerometer(); accelSensor.Start(); accelSensor.ReadingChanged += accelSensor_ReadingChanged; // TODO: Add your initialization code here spriteBatch = new SpriteBatch(gameMS.GraphicsDevice); mannRect = new Rectangle(555, 80, 185, 320); mannRect2 = new Rectangle(560, 80, 180, 320); mannRect3 = new Rectangle(525, 80, 215, 320); guiBubbleRct = new Rectangle(210,10, 400, 250); basketLeftRect = new Rectangle(0, 320, 250, 150); basketOpeningRct = new Rectangle(25, 305, 250, 150); bskHit = new Rectangle(35, 400, 180, 80); indicatorRct = new Rectangle(470, 145, 200, 200); roomRect = new Rectangle(-170, -20, 1140, 620); //default toy størrelse defaultRect = new Rectangle(510, 195, 120, 90); rectangles[0] = new Rectangle(510, 195, 120, 90); //sportscar rectangles[1] = new Rectangle(530, 205, 130, 120); //plane rectangles[2] = new Rectangle(510, 210, 130, 90);//train rectangles[3] = new Rectangle(510, 220, 120, 90); //tractor rectangles[4] = new Rectangle(515, 180, 120, 120); //digger rectangles[5] = new Rectangle(510, 180, 130, 130); //dino rectangles[6] = new Rectangle(505, 180, 120, 120); //baby rectangles[7] = new Rectangle(505, 160, 120, 120); //soldier rectangles[8] = new Rectangle(508, 190, 100, 90);//actionfigure rectangles[9] = new Rectangle(505, 195, 120, 120);//teddy rectangles[10] = new Rectangle(530, 210, 80, 80); //block rectangles[11] = new Rectangle(515, 210, 80, 80);//ball rectangles[12] = new Rectangle(525, 150, 105, 150); //balloon rectangles[13] = new Rectangle(510, 190, 130, 130);//horse rectangles[14] = new Rectangle(520, 185, 110, 110);//pad rectangles[15] = new Rectangle(510, 200, 130, 100);//racecar rectangles[16] = new Rectangle(510, 190, 150, 120);//dumper rnd = new Random(); numberOfTurns = rectangles.Length - 1; base.Initialize(); }
public GameplayScreen() { TransitionOnTime = TimeSpan.FromSeconds(0.0); TransitionOffTime = TimeSpan.FromSeconds(0.0); Accelerometer = new Accelerometer(); if (Accelerometer.State == SensorState.Ready) { Accelerometer.CurrentValueChanged += (s, e) => { accelState = e; }; Accelerometer.Start(); } }
/// <summary> /// ������Ϸ�ڿ�ʼ����֮ǰִ����������κγ�ʼ���� /// ��Ϸ�ܹ��ڴ�ʱ��ѯ�κ�����������κη�ͼ�� /// ��ص����ݡ����� base.Initialize ��ö��������� /// ��������г�ʼ���� /// </summary> protected override void Initialize() { // TODO: �ڴ˴���ӳ�ʼ���� Accelerometer accer = new Accelerometer(); accer.CurrentValueChanged += (s, e) => { lock (acceLock) { acce = 0.5f * oldAcce + 0.5f * e.SensorReading.Acceleration; oldAcce = acce; } }; accer.Start(); base.Initialize(); }
protected override void Initialize() { base.Initialize(); camPos = new Vector3(0f, -250f, 300.0f); camTarget = new Vector3(0, -100, 0); float aspectRatio = 640.0f / 480.0f; projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(80F), aspectRatio, 10F, 1000F); view = Matrix.CreateLookAt(camPos, camTarget, Vector3.Up); rotations = new Vector3[MAX_PLAYERS]; translations = new Vector3[MAX_PLAYERS]; mX = new Matrix[MAX_PLAYERS]; mY = new Matrix[MAX_PLAYERS]; mZ = new Matrix[MAX_PLAYERS]; mT = new Matrix[MAX_PLAYERS]; for (int i = 0; i < MAX_PLAYERS; i++) { rotations[i] = new Vector3(); translations[i] = new Vector3(); } progress = new float[] { 0, .2F, .4F, .6F, .8F }; #if(WINDOWS_PHONE) graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft; TouchPanel.EnabledGestures = GestureType.Tap | GestureType.HorizontalDrag | GestureType.DragComplete; accelSensor = new Accelerometer(); accelSensor.CurrentValueChanged += new EventHandler<SensorReadingEventArgs<AccelerometerReading>>(accelSensor_CurrentValueChanged); try { accelSensor.Start(); } catch (AccelerometerFailedException) { } catch (UnauthorizedAccessException) { } #endif }
public Player() { this.Position = new Vector2(125, 200); this.Color = Color.White; this.Rotation = 0.0f; this.IsAlive = true; this.Hitpoints = maxHealth; this.Ammo = maxAmmo; this.AvailibleBombs = maxBombs; healthBar = new Bar(Color.Red, new Vector2(25, 10)); ammoBar = new Bar(Color.Gold, new Vector2(25, 20)); score = new ScoreHandler(); shootButton = new Button(ButtonType.SHOOT, shootButtonPosition); bombButton = new Button(ButtonType.BOMB, bombButtonPosition); accelerometer = new Accelerometer(); accelerometer.CurrentValueChanged += new EventHandler<SensorReadingEventArgs<AccelerometerReading>>(accelerometer_CurrentValueChanged); this.Init(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { //ACCELEROMETER accel = new Accelerometer(); accel.CurrentValueChanged += new EventHandler<SensorReadingEventArgs<AccelerometerReading>>(AccelChanged); //GAME VARS displayHeight = GraphicsDevice.Viewport.Height; displayWidth = GraphicsDevice.Viewport.Width; CMenu.displayHeight = displayHeight; CMenu.displayWidth = displayWidth; CGameItem.displayHeight = displayHeight; CGameItem.displayWidth = displayWidth; TouchCollector = new CTouchCollector(); base.Initialize(); }
private void initializeAccelerometer() { // D! Port to accelerometer. Fix the gyro + acce next time. accelSensor = new Accelerometer(); accelSensor.CurrentValueChanged += new EventHandler<SensorReadingEventArgs<AccelerometerReading>>(AccelerometerReadingChanged); accelSensor.Start(); }
/// <summary> /// 允许游戏在开始运行之前执行其所需的任何初始化。 /// 游戏能够在此时查询任何所需服务并加载任何非图形 /// 相关的内容。调用 base.Initialize 将枚举所有组件 /// 并对其进行初始化。 /// </summary> public void initialize() { // TODO: 在此处添加初始化逻辑 //open isolated storage, and load data from the savefile if it exists. #if WINDOWS_PHONE using (IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication()) #else using (IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForDomain()) #endif { if (savegameStorage.FileExists("fish_amount")) { using (IsolatedStorageFileStream fs = savegameStorage.OpenFile("fish_amount", System.IO.FileMode.Open, System.IO.FileAccess.Read)) { if (fs != null) { //Reload the saved high-score data. byte[] saveBytes = new byte[4]; int count = fs.Read(saveBytes, 0, 4); if (count > 0) { this.fishCount = System.BitConverter.ToInt32(saveBytes, 0); } } } } } if (!Accelerometer.IsSupported) {//检测设备是否支持重力感应,不支持则抛出异常 throw new Exception("Device does not support accelerometer!"); } if (accelerometer == null) {//初始化accelerometer accelerometer = new Accelerometer(); //设置感应器检测间隔 单位是毫秒 (The default value is 2 milliseconds.[MSDN]) accelerometer.TimeBetweenUpdates = TimeSpan.FromMilliseconds(20); //[他人理解] 添加监听事件的回调函数 (accelerometer_CurrentValueChanged), // 即每次检测的到的结果交给此方法进行处理(本例中用来更新四个方向指示属性) accelerometer.ReadingChanged += new EventHandler<AccelerometerReadingEventArgs>(AccelerometerReadingChanged); } try { //开始感应器检测 accelerometer.Start(); } catch (InvalidOperationException ex) { throw new Exception("Unable to start accelerometer", ex); }s }
protected override void UnloadContent() { loadScreenDraw(loadScreen, new Vector2(-90, -20)); accelSensor = null; indicator = null; basketLeft = null; basketOpeningLeft = null; basketOpeningLeft = null; basketRight = null; mama = null; boy = null; toy = null; talkingBubble = null; toysCollected = null; for (int r = 0; r < rectangles.Count; r++) rectangles[r] = Rectangle.Empty; Content.Unload(); Components.Clear(); rectangles.Clear(); for (int txt = 0; txt < textures.Count; txt++) { textures[txt] = null; } rectangles.Clear(); textures.Clear(); GC.Collect(); GC.WaitForPendingFinalizers(); string test = GC.GetTotalMemory(true).ToString(); Debug.WriteLine(test); base.UnloadContent(); }
private void initializeAccelerometer() { accelSensor = new Accelerometer(); accelSensor.Start(); }
protected override void Initialize() { accel = new Accelerometer(); accel.Start(); base.Initialize(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here Plasmacore.configure( Content, GraphicsDevice, PlasmacoreSettings.display_width, PlasmacoreSettings.display_height ); Accelerometer accelerometer = new Accelerometer(); try { accelerometer.Start(); accelerometer.ReadingChanged += new EventHandler<AccelerometerReadingEventArgs>( AccelerometerReadingChanged); } catch (Exception) { } base.Initialize(); }
public Game(Game1 game) { CoefBonus = 1; RageMetter_tmp = 0; _origin = game; RageMetter = 1; RageMetter_flag = 1; _TouchFlag = 0; _ValueTouch = 0; _selectFlag = 0; _moveTouch = false; _zoom = false; Zoom = new Vector2(0, 0); _central = new Potatoe(0, 0, this); BulletList = new List<Shoot>(); BulletTexture = new Dictionary<EBulletType, Texture2D>(); TypeTexture = new Dictionary<EType, Texture2D>(); MobTexture = new Dictionary<EMobType, Texture2D>(); accSensor = new Accelerometer(); accSensor.ReadingChanged += new EventHandler<AccelerometerReadingEventArgs>(AccelerometerReadingChanged); startAccSensor(); MapTexture = new Dictionary<EMapTexture, Texture2D>(); LevelColor = new Dictionary<int, Color>(); LevelTexture = new Dictionary<int, Texture2D>(); FrameSize = new Point(40, 40); BulletFrameSize = new Point(20, 20); mobSpawnTime = TimeSpan.FromSeconds(1.0f); previousSpawnTime = TimeSpan.Zero; }
public PongGameScreen() { TransitionOnTime = TimeSpan.FromSeconds(0.0); TransitionOffTime = TimeSpan.FromSeconds(0.0); screenLeftBound = 0; screenRightBound = 480; screenTopBound = 0; screenBottomBound = 800; Accelerometer = new Accelerometer(); if (Accelerometer.State == SensorState.Ready) { Accelerometer.ReadingChanged += (s, e) => { accelState = e; }; Accelerometer.Start(); } lastAccelInput = 0f; bottomPaddleTouch = new TouchLocation(); bottomPaddleTouchId = -1; lastTouchInput = new List<TouchLocation>(); lastKeyInput = new List<Keys>(); bottomPaddle = new DefaultPaddle(); topPaddle = new DefaultPaddle(); }
/// <summary> /// 允许游戏在开始运行之前执行其所需的任何初始化。 /// 游戏能够在此时查询任何所需服务并加载任何非图形 /// 相关的内容。调用 base.Initialize 将枚举所有组件 /// 并对其进行初始化。 /// </summary> protected override void Initialize() { // TODO: 在此处添加初始化逻辑 acce = new Accelerometer(); acce.CurrentValueChanged+= new EventHandler<SensorReadingEventArgs<AccelerometerReading>>(onAcceReadingChanged); acce.Start(); base.Initialize(); }
public GameplayScreen() { random = new Random(); worldBounds = new Rectangle(0, 0, (int)screenWidth, (int)screenHeight); gameOver = true; TransitionOnTime = TimeSpan.FromSeconds(0.0); TransitionOffTime = TimeSpan.FromSeconds(0.0); player = new Player(); playerBullets = new List<Bullet>(); aliens = new List<Alien>(); alienBullets = new List<Bullet>(); Accelerometer = new Accelerometer(); if (Accelerometer.State == SensorState.Ready) { Accelerometer.ReadingChanged += (s, e) => { accelState = e; }; Accelerometer.Start(); } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); map = Content.Load<Map>("Maps\\simpleTileMap"); // tIDE map load //foreach (Layer l in map.Layers) //{ // if (l.Properties["CollisionLayer"]) // { // //Add to farser physics // //l. // } //} int fooProp = map.Layers[0].Properties["foo"]; Layer col = map.GetLayer("CollisionLayer"); //for(int i = 0; i < col.Tiles;) var viewport = this.GraphicsDevice.Viewport; Texture2D playerTexture = Content.Load<Texture2D>("player");//todo: add player texture player = new Sprite(playerTexture); world = new World(Vector2.Zero);//0 gravity world playerBody = BodyFactory.CreateBody(world); CircleShape playerShape = new CircleShape(ConvertUnits.ToSimUnits(playerTexture.Bounds.Width / 2), 5f); Fixture playerFixture = playerBody.CreateFixture(playerShape); playerBody.BodyType = BodyType.Dynamic; playerBody.Position = ConvertUnits.ToSimUnits(new Vector2(450, 0)); //playerBody.Restitution = 0.8f; accelerometerInput = new Vector2(); if (accelerometer == null) { accelerometer = new Accelerometer(); accelerometer.TimeBetweenUpdates = TimeSpan.FromMilliseconds(20); accelerometer.CurrentValueChanged += (s, e) => { accelerometerInput.X = e.SensorReading.Acceleration.X; accelerometerInput.Y = -e.SensorReading.Acceleration.Y; }; accelerometer.Start(); } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here // Accelerometer accelerometer = new Accelerometer(); accelerometer.CurrentValueChanged += new EventHandler<SensorReadingEventArgs<AccelerometerReading>>(AccelerometerCurrentValueChanged); accelerometer.Start(); base.Initialize(); }
/// <summary> /// 允许游戏在开始运行之前执行其所需的任何初始化。 /// 游戏能够在此时查询任何所需服务并加载任何非图形 /// 相关的内容。调用 base.Initialize 将枚举所有组件 /// 并对其进行初始化。 /// </summary> protected override void Initialize() { // TODO: 在此处添加初始化逻辑 accelerometer = new Accelerometer(); accelerometer.CurrentValueChanged += accelerometer_CurrentValueChanged; accelerometer.Start(); Viewport viewport = graphics.GraphicsDevice.Viewport; ringsPosition = new Vector2((viewport.Width - ringsFrameSize.X) / 2, (viewport.Height - ringsFrameSize.Y) / 2); base.Initialize(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { player = new Player(); // Set a constant player move speed playerMoveSpeed = 4.0f; //Enable the FreeDrag gesture. TouchPanel.EnabledGestures = GestureType.FreeDrag; bgLayer1 = new ParallaxingBackground(); bgLayer2 = new ParallaxingBackground(); // Initialize the enemies list enemies = new List<Enemy>(); // Set the time keepers to zero previousSpawnTime = TimeSpan.Zero; // Used to determine how fast enemy respawns enemySpawnTime = TimeSpan.FromSeconds(1.0f); // Initialize our random number generator random = new Random(); projectiles = new List<Projectile>(); // Set the laser to fire every quarter second fireTime = TimeSpan.FromSeconds(.15f); explosions = new List<Animation>(); //Set player's score to zero score = 0; #if WINDOWS_PHONE Accelerometer accelSensor = new Accelerometer(); // Start the accelerometer try { accelSensor.Start(); accelActive = true; accelSensor.ReadingChanged += new EventHandler<AccelerometerReadingEventArgs>(accel_ReadingChanged); } catch (AccelerometerFailedException e) { // the accelerometer couldn't be started. No fun! accelActive = false; } catch (UnauthorizedAccessException e) { // This exception is thrown in the emulator-which doesn't support an accelerometer. accelActive = false; } #endif // TODO: Add your initialization logic here base.Initialize(); }
private void StartAccelerometer() { //throw new NotImplementedException(); if (accelerometer == null) { // Instantiate the accelerometer. accelerometer = new Accelerometer(); accelerometer.ReadingChanged += new EventHandler<AccelerometerReadingEventArgs>(accelerometer_ReadingChanged); } try { accelerometer.Start(); } catch (InvalidOperationException) { // Accelerometer failed to start //this.Exit(); } }