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 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
public class Game1 : Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Camera camera; Vector2 vp, gameWorldSize = new Vector2(1334, 750); float ScaleX, ScaleY, Scale; Vector2 Newcameraposition; Texture2D Hintergrund, Balken; float BalkenPosOben, BalkenPosUnten, BalkenBreite, BalkenHoehe; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.IsFullScreen = true; graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight; } protected override void Initialize() { base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); Hintergrund = Content.Load<Texture2D>("Hintergrundbild"); Balken = Content.Load<Texture2D>("Balkenschwarz"); vp = new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); ScaleX = vp.X / gameWorldSize.X; ScaleY = vp.Y / gameWorldSize.Y; Scale = Math.Min(ScaleX, ScaleY); camera = new Camera(new Vector2(gameWorldSize.X / 2, gameWorldSize.Y / 2), Scale, vp); float ScreenHoehe = GraphicsDevice.PresentationParameters.BackBufferHeight; float Bildhoehe = Scale * vp.Y / 2; float Differenz = ScreenHoehe - Bildhoehe; BalkenBreite = GraphicsDevice.PresentationParameters.BackBufferWidth; BalkenHoehe = Differenz / 2; BalkenPosOben = (int)gameWorldSize.Y / 2 - Bildhoehe / 2 - BalkenHoehe / 2; BalkenPosUnten = (int)gameWorldSize.Y / 2 + Bildhoehe / 2 + BalkenHoehe / 2; } protected override void Update(GameTime gameTime) { Newcameraposition = new Vector2(gameWorldSize.X / 2, gameWorldSize.Y / 2); camera.Update(gameTime, Newcameraposition, Scale, vp); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, camera.GetMatrix()); spriteBatch.Draw(Hintergrund, new Rectangle((int)gameWorldSize.X / 2, (int)gameWorldSize.Y / 2, Hintergrund.Width, Hintergrund.Height), null, Color.White, 0, new Vector2(Hintergrund.Width / 2, Hintergrund.Height / 2), SpriteEffects.None, 0.10f); spriteBatch.Draw(Balken, new Rectangle((int)gameWorldSize.X / 2, (int)BalkenPosOben, (int)BalkenBreite, (int)BalkenHoehe), null, Color.White, 0, new Vector2(Balken.Width / 2, Balken.Height / 2), SpriteEffects.None, 0.09f); spriteBatch.Draw(Balken, new Rectangle((int)gameWorldSize.X / 2, (int)BalkenPosUnten, (int)BalkenBreite, (int)BalkenHoehe), null, Color.White, 0, new Vector2(Balken.Width / 2, Balken.Height / 2), SpriteEffects.None, 0.09f); 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 25 26 27 |
public class Camera { public Vector2 PlayerPosition; private Vector2 Viewport; private float Scale; public Camera(Vector2 playerposition, float scale, Vector2 viewport) { PlayerPosition = playerposition; Scale = scale; Viewport = viewport; } public void Update(GameTime gameTime, Vector2 playerposition, float scale, Vector2 viewport) { PlayerPosition = playerposition; Scale = scale; Viewport = viewport; } public Matrix GetMatrix() { return Matrix.CreateTranslation(new Vector3(-PlayerPosition.X, -PlayerPosition.Y, 0)) * Matrix.CreateScale(Scale, Scale, 1) * Matrix.CreateTranslation(Viewport.X / 2, Viewport.Y / 2, 0); } } |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
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 52 53 54 55 56 57 58 59 60 61 |
public class Game1 : Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Vector2 vp, gameWorldSize = new Vector2(1334, 750); float ScaleX, ScaleY, Scale; Texture2D Hintergrund, Balken; float BalkenPosOben, BalkenPosUnten, BalkenBreite, BalkenHoehe; Matrix Scalematrix; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.IsFullScreen = true; graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight; } protected override void Initialize() { base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); Hintergrund = Content.Load<Texture2D>("Hintergrundbild"); Balken = Content.Load<Texture2D>("Balkenschwarz"); vp = new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); ScaleX = vp.X / gameWorldSize.X; ScaleY = vp.Y / gameWorldSize.Y; Scale = Math.Min(ScaleX, ScaleY); Scalematrix = Matrix.CreateScale(Scale, Scale, 1.0f); float ScreenHoehe = GraphicsDevice.Viewport.Height; float Bildhoehe = Hintergrund.Height; float Differenz = ScreenHoehe - Bildhoehe * Scale; BalkenBreite = GraphicsDevice.Viewport.Width; BalkenHoehe = Differenz / 2; BalkenPosOben = (int)0 + BalkenHoehe / 2; BalkenPosUnten = (int)ScreenHoehe + BalkenHoehe / 2; } protected override void Update(GameTime gameTime) { base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, Scalematrix); spriteBatch.Draw(Hintergrund, new Rectangle((int)gameWorldSize.X / 2, (int)gameWorldSize.Y / 2, Hintergrund.Width, Hintergrund.Height), null, Color.White, 0, new Vector2(Hintergrund.Width / 2, Hintergrund.Height / 2), SpriteEffects.None, 0.10f); spriteBatch.Draw(Balken, new Rectangle((int)gameWorldSize.X / 2, (int)BalkenPosOben, (int)BalkenBreite, (int)BalkenHoehe), null, Color.White, 0, new Vector2(Balken.Width / 2, Balken.Height / 2), SpriteEffects.None, 0.09f); spriteBatch.Draw(Balken, new Rectangle((int)gameWorldSize.X / 2, (int)BalkenPosUnten, (int)BalkenBreite, (int)BalkenHoehe), null, Color.White, 0, new Vector2(Balken.Width / 2, Balken.Height / 2), SpriteEffects.None, 0.09f); spriteBatch.End(); base.Draw(gameTime); } } |
Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von »Big_Santa« (04.11.2018, 00:26)
Werbeanzeige