TouchPanel
class from the Xna.Framework.Input.Touch.
Supports gestures, and the combined interaction with the mouse. In the simplest case, in order to find out whether there is a click on the screen, it is enough to call the GetState()
method which will return the list of points to which the touch is currently performed: foreach (TouchLocation location in TouchPanel.GetState()) { switch (location.State) { case TouchLocationState.Moved: // location.Position.X; // location.Position.Y; // location.Pressure // location.Id break; case TouchLocationState.Pressed: break; case TouchLocationState.Released: break; case TouchLocationState.Invalid: break; } }
TouchLocation
object contains data on the type, coordinates of the touch, its sequence number (up to five simultaneous points are supported as standard) and the force of pressing.Update()
method (before calling Draw
). At the same time, the InputState
class remembers the previous state of keystrokes. Additionally, direct player status is used to control the player. These standard handlers are required to be modified.Assets/GameContent
. In principle, we do not even need to create an XNB file, the content subsystem in MonoGame can read PNG files directly.LoadContent()
method: arrowkeys_texture = Content.Load<Texture2D>(@"transparent_arrow_keys");
Draw()
SpriteBatch.Begin(); SpriteBatch.Draw(arrowkeys_texture, drawPos, new Color(0, 0, 0)); SpriteBatch.End();
TouchLocationState.Moved
InputState
class.AddTouchKey(Keys key, Rectangle rect)
coordinate associated with the key will be specified, and in addition to polling the keyboard status, the UpdateTouchKeys()
method will also be called internal bool UpdateTouchPos(Dictionary<Keys, bool> key_states ) { bool touched = false; foreach (Keys key in _touchKeys.Keys) key_states.Add(key,false); foreach (TouchLocation location in TouchPanel.GetState()) { touched = true; foreach (var k in _touchKeys.Keys) { if (location.State == TouchLocationState.Moved) { if (_touchKeys[k].Contains((int)location.Position.X, (int)location.Position.Y)) { key_states[k] = true; } } } } return touched; }
IsKeyDown()
and IsKeyUp()
methods IsKeyDown()
public bool IsKeyDown(Keys key) { if (touchKeys.ContainsKey(key) && isTouched) return touchKeys[key]; else return orig_key_state.IsKeyDown(key); }
Input.AddTouchKey(Keys.Down, hitPosDown); Input.AddTouchKey(Keys.Up, hitPosUp); Input.AddTouchKey(Keys.Left, hitPosLeft); Input.AddTouchKey(Keys.Right, hitPosRight); Input.Update();
protected override void Initialize() { base.Initialize(); SettingsPane.GetForCurrentView().CommandsRequested += PaneRequest; } void PaneRequest(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args) { UICommandInvokedHandler handler = new UICommandInvokedHandler(onPrivacyPolicyCommand); var privPolicyCmd = new SettingsCommand("PrivacyPolicyId", "Privacy Policy", handler); args.Request.ApplicationCommands.Add(privPolicyCmd); } void onPrivacyPolicyCommand(IUICommand command) { Launcher.LaunchUriAsync(new Uri("http://wincommunity.ru/baller/privacy.html")); }
Source: https://habr.com/ru/post/167815/
All Articles