Du bist nicht angemeldet.

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

1

19.06.2013, 15:02

Bild loading problem(SDL+C++)

Hallo allerseits,

Ich habe folgendes Problem:

Ich muss zwei Szenen animieren bzw zum laufen bringen.
Dazu Habe ich folgende Dateien:
animation.cpp
animation.h
zweitesbild.cpp
zweitesbild.h
main.cpp

Ich kann die Erste Szene erfolgreich laden aber sobald ich die zweite Szene zum laufen bringen will, lädt er das Bild nicht auf der Surface.

C-/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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "zweitesbild.h"

const int framepersecond = 10;
using namespace std;
int zahl;

SDL_Event event;

int main( int argc, char* args[])
{
    bool quit = false;
    SDL_Init(SDL_INIT_EVERYTHING);
    cout << "welches Bild wollen laden ?" << endl;

    cin >> zahl;

    switch(zahl)
    {

    case 1:
        if(zahl = 1)
        {
            animation ani;
            ani.loadimages();
            ani.clips();

            while( quit == false )
            {
                ani.start();


                while( SDL_PollEvent( &event ) )
                {

                    //If the user has Xed out the window
                    if( event.type == SDL_QUIT )
                    {
                        //Quit the program
                        quit = true;
                    }
                }

                ani.Move2();
                ani.Move();
                ani.show();
                ani.update();


                if( ani.getticks() < 1000 / framepersecond )
                {
                    SDL_Delay( ( 5500 / framepersecond ) - ani.getticks() );
                }


            }
            return 0;
        }
    case 2:
        if(zahl = 2)
        {
            zweitesbild anii;
            anii.loadimages();
            anii.clips();

            while( quit == false )
            {
                anii.start();


                while( SDL_PollEvent( &event ) )
                {

                    //If the user has Xed out the window
                    if( event.type == SDL_QUIT )
                    {
                        //Quit the program
                        quit = true;
                    }
                }


                anii.Move();
                anii.show();
                anii.update();


                if( anii.getticks() < 1000 / framepersecond )
                {
                    SDL_Delay( ( 5500 / framepersecond ) - anii.getticks() );
                }


            }
            return 0;
        }

    }


}


Hier ist das ganze Programm mit den Bildern
»killermiller« hat folgende Dateien angehängt:
  • Bilder.rar (980,16 kB - 49 mal heruntergeladen - zuletzt: 25.05.2024, 16:08)
  • Animation.rar (338,26 kB - 40 mal heruntergeladen - zuletzt: 25.05.2024, 07:26)
  • Bilder1.rar (901,09 kB - 42 mal heruntergeladen - zuletzt: 15.05.2024, 06:31)

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »killermiller« (19.06.2013, 15:19)


BlueCobold

Community-Fossil

Beiträge: 10 738

Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer

  • Private Nachricht senden

2

19.06.2013, 15:09

ladet lädt
Teamleiter von Rickety Racquet (ehemals das "Foren-Projekt") und von Marble Theory

Willkommen auf SPPRO, auch dir wird man zu Unity oder zur Unreal-Engine raten, ganz bestimmt.[/Sarkasmus]

Fawkes

Frischling

Beiträge: 58

Beruf: Realschüler :)

  • Private Nachricht senden

3

19.06.2013, 21:40

Vielleicht liegt es daran, dass du die break;'s vergessen hast. Nach jedem case: muss ein break; kommen.

4

19.06.2013, 22:29

C-/C++-Quelltext

1
if(zahl = 1)

C-/C++-Quelltext

1
if(zahl = 2)


Grundlagen?
"Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: Nothing works and they don’t know why." - Anon

Nimelrian

Alter Hase

Beiträge: 1 216

Beruf: Softwareentwickler (aktuell Web/Node); Freiberuflicher Google Proxy

  • Private Nachricht senden

5

19.06.2013, 22:49

Ich finde ja das

C-/C++-Quelltext

1
2
3
switch(zahl)
    case 1:
        if(zahl = 1)


