Jypeli  5
The simple game programming library
Touch.cs
Siirry tämän tiedoston dokumentaatioon.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using Microsoft.Xna.Framework;
6 
7 #if WINDOWS_PHONE
8 using Microsoft.Xna.Framework.Input.Touch;
9 #endif
10 
11 namespace Jypeli.WP7
12 {
16  public class Touch
17  {
18  protected Vector2 _previousPosition;
19  protected Vector2 _position;
20  protected Vector2 _movement;
21 
25  public int Id { get; private set; }
26 
30  public Vector PositionOnScreen
31  {
32  get
33  {
34  return Game.Screen.FromXnaScreenCoordinates( _position );
35  }
36  }
37 
41  public Vector PositionOnWorld
42  {
43  get
44  {
45  return Game.Instance.Camera.ScreenToWorld( PositionOnScreen );
46  }
47  }
48 
52  public Vector MovementOnScreen
53  {
54  get
55  {
56  return new Vector( (double)_movement.X, -(double)_movement.Y );
57  }
58  }
59 
63  public Vector MovementOnWorld
64  {
65  get
66  {
67  return MovementOnScreen / Game.Instance.Camera.ZoomFactor;
68  }
69  }
70 
71 #if WINDOWS_PHONE
72  public TouchLocationState State { get; internal set; }
73 
74  internal Touch( Vector2 position, Vector2 movement )
75  {
76  this._position = position;
77  this._movement = movement;
78  }
79 
80  internal Touch( int id, Vector2 initialPosition, TouchLocationState initialState )
81  {
82  this.Id = id;
83  this._position = this._previousPosition = initialPosition;
84  this._movement = Vector2.Zero;
85  this.State = initialState;
86  }
87 
88  internal void Update( Vector2 newPosition, TouchLocationState newState )
89  {
90  _previousPosition = _position;
91  _position = newPosition;
92  _movement = newPosition - _previousPosition;
93  State = newState;
94  }
95 #endif
96 
97  }
98 }
Vector2 _position
Definition: Touch.cs:19
double ZoomFactor
Kameran zoomauskerroin. Oletuksena 1.0. Mitä suurempi zoomauskerroin, sitä lähempänä kamera on (esim ...
Definition: Camera.cs:99
Kosketuspaneelin kosketus.
Definition: Touch.cs:16
static Game Instance
Definition: Game.cs:149
static ScreenView Screen
Näytön dimensiot, eli koko ja reunat.
Definition: Game.cs:194
Peliluokka reaaliaikaisille peleille.
Definition: DebugScreen.cs:10
Vector2 _movement
Definition: Touch.cs:20
Camera Camera
Kamera, joka näyttää ruudulla näkyvän osan kentästä. Kameraa voidaan siirtää, zoomata tai asettaa seu...
Definition: Game.cs:166
2D-vektori.
Definition: Vector.cs:56
Vector ScreenToWorld(Vector point)
Muuntaa annetun pisteen ruutukoordinaateista maailmankoordinaatteihin.
Definition: Camera.cs:168
Vector2 _previousPosition
Definition: Touch.cs:18