Jypeli 10
The simple game programming library
Device.cs
Siirry tämän tiedoston dokumentaatioon.
1#region MIT License
2/*
3 * Copyright (c) 2009 University of Jyväskylä, Department of Mathematical
4 * Information Technology.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24#endregion
25
26/*
27 * Authors: Tero Jäntti, Tomi Karppinen
28 */
29
30
31namespace Jypeli.Devices
32{
36 public class Device
37 {
40
44 public Accelerometer Accelerometer { get; protected set; }
45
49 public FileManager Storage { get; protected set; }
50
54 public virtual bool IsMobileDevice
55 {
56 get { return false; }
57 }
58
62 public virtual bool IsPhone
63 {
64 get { return false; }
65 }
66
71 {
72 get { return _displayResolution; }
73 set
74 {
75 if ( _displayResolution == value )
76 return;
77
78 _displayResolution = value;
79 if ( Game.Instance != null && Game.Screen != null ) ResetScreen();
80 }
81 }
82
87 {
88 get { return _displayOrientation; }
89 set
90 {
91 if ( _displayOrientation == value )
92 return;
93
94 _displayOrientation = value;
95 //Game.Instance.Accelerometer.DisplayOrientation = value;
96 if ( Game.Instance != null && Game.Screen != null ) UpdateScreen();
97 }
98 }
99
103 protected Device()
104 {
105 // Initialize components as dummy ones if they're not initialized otherwise
106 if (this.Accelerometer == null)
108 }
109
110 internal static Device Create()
111 {
112#if DESKTOP
113 return new ComputerDevice();
114#elif ANDROID
115 return new Jypeli.Android.AndroidDevice();
116#elif WINDOWS_PHONE81
117 return new WindowsPhone81Device();
118#elif WINDOWS_UAP
119 return new WindowsUniversalDevice();
120#elif WINRT
121 return new Windows8Device();
122#else
123 return new Device();
124#endif
125 }
126
131 public virtual void Vibrate( int milliSeconds )
132 {
133 }
134
138 public virtual void StopVibrating()
139 {
140 }
141
145 protected virtual void UpdateScreen()
146 {
147 Vector defaultSize = Game.Screen.ViewportSize;
148 Vector defaultScale = Vector.Diagonal;
149
151 {
152 defaultSize = new Vector( 400, 240 );
153 defaultScale = new Vector( Game.Screen.ViewportSize.X / defaultSize.X, Game.Screen.ViewportSize.Y / defaultSize.Y );
154 }
155
157 {
158 Game.Screen.Size = defaultSize.Transpose();
159 Game.Screen.Scale = defaultScale.Transpose();
161 }
162 else
163 {
164 Game.Screen.Size = defaultSize;
165 Game.Screen.Scale = defaultScale;
167 }
168 }
169
170 internal virtual void ResetScreen()
171 {
172 }
173 }
174}
Fyysinen laite, joka on tietokone
Fyysinen laite.
Definition: Device.cs:37
virtual void Vibrate(int milliSeconds)
Värisyttää puhelinta.
Definition: Device.cs:131
DisplayResolution _displayResolution
Definition: Device.cs:39
Device()
Fyysinen laite
Definition: Device.cs:103
FileManager Storage
Tiedostojen säilytyspaikka.
Definition: Device.cs:49
virtual bool IsPhone
Onko laite puhelin.
Definition: Device.cs:63
static Device Create()
Definition: Device.cs:110
DisplayOrientation _displayOrientation
Definition: Device.cs:38
virtual bool IsMobileDevice
Onko laite mobiililaite.
Definition: Device.cs:55
virtual void StopVibrating()
Lopettaa puhelimen värinän.
Definition: Device.cs:138
virtual void ResetScreen()
Definition: Device.cs:170
virtual void UpdateScreen()
Päivittää näytön koon ja asemoinnin
Definition: Device.cs:145
static DisplayOrientation Landscape
Vaakasuuntainen.
static DisplayOrientation PortraitInverse
Pystysuuntainen, ylösalaisin käännetty.
static DisplayOrientation LandscapeRight
Vaakasuuntainen, oikealle käännetty.
static DisplayOrientation Portrait
Pystysuuntainen.
Mobiililaitteiden resoluutiovaihtoehdot
static readonly DisplayResolution Small
Pieni tarkkuus (WVGA, 400 x 240). WP7-yhteensopivuustila, ei varsinaisesti paranna suorituskykyä.
static readonly DisplayResolution Large
Suuri tarkkuus (WVGA, 800 x 480). Oletus WP8:lla.
static Game Instance
Käynnissä olevan pelin pääolio.
Definition: Game.cs:96
static ScreenView Screen
Näytön dimensiot, eli koko ja reunat.
Definition: Graphics.cs:90
Vector ViewportSize
Näytön todellinen koko.
Definition: View.cs:284
Vector Size
Näytön koko vektorina.
Definition: View.cs:248
Vector Scale
Näytön skaalaus.
Definition: View.cs:208
Angle Angle
Näytön kiertokulma.
Definition: View.cs:199
Suuntakulma (rajoitettu -180 ja 180 asteen välille) asteina ja radiaaneina. Tietoja kulmasta: http://...
Definition: Angle.cs:40
static readonly Angle RightAngle
Suora kulma (90 astetta).
Definition: Angle.cs:49
static readonly Angle StraightAngle
Oikokulma (180 astetta).
Definition: Angle.cs:54
static readonly Angle Zero
Nollakulma.
Definition: Angle.cs:44
2D-vektori.
Definition: Vector.cs:67
double Y
Vektorin Y-komponentti
Definition: Vector.cs:339
double X
Vektorin X-komponentti.
Definition: Vector.cs:334
static readonly Vector Diagonal
Diagonaalivektori (1,1)
Definition: Vector.cs:91
Vector Transpose()
Palauttaa uuden vektorin, jossa x ja y on vaihdettu keskenään.
Definition: Vector.cs:240