public void Initialize(asgCameraMode mode, asgPlayerActor player, float cameraForce, Vector2 targetOffset) { cameraMode = mode; this.cameraForce = cameraForce; if (gxtDisplayManager.SingletonIsInitialized) { gxtDisplayManager.Singleton.resolutionChanged += OnResolutionChanged; } gxtOBB tmp = Camera.GetViewOBB(); cameraSafeZone = new gxtOBB(tmp.Position, tmp.Extents * 0.8f, tmp.Rotation); if (gxtDisplayManager.SingletonIsInitialized) { gxtDisplayManager.Singleton.resolutionChanged += OnResolutionChanged; } // cameraSpeed is in screen space cameraSpeed = 3.0f; cameraBody = new gxtRigidBody(); cameraBody.MotionType = gxtRigidyBodyMotion.DYNAMIC; cameraBody.AngularDamping = 1.0f; cameraBody.Damping = 1.0f; cameraBody.IgnoreGravity = true; cameraBody.Mass = 2.0f; cameraBody.CanSleep = false; cameraBody.Awake = true; player.World.AddRigidBody(cameraBody); this.player = player; this.offset = targetOffset; }
public override void Update(GameTime gameTime) { if (!Enabled) return; gxtGamepad gp = gxtGamepadManager.Singleton.GetGamepad(PlayerIndex.One); gxtKeyboard kb = gxtKeyboardManager.Singleton.GetKeyboard(); if (kb.GetState(Keys.F1) == gxtControlState.FIRST_PRESSED) { if (cameraMode == asgCameraMode.AUTONOMOUS) cameraMode = asgCameraMode.PLAYER_CONTROLLED; else cameraMode = asgCameraMode.AUTONOMOUS; } if (cameraMode == asgCameraMode.AUTONOMOUS) { // we'll be naive for the time being // just set the position to the player + offset Camera.Position = (player.Position + offset) * gxtPhysicsWorld.PHYSICS_SCALE; } else { float dt = (float)gameTime.ElapsedGameTime.TotalSeconds; // IMPORTANT -- REVERSED if (!gp.IsConnected) { ProcessGamepad(gp, dt); } else { ProcessKeyboard(kb, dt); } //Camera.TranslateLocal(gp.AdjLStick() * cameraSpeed * dt); //gxtLog.WriteLineV(gxtVerbosityLevel.WARNING, "The camera mode: {0} is not yet supported by this controller", cameraMode.ToString()); } }