Jypeli 10
The simple game programming library
Content.cs
Siirry tämän tiedoston dokumentaatioon.
1#region MIT License
2/*
3 * Copyright (c) 2013 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, Janne Nikkanen, Mikko Röyskö.
28 */
29
30using System;
31using System.IO;
32using Jypeli.Content;
33using Microsoft.Xna.Framework.Content;
34using Microsoft.Xna.Framework.Graphics;
35
36using XnaSoundEffect = Microsoft.Xna.Framework.Audio.SoundEffect;
37
38#if NETFX_CORE
39using Windows.ApplicationModel.Resources;
40#else
41#endif
42
43
44namespace Jypeli
45{
46 public partial class Game
47 {
51 public MediaPlayer MediaPlayer { get; private set; }
52
57 public double MasterVolume
58 {
60 set => SoundEffect.MasterVolume = value;
61 }
62
67 public static JypeliContentManager ResourceContent { get; private set; }
68
69 private void InitXnaContent()
70 {
72 Content.RootDirectory = "Content";
74 }
75
81 public static Image LoadImage(string name)
82 {
83 return new Image("Content/" + name);
84 }
85
91 public static Image LoadImageFromResources(string name)
92 {
94 }
95
101 public static Image[] LoadImages(params string[] names)
102 {
103 Image[] result = new Image[names.Length];
104 for (int i = 0; i < names.Length; i++)
105 result[i] = LoadImage(names[i]);
106 return result;
107 }
108
117 public static Image[] LoadImages(string baseName, int startIndex, int endIndex, bool zeroPad = false)
118 {
119 if (startIndex > endIndex) throw new ArgumentException("Starting index must be smaller than ending index.");
120
121 Image[] result = new Image[endIndex - startIndex];
122 string format;
123
124 if (zeroPad)
125 {
126 int digits = endIndex.ToString().Length;
127 format = "{0}{1:" + "0".Repeat(digits) + "}";
128 }
129 else
130 {
131 format = "{0}{1}";
132 }
133
134 for (int i = startIndex; i < endIndex; i++)
135 {
136 string imgName = String.Format(format, baseName, i);
137 result[i - startIndex] = LoadImage(imgName);
138 }
139
140 return result;
141 }
142
147 public static void PlaySound(string name)
148 {
149 LoadSoundEffect(name).Play();
150 }
151
157 public static SoundEffect LoadSoundEffect(string name)
158 {
159 return new SoundEffect("Content/" + name);
160 }
161
167 public static SoundEffect LoadSoundEffectFromResources(string name)
168 {
170 }
171
177 public static SoundEffect[] LoadSoundEffects(params string[] names)
178 {
179 SoundEffect[] result = new SoundEffect[names.Length];
180 for (int i = 0; i < names.Length; i++)
181 result[i] = LoadSoundEffect(names[i]);
182 return result;
183 }
184
189 public static Font LoadFont(string name)
190 {
191 return Font.FromContent(name);
192 }
193
200 internal static string FileExtensionCheck(string file, string[] extensions)
201 {
202 if (!File.Exists(file))
203 {
204 foreach (string ex in extensions)
205 {
206 if (File.Exists(file + ex))
207 {
208 file += ex;
209 break;
210 }
211 }
212 }
213 return file;
214 }
215 }
216}
Microsoft.Xna.Framework.Audio.SoundEffect XnaSoundEffect
Definition: Content.cs:36
Hallitsee pelin tiedostojen lataamista.
SoundEffect LoadInternalSoundEffect(string assetName)
Lataa äänitiedoston Jypelin sisäisistä resursseista
Image LoadInternalImage(string assetName)
Lataa kuvatiedoston Jypelin sisäisistä resursseista
Fontti.
Definition: Font.cs:24
static Font FromContent(string name)
Lataa uuden fontin contentista.
Definition: Font.cs:146
static SoundEffect LoadSoundEffect(string name)
Lataa ääniefektin contentista.
Definition: Content.cs:157
double MasterVolume
Pelin kaikkien ääniefektien voimakkuuskerroin, Väliltä 0-1.0. Tämä on sama kuin SoundEffect....
Definition: Content.cs:58
static Image LoadImageFromResources(string name)
Lataa kuvan Jypelin sisäisistä resursseista.
Definition: Content.cs:91
static SoundEffect[] LoadSoundEffects(params string[] names)
Lataa taulukon ääniefektejä contentista.
Definition: Content.cs:177
static SoundEffect LoadSoundEffectFromResources(string name)
Lataa ääniefektin Jypelin sisäisistä resursseista.
Definition: Content.cs:167
static Image LoadImage(string name)
Lataa kuvan contentista.
Definition: Content.cs:81
static void PlaySound(string name)
Soittaa ääniefektin.
Definition: Content.cs:147
void InitXnaContent()
Definition: Content.cs:69
static Font LoadFont(string name)
Lataa fontin. Fontin tulee olla lisätty content-hakemistoon.
Definition: Content.cs:189
static string FileExtensionCheck(string file, string[] extensions)
Etsii millä päätteellä annettu tiedosto löytyy
Definition: Content.cs:200
static JypeliContentManager ResourceContent
Kirjaston mukana tuleva sisältö. Voidaan käyttää esimerkiksi sisäisten tekstuurien lataamiseen.
Definition: Content.cs:67
MediaPlayer MediaPlayer
Mediasoitin. Voidaan käyttää musiikin soittamiseen.
Definition: Content.cs:51
static Image[] LoadImages(params string[] names)
Lataa taulukon kuvia contentista.
Definition: Content.cs:101
static Image[] LoadImages(string baseName, int startIndex, int endIndex, bool zeroPad=false)
Lataa taulukon kuvia contentista.
Definition: Content.cs:117
Kuva.
Definition: Image.cs:30
Mediasoitin, jolla voi soittaa musiikkikappaleita.
Definition: MediaPlayer.cs:13
Ääniefekti. Yhdestä efektistä voi luoda CreateSound-metodilla monta ääntä (Sound),...
Definition: SoundEffect.cs:17
bool Play()
Soittaa äänen.
Definition: SoundEffect.cs:131
static double MasterVolume
Äänenvoimakkuuden taso 0.0 - 1.0
Definition: SoundEffect.cs:196