C# Amimations problem

starfire

Grünschnabel
Also folgendes Problem.
Ich hol mir die Tasten bzw. den Code der tTste die auf der Tastatur gedrückt werden und leite sie an eine Methode weiter.
Wenn jetzt bespielweise "W" gedrückt wird, soll die entsprechende Animation abgespielt werden.
Mit den Pfeiltasten klappt das auch wunderbar, wenn ich allerdings eine andere Taste(z.B. Buchstaben) drücke gibt er mit nur das erste und manchmal auch noch ein einzellnes Bild, mitten aus der Animation aus und bleibt dann in der Animation stehen, spielt sie also nicht weiter ab. Dabei ist es die gleiche if-Abfrage.

Zum Code:
Ich übergebe der Methode die Taste als int. Klappt auch wunderbar.
Ich stoppe die zuvor laufende Animation und überprüfe anschließend welche Taste gedrückt wurde.
Dann weise ich die entsprechende Grafik zu und melde sie zur animation an.

Bei machen kommen dann noch ein paar zusätzliche Sachen wie Sound abspielen oder Grafik verschieben hinzu, aber das klappt ja auch soweit. Er spielt ja nur die Grafiken nicht ab, was aus meiner sicht heraus unverständlich ist, da er dies ja bei den Pfeiltasten macht. Ich hoffe, dass ihr mir dabei weiter helfen könnt.

Code:
internal void action(int taste)
        {
                ImageAnimator.StopAnimate(f1.windowImage[500], new EventHandler(Handle));
                if (!(f1.windowCords[500, 0] > f1.windowCords[0, 0] && f1.windowCords[500, 0] < f1.windowCords[0, 0] + f1.windowCords[0, 0] && f1.windowCords[500, 1] > f1.windowCords[0, 1] && f1.windowCords[500, 1] < f1.windowCords[0, 1] + f1.windowCords[0, 1]))
                {
                    if (taste == 38 || taste == 119 && f1.mode.Equals("game")) //up
                    {
                        f1.windowImage[500] = Image.FromFile(Application.StartupPath + "/System/human_male_blond_back.gif");
                        f1.windowRenderSize[500, 0] = f1.sc.objektGroeßeInt(502);
                        f1.windowRenderSize[500, 1] = f1.sc.objektGroeßeInt(512);
                        if (ImageAnimator.CanAnimate(f1.windowImage[500]))
                            ImageAnimator.Animate(f1.windowImage[500], new EventHandler(Handle));
                        position = "back";
                        f1.windowCords[0, 1] = f1.windowCords[0, 1] + (10 * konstitution);
                        objektPlatzierung(0,(10 * konstitution));
                        if ((f1.windowCords[500, 0] > f1.windowCords[0, 0] && f1.windowCords[500, 0] < f1.windowCords[0, 0] + f1.windowCords[0, 0] && f1.windowCords[500, 1] > f1.windowCords[0, 1] && f1.windowCords[500, 1] < f1.windowCords[0, 1] + f1.windowCords[0, 1]))
                        {
                            f1.windowCords[0, 1] = f1.windowCords[0, 1] - (10 * konstitution);
                            objektPlatzierung(0, (-10 * konstitution));
                        }
                    }
                    else if (taste == 40 || taste == 115 && f1.mode.Equals("game")) //down
                    {
                        f1.windowImage[500] = Image.FromFile(Application.StartupPath + "/System/human_male_blond_front.gif");
                        f1.windowRenderSize[500, 0] = f1.sc.objektGroeßeInt(502);
                        f1.windowRenderSize[500, 1] = f1.sc.objektGroeßeInt(512);
                        if (ImageAnimator.CanAnimate(f1.windowImage[500]))
                            ImageAnimator.Animate(f1.windowImage[500], new EventHandler(Handle));
                        position = "front";
                        f1.windowCords[0, 1] = f1.windowCords[0, 1] - (10 * konstitution);
                        objektPlatzierung(0,(-10 * konstitution));
                        if ((f1.windowCords[500, 0] > f1.windowCords[0, 0] && f1.windowCords[500, 0] < f1.windowCords[0, 0] + f1.windowCords[0, 0] && f1.windowCords[500, 1] > f1.windowCords[0, 1] && f1.windowCords[500, 1] < f1.windowCords[0, 1] + f1.windowCords[0, 1]))
                        {
                            f1.windowCords[0, 1] = f1.windowCords[0, 1] + (10 * konstitution);
                            objektPlatzierung(0, (+10 * konstitution));
                        }
                    }
                    else if (taste == 37 || taste == 97 && f1.mode.Equals("game")) //left
                    {
                        f1.windowImage[500] = Image.FromFile(Application.StartupPath + "/System/human_male_blond_left.gif");
                        f1.windowRenderSize[500, 0] = f1.sc.objektGroeßeInt(502);
                        f1.windowRenderSize[500, 1] = f1.sc.objektGroeßeInt(512);
                        if (ImageAnimator.CanAnimate(f1.windowImage[500]))
                            ImageAnimator.Animate(f1.windowImage[500], new EventHandler(Handle));
                        position = "left";
                        f1.windowCords[0, 0] = f1.windowCords[0, 0] + (10 * konstitution);
                        objektPlatzierung((10 * konstitution), 0);
                        if ((f1.windowCords[500, 0] > f1.windowCords[0, 0] && f1.windowCords[500, 0] < f1.windowCords[0, 0] + f1.windowCords[0, 0] && f1.windowCords[500, 1] > f1.windowCords[0, 1] && f1.windowCords[500, 1] < f1.windowCords[0, 1] + f1.windowCords[0, 1]))
                        {
                            f1.windowCords[0, 0] = f1.windowCords[0, 0] - (10 * konstitution);
                            objektPlatzierung(0, (-10 * konstitution));
                        }
                    }
                    else if (taste == 39 || taste == 100 && f1.mode.Equals("game")) //right
                    {
                        f1.windowImage[500] = Image.FromFile(Application.StartupPath + "/System/human_male_blond_right.gif");
                        f1.windowRenderSize[500, 0] = f1.sc.objektGroeßeInt(502);
                        f1.windowRenderSize[500, 1] = f1.sc.objektGroeßeInt(512);
                        if (ImageAnimator.CanAnimate(f1.windowImage[500]))
                            ImageAnimator.Animate(f1.windowImage[500], new EventHandler(Handle));
                        position = "right";
                        f1.windowCords[0, 0] = f1.windowCords[0, 0] - (10 * konstitution);
                        objektPlatzierung((-10 * konstitution), 0);
                        if ((f1.windowCords[500, 0] > f1.windowCords[0, 0] && f1.windowCords[500, 0] < f1.windowCords[0, 0] + f1.windowCords[0, 0] && f1.windowCords[500, 1] > f1.windowCords[0, 1] && f1.windowCords[500, 1] < f1.windowCords[0, 1] + f1.windowCords[0, 1]))
                        {
                            f1.windowCords[0, 0] = f1.windowCords[0, 0] + (10 * konstitution);
                            objektPlatzierung(0, (+10 * konstitution));
                        }
                    }
                }
                else if (taste == 102) //Attack
                {
                    if (position == "front")
                    {
                        ImageAnimator.StopAnimate(f1.windowImage[500], new EventHandler(Handle));
                        f1.windowRenderSize[500, 0] = f1.sc.objektGroeßeInt(552);
                        f1.windowRenderSize[500, 1] = f1.sc.objektGroeßeInt(563);
                        f1.windowImage[500] = Image.FromFile(Application.StartupPath + "/System/human_male_blond_fight_front.gif");
                        if (ImageAnimator.CanAnimate(f1.windowImage[500]))
                            ImageAnimator.Animate(f1.windowImage[500], new EventHandler(Handle));
                    }
                    else if (position == "back")
                    {
                        ImageAnimator.StopAnimate(f1.windowImage[500], new EventHandler(Handle));
                        f1.windowRenderSize[500, 0] = f1.sc.objektGroeßeInt(552);
                        f1.windowRenderSize[500, 1] = f1.sc.objektGroeßeInt(563);
                        f1.windowImage[500] = Image.FromFile(Application.StartupPath + "/System/human_male_blond_fight_back.gif");
                        if (ImageAnimator.CanAnimate(f1.windowImage[500]))
                            ImageAnimator.Animate(f1.windowImage[500], new EventHandler(Handle));
                    }
                    else if (position == "left")
                    {
                        ImageAnimator.StopAnimate(f1.windowImage[500], new EventHandler(Handle));
                        f1.windowRenderSize[500, 0] = f1.sc.objektGroeßeInt(552);
                        f1.windowRenderSize[500, 1] = f1.sc.objektGroeßeInt(563);
                        f1.windowImage[500] = Image.FromFile(Application.StartupPath + "/System/human_male_blond_fight_left.gif");
                        if (ImageAnimator.CanAnimate(f1.windowImage[500]))
                            ImageAnimator.Animate(f1.windowImage[500], new EventHandler(Handle));
                    }
                    else if (position == "right")
                    {
                        ImageAnimator.StopAnimate(f1.windowImage[500], new EventHandler(Handle));
                        f1.windowRenderSize[500, 0] = f1.sc.objektGroeßeInt(552);
                        f1.windowRenderSize[500, 1] = f1.sc.objektGroeßeInt(563);
                        f1.windowImage[500] = Image.FromFile(Application.StartupPath + "/System/human_male_blond_fight_right.gif");
                        if (ImageAnimator.CanAnimate(f1.windowImage[500]))
                            ImageAnimator.Animate(f1.windowImage[500], new EventHandler(Handle));
                    }
                    f1.soundChanel2 = new SoundFile("System/sword.wav");
                    f1.soundChanel2.Repeat = false;
                    f1.soundChanel2.Volume = 75 * 10;
                    f1.soundChanel2.Play();
                }
                else if (taste == 122) //Zauber
                {
                    if (position == "front")
                    {
                        ImageAnimator.StopAnimate(f1.windowImage[500], new EventHandler(Handle));
                        f1.windowRenderSize[500, 0] = f1.sc.objektGroeßeInt(502);
                        f1.windowRenderSize[500, 1] = f1.sc.objektGroeßeInt(512);
                        f1.windowImage[500] = Image.FromFile(Application.StartupPath + "/System/human_male_blond_cast_front.gif");
                        if (ImageAnimator.CanAnimate(f1.windowImage[500]))
                            ImageAnimator.Animate(f1.windowImage[500], new EventHandler(Handle));
                    }
                    else if (position == "back")
                    {
                        ImageAnimator.StopAnimate(f1.windowImage[500], new EventHandler(Handle));
                        f1.windowRenderSize[500, 0] = f1.sc.objektGroeßeInt(502);
                        f1.windowRenderSize[500, 1] = f1.sc.objektGroeßeInt(512);
                        f1.windowImage[500] = Image.FromFile(Application.StartupPath + "/System/human_male_blond_cast_back.gif");
                        if (ImageAnimator.CanAnimate(f1.windowImage[500]))
                            ImageAnimator.Animate(f1.windowImage[500], new EventHandler(Handle));
                    }
                    else if (position == "left")
                    {
                        ImageAnimator.StopAnimate(f1.windowImage[500], new EventHandler(Handle));
                        f1.windowRenderSize[500, 0] = f1.sc.objektGroeßeInt(502);
                        f1.windowRenderSize[500, 1] = f1.sc.objektGroeßeInt(512);
                        f1.windowImage[500] = Image.FromFile(Application.StartupPath + "/System/human_male_blond_cast_left.gif");
                        if (ImageAnimator.CanAnimate(f1.windowImage[500]))
                            ImageAnimator.Animate(f1.windowImage[500], new EventHandler(Handle));
                    }
                    else if (position == "right")
                    {
                        ImageAnimator.StopAnimate(f1.windowImage[500], new EventHandler(Handle));
                        f1.windowRenderSize[500, 0] = f1.sc.objektGroeßeInt(502);
                        f1.windowRenderSize[500, 1] = f1.sc.objektGroeßeInt(512);
                        f1.windowImage[500] = Image.FromFile(Application.StartupPath + "/System/human_male_blond_cast_right.gif");
                        if (ImageAnimator.CanAnimate(f1.windowImage[500]))
                            ImageAnimator.Animate(f1.windowImage[500], new EventHandler(Handle));
                    }
                    f1.soundChanel2 = new SoundFile("System/magic.wav");
                    f1.soundChanel2.Repeat = false;
                    f1.soundChanel2.Volume = 75 * 10;
                    f1.soundChanel2.Play();
                }


            }

Danke schonmal im Vorraus und bei weiteren fragen, melden.
 
Zurück