Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C#-Quelltext |
|
1 2 3 4 5 |
public interface IState { void Update(); void Render(); } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 |
public class Menu:IState { public void Update() { } public void Render() { } } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 |
public class Game:IState { public void Update() { } public void Render() { } } |
C#-Quelltext |
|
1 |
private IState currentState;
|
C#-Quelltext |
|
1 |
currentState = new Menu(); |
C#-Quelltext |
|
1 |
currentState.Update(); |
Es ist ja keine Schande etwas falsch zu machen, als Programmierer tu ich das täglich, [...].
C#-Quelltext |
|
1 |
public class Menu:IState |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; public IState currentState; public interface IState { void Load(); void Update(); void Render(); } public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { currentState = new Intro(); base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); } protected override void Update(GameTime gameTime) { currentState.Update(); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); currentState.Render(); spriteBatch.End(); base.Draw(gameTime); } } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
public class Intro : menuinterface.Game1.IState { Game1 game1; Texture2D Titelbildschirm; public void Load(ContentManager content) { Titelbildschirm = content.Load<Texture2D>("gruft"); } public void Update() { KeyboardState kbState = Keyboard.GetState(); if (kbState.IsKeyDown(Keys.Space)) game1.currentState = new Menu(); } public void Render(SpriteBatch batch) { batch.Begin(); batch.Draw(Titelbildschirm, new Rectangle(0, 0, 1280, 720), Color.White); batch.End(); } } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
public class Menu:menuinterface.Game1.IState { Game1 game1; Texture2D Auswahlbildschirm; public void Load(ContentManager content) { Auswahlbildschirm = content.Load<Texture2D>("menubild"); } public void Update() { KeyboardState kbState = Keyboard.GetState(); if (kbState.IsKeyDown(Keys.Enter)) game1.currentState = new Game(); if (kbState.IsKeyDown(Keys.Escape)) this.Exit(); } public void Render(SpriteBatch batch) { batch.Begin(); batch.Draw(Auswahlbildschirm, new Rectangle(0, 0, 1280, 720), Color.White); batch.End(); } } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
public class Game : menuinterface.Game1.IState { Game1 game1; Texture2D Spielbildschirm; public void Load(ContentManager content) { Spielbildschirm = content.Load<Texture2D>("hauszombie"); } public void Update() { KeyboardState kbState = Keyboard.GetState(); if (kbState.IsKeyDown(Keys.Escape)) this.Exit(); } public void Render(SpriteBatch batch) { batch.Begin(); batch.Draw(Spielbildschirm, new Rectangle(0, 0, 1280, 720), Color.White); batch.End(); } } |
C#-Quelltext |
|
1 |
public IState currentState;
|
C#-Quelltext |
|
1 2 3 4 5 |
public interface IState { void Load(); void Update(); void Render(); } |
Werbeanzeige