In this recipe we will look into how to use the accelerometer and gyroscope.
Open PSM Studio and create a new project, adding references for GameEngine2D
and GameEngine2D.Base
. The complete code for this recipe is available at Ch2_Example5
.
This example will not run in the simulator. Some Android based devices may not support the gyro, so AngularVelocity
may not be available.
Open AppMain.cs
and enter the following code:
using System; using System.Collections.Generic; using Sce.PlayStation.Core; using Sce.PlayStation.Core.Environment; using Sce.PlayStation.Core.Graphics; using Sce.PlayStation.Core.Input; using Sce.PlayStation.HighLevel.GameEngine2D; using Sce.PlayStation.HighLevel.GameEngine2D.Base; namespace Ch2_Example5 { public class AppMain { public static void Main (string[] args) { Director.Initialize(); Scene scene = new Scene(); scene.Camera.SetViewFromViewport(); float screenWidth = Director...