wesentlich interessanter...
Ich bin kein UserSideGoogleProxy. Und nein, dieses Forum ist kein UserSideGoogleProxyAbstractFactorySingleton.

6

19.06.2013, 23:34

Ich finde ja das

C-/C++-Quelltext

1
2
3
switch(zahl)
    case 1:
        if(zahl = 1)


wesentlich interessanter...



naja ich verstehe nicht direkt was ihr meint :rolleyes:

Architekt

Community-Fossil

Beiträge: 2 481

Wohnort: Hamburg

Beruf: Student

  • Private Nachricht senden

7

20.06.2013, 00:12

Zum einen: im if wird per == überprüft. = ist eine Zuweisung, == ein Vergleich.
Zum anderen: wenn du schom in case 1 bist, also deine Zahl 1 ist, wieso solltest du dann nochmal redundanter weise prüfen, ob deine Zahl auch wirklich 1 ist?
Der einfachste Weg eine Kopie zu entfernen ist sie zu löschen.
- Stephan Schmidt -

8

20.06.2013, 00:29

[edit]schade, zu langsam, ich sollte meine Tabs nicht so lange offen lassen ... [/edit]

case und if sind redundant, da dieser case Zweig genau dann aufgerufen wird, wenn zahl==1 ist. Das nochmal abzufragen ist sinnlos. Desweiteren ist = der Zuweisungsoperator, == der Vergelichsoperator. Effektiv fragst du also im switch ab, ob zahl 1 ist, setzt sie dann während der Abfrage auf 1 und führst den Code im if aus, da der Wert der Zuweisung 1 ist, was zu true evaluiert.
Direkt danach wird das case 2: ausgeführt, da switch nur in den richtigen Zweig springt, danach nicht aber heraus - genau dafür ist das break da, das du vergessen hast.
Lieber dumm fragen, als dumm bleiben!

9

20.06.2013, 00:45

Direkt danach wird das case 2: ausgeführt, da switch nur in den richtigen Zweig springt, danach nicht aber heraus - genau dafür ist das break da, das du vergessen hast.

Auch wenn dort kein break steht, so wird der 2. Zweig nicht ausgeführt. Das return beendet zuvor das Programm. Guter Stil ist das aber nicht unbedingt.
"Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: Nothing works and they don’t know why." - Anon

10

20.06.2013, 00:52

Das sieht nun folgendermaßen aus:

C-/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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "zweitesbild.h"

const int framepersecond = 10;
using namespace std;
int zahl ;

SDL_Event event;

int main(int argc, char* args[])
{
    bool quit = false;
    SDL_Init(SDL_INIT_EVERYTHING);
    cout << "welches Bild wollen laden ?" << endl;
    cin >> zahl;



    if(zahl == 1)
    {
        animation ani;
        ani.loadimages();
        ani.clips();

        while( quit == false )
        {
            ani.start();


            while( SDL_PollEvent( &event ) )
            {

                //If the user has Xed out the window
                if( event.type == SDL_QUIT )
                {
                    //Quit the program
                    quit = true;
                }
            }

            ani.Move2();
            ani.Move();
            ani.show();
            ani.update();


            if( ani.getticks() < 1000 / framepersecond )
            {
                SDL_Delay( ( 5500 / framepersecond ) - ani.getticks() );
            }


        }
    }

    if(zahl == 2)
    {
        zweitesbild anii;
        anii.loadimages();
        anii.clips();

        while( quit == false )
        {
            anii.start();


            while( SDL_PollEvent( &event ) )
            {

                //If the user has Xed out the window
                if( event.type == SDL_QUIT )
                {
                    //Quit the program
                    quit = true;
                }
            }


            anii.Move();
            anii.show();
            anii.update();


            if( anii.getticks() < 1000 / framepersecond )
            {
                SDL_Delay( ( 5500 / framepersecond ) - anii.getticks() );
            }


        }
    }
    return 0;
}


Ergebnis bleibt erfolglos. Die erste Szene wird geladen die zweite nicht.

Werbeanzeige