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 |
animations[0] = new Animation(new Rectangle[10], Content.Load<Texture2D>("kurzeanim"), TimeSpan.FromSeconds(2), Animationsablaeufe.vorwärts); |
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
public class Animation { private int _animIndex; private int _count = 0; public enum Animationsablaeufe { vorwärts, rückwärts, vorrück, rückvor } public TimeSpan PassedTime { get; private set; } public Rectangle[] SourceRects { get; private set; } public Texture2D Texture {get; private set; } public TimeSpan Duration { get; private set; } public Animationsablaeufe Ablauf { get; private set; } public Animation(Rectangle[] sourceRects, Texture2D texture, TimeSpan duration, Animationsablaeufe animationsablaeufe) { int framewidth = texture.Width / sourceRects.Length; int frameheight = texture.Height; switch (animationsablaeufe) { case Animationsablaeufe.vorwärts: { for (int i = 0; i < sourceRects.Length; i++) { sourceRects[i] = new Rectangle(i * framewidth, 0, framewidth, frameheight); } break; } case Animationsablaeufe.rückwärts: { for (int i = 0; i < sourceRects.Length; i++) { sourceRects[i] = new Rectangle((sourceRects.Length - 1 - i) * framewidth, 0, framewidth, frameheight); } break; } case Animationsablaeufe.vorrück: { for (int i = 0; i < sourceRects.Length; i++) { _count += 1; if (_count < sourceRects.Length + 1) { sourceRects[i] = new Rectangle(i * framewidth, 0, framewidth, frameheight); } else { sourceRects[i] = new Rectangle((sourceRects.Length - 1 - i) * framewidth, 0, framewidth, frameheight); if (i == sourceRects.Length - 1) _count = 0; } } break; } case Animationsablaeufe.rückvor: { for (int i = 0; i < sourceRects.Length; i++) { _count += 1; if (_count < sourceRects.Length + 1) { sourceRects[i] = new Rectangle((sourceRects.Length - 1 - i) * framewidth, 0, framewidth, frameheight); } else { sourceRects[i] = new Rectangle(i * framewidth, 0, framewidth, frameheight); if (i == sourceRects.Length - 1) _count = 0; } } break; } } SourceRects = sourceRects; Texture = texture; Duration = duration; Ablauf = animationsablaeufe; } |
C#-Quelltext |
|
1 |
animations[0] = new Animation(new Rectangle[10], Content.Load<Texture2D>("kurzeanim"), TimeSpan.FromSeconds(2), Animation.Animationsablaeufe.vorwärts); |
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 |
case Animationsablaeufe.vorrück: { for (int z = 0; z < 2; z++) { if (z == 0) { for (int i = 0; i < sourceRects.Length; i++) { sourceRects[i] = new Rectangle(i * framewidth, 0, framewidth, frameheight); } } if (z == 1) { for (int i = 0; i < sourceRects.Length; i++) { sourceRects[i] = new Rectangle((sourceRects.Length - 1 - i) * framewidth, 0, framewidth, frameheight); } } } break; } case Animationsablaeufe.rückvor: { for (int z = 0; z < 2; z++) { if (z == 0) { for (int i = 0; i < sourceRects.Length; i++) { sourceRects[i] = new Rectangle((sourceRects.Length - 1 - i) * framewidth, 0, framewidth, frameheight); } } if (z == 1) { for (int i = 0; i < sourceRects.Length; i++) { sourceRects[i] = new Rectangle(i * framewidth, 0, framewidth, frameheight); } } } break; } |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Es ist ja keine Schande etwas falsch zu machen, als Programmierer tu ich das täglich, [...].
Werbeanzeige