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

16.11.2009, 15:53

[Erstes Spiel]Überspringt Intro und zeigt Textur nicht an

Hallo zusammen!
Ich hab wieder ein Problem.
Das Intro wurde mir schön angezeigt, bis ich das Hauptmenü fertig
programmiert hatte.
Jetzt überspringt er das Intro und geht direkt zum Hauptmenü.
Und dort wird auch die Textur erst angezeigt nachdem man auf "Spiel beenden" gedrückt hat.

Dann mal hier alle Quellcodes:
TicTacToe.cpp

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#include "TicTacToe.h" 

//______________Globale___Variablen_______________________________________//

CTicTacToe*     g_pTicTacToe;
float*          g_pfButtons = NULL;
BOOL*           g_pbButtons = NULL;
//________________________________________________________________________//

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   char* pcCommandLine,
                   int iShowCommand)
{
    tbResult r;
    g_pTicTacToe = new CTicTacToe;
    r = g_pTicTacToe->Init();
    if(r == TB_CANCELED)
    {
        TB_SAFE_DELETE(g_pTicTacToe);
        return 0;
    }
    else if(r)
    {
        TB_SAFE_DELETE(g_pTicTacToe);
        MessageBox(0,"Fehler beim Initialisieren des Spiels", "Fehler", MB_OK | MB_ICONEXCLAMATION);
        return 1;
    }

    if(g_pTicTacToe->Run())
    {
        g_pTicTacToe->Exit();
        TB_SAFE_DELETE(g_pTicTacToe);
        MessageBox(0, "Fehler im Spiel", "Fehler", MB_OK | MB_ICONEXCLAMATION);
        return 1;
    }

    g_pTicTacToe->Exit();
    TB_SAFE_DELETE(g_pTicTacToe);
    return 0;
}

tbResult CTicTacToe::Init()
{
    tbResult r;
    
    ZeroMemory(this, sizeof(CTicTacToe));

    if(tbInit()) return TB_ERROR;
    r = tbDoConfigDialog(&m_Config);
    if(r == TB_CANCELED) return TB_CANCELED;
    else if(r) TB_ERROR("Engine konnte nicht Initialisiert werden", r);  
    
    if(Load()) TB_ERROR("Fehler beim Laden des Spiels", TB_ERROR);

    m_pIntro = new CIntro;
    m_pMainMenu = new CMainMenu;
    m_pGame = new CGame;

    SetGameStat(GS_INTRO);

    return TB_OK;
}

tbResult CTicTacToe::Exit()
{
    SetGameStat(GS_NONE);

    Unload();

    TB_SAFE_DELETE(m_pIntro);
    TB_SAFE_DELETE(m_pMainMenu);
    TB_SAFE_DELETE(m_pGame);

    tbExit();
    
    return TB_OK;
}
tbResult CTicTacToe::Load()
{
 tbResult r;
 if(tbDirect3D::Instance().Init(&m_Config,"Tic Tac Toe", NULL, 0))
 {
     TB_ERROR("Fehler beim Initialisieren von Direct3D", TB_ERROR);
 }

 tbDirect3D::Instance()->CreateStateBlock(D3DSBT_ALL, &m_pStateBlock);

 if(tbTextureManager::Instance().Init())
 {
     TB_ERROR("Fehler beim Initialisieren des Textur Managers",TB_ERROR);
 }

 if(tbDirectInput::Instance().Init())
 {
     TB_ERROR("Fehler beim Initialisieren von Direct Input", TB_ERROR);
 }

 g_pfButtons = new float[tbDirectInput::Instance().GetNumButtons()];
 g_pbButtons = new BOOL[tbDirectInput::Instance().GetNumButtons()];

 m_pFont = new tbFont;
 if(m_pFont->Init("Data\\Font.tga", "Data\\Font.tbf"))
 {
     TB_ERROR("Fehler beim Laden der Fonts", TB_ERROR);
 }

 return TB_OK;
}

tbResult CTicTacToe::Unload()
{
    TB_SAFE_DELETE(m_pFont);
    TB_SAFE_RELEASE(m_pStateBlock);
    TB_SAFE_DELETE_ARRAY(g_pfButtons);
    TB_SAFE_DELETE_ARRAY(g_pbButtons);
    tbDirect3D::Instance().Exit();
    tbTextureManager::Instance().Exit();
    tbDirectInput::Instance().Exit();

    return TB_OK;
}

tbResult Move(float fTime) {return g_pTicTacToe->Move(fTime);}
tbResult Render(float fTime) {return g_pTicTacToe->Render(fTime);}

tbResult CTicTacToe::Run()
{
    if(tbDoMessageLoop(::Move, ::Render))
    {
        TB_ERROR("Fehler in der Nachrichtenschleife", TB_ERROR);
    }

    return TB_OK;
}

tbResult CTicTacToe::SetGameStat(EGameStat NewGameStat)
{
    tbResult r = TB_OK;

    switch(m_GameStat)
    {
    case GS_INTRO:      m_pIntro->Exit(); break;
    case GS_MAINMENU:   m_pMainMenu->Exit(); break;
    //case GS_GAME:       m_pGame->Exit(); break;

    }

    m_fTime = 0.0f;

    m_pStateBlock->Apply();
    tbDirect3D::Instance().Capture();

    m_GameStat = NewGameStat;

    switch(m_GameStat)
    {
    case GS_INTRO:       m_pIntro->Init(); break;
    case GS_MAINMENU:    m_pMainMenu->Init(); break;
    //case GS_GAME:        m_pGame->Init(); break;

    }

    if(r) TB_ERROR("Fehler beim Setzen des Spiel Status", TB_ERROR);
}

tbResult CTicTacToe::Move(float fTime)
{
    tbResult r = TB_OK;

    tbDirectInput::Instance().GetState(g_pfButtons, g_pbButtons);

    switch(m_GameStat)
    {
    case GS_INTRO:     m_pIntro->Move(fTime);
    case GS_MAINMENU:  m_pMainMenu->Move(fTime);
  //case GS_GAME:      m_pGame->Move(fTime);

    }

    if(r) TB_ERROR("Fehler beim Bewegen des Spiels", TB_ERROR);

    m_fTime += fTime;

    return TB_OK;
}

tbResult CTicTacToe::Render(float fTime)
{
    if(tbDirect3D::Instance().GetPresentResult())
    {
        // Anzeigen ist fehlgeschlagen!

        // Wahrscheinlich läuft das Programm im Vollbildmodus und es

        // wurde zwischenzeitlich minimiert.

        // Wir initialisieren das Spiel komplett neu.


        // Aktuellen Spielzustand entladen

        switch(m_GameStat)
        {
        case GS_INTRO:      m_pIntro->Unload();     break;
        case GS_MAINMENU:   m_pMainMenu->Unload();  break;
        //case GS_GAME:     m_pGame->Unload();      break;

        }

        // Das ganze Spiel entladen und dann wieder neu laden

        Unload();
        Load();

        // Aktuellen Spielstatus neu laden

        switch(m_GameStat)
        {
        case GS_INTRO:      m_pIntro->Load();       break;
        case GS_MAINMENU:   m_pMainMenu->Load();    break;
        //case GS_GAME:     m_pGame->Load();        break;

        }
    }
    tbResult r = TB_OK;

    switch(m_GameStat)
    {
    case GS_INTRO:     m_pIntro->Render(fTime);
    case GS_MAINMENU:  m_pMainMenu->Render(fTime);
    //case GS_GAME:      m_pGame->Render(fTime);

    }

    if(r) TB_ERROR("Fehler beim Zeichnen des Spiels", TB_ERROR);

    return TB_OK;
}

TicTacToe.h

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
#include <TriBase.h>
#include "Intro.h"
#include "MainMenu.h"
#include "Game.h"

enum EGameStat
{
    GS_NONE,
    GS_INTRO,
    GS_MAINMENU,
    GS_GAME
};

class CTicTacToe
{
public:
    tbConfig m_Config;
    PDIRECT3DSTATEBLOCK9    m_pStateBlock;

    CIntro*     m_pIntro;
    CMainMenu*  m_pMainMenu;
    CGame*      m_pGame;
    EGameStat   m_GameStat;
    float       m_fTime;

    tbFont* m_pFont;

    tbResult Init();
    tbResult Exit();
    tbResult Load();
    tbResult Unload();
    tbResult Run();
    tbResult SetGameStat(EGameStat NewGameStat);
    tbResult Move(float fTime);
    tbResult Render(float fTime);
};

extern CTicTacToe*  g_pTicTacToe;
extern float*       g_pfButtons;
extern BOOL*        g_pbButtons;

Intro.cpp

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
#include "TicTacToe.h" 

struct STitleVertex
{
    tbVector3           vPosition;
    float               fRHW;
    D3DCOLOR            Color;
    tbVector2           vTex0;
    static const DWORD  dwFVF;
};

const DWORD STitleVertex::dwFVF = D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1;

tbResult CIntro::Init()
{
    if(Load()) TB_ERROR("Fehler beim Laden des Spielzustands", TB_ERROR);

    return TB_OK;
}

tbResult CIntro::Exit()
{
    Unload();

    return TB_OK;
}

tbResult CIntro::Load()
{
    m_pBackground = tbTextureManager::Instance().GetTexture("Data\\Bild.jpg");
    if(m_pBackground == NULL) TB_ERROR("Fehler beim Laden der Texturen", TB_ERROR);
    return TB_OK;
}

tbResult CIntro::Unload()
{
    tbTextureManager::Instance().ReleaseTexture(m_pBackground);
    return TB_OK;
}

tbResult CIntro::Move(float fTime)
{
    if(g_pbButtons[TB_KEY_RETURN] ||
       g_pbButtons[TB_KEY_SPACE])
    {
        tbDelay(100);
        g_pTicTacToe->SetGameStat(GS_MAINMENU);
    }
    return TB_OK;
}

tbResult CIntro::Render(float fTime)
{
    STitleVertex aVertex[4];

    tbDirect3D& D3D = tbDirect3D::Instance();
    D3D->Clear(0 , 0 , D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, tbColor(0.0f,0.0f,0.0f), 1.0f, 0);
    D3D->BeginScene();

    D3D.SetFVF(STitleVertex::dwFVF);
    D3D.SetTexture(0, m_pBackground);
    D3D.SetRS(D3DRS_ZENABLE, D3DZB_FALSE);

    aVertex[0].vPosition = tbVector3(0.0f, D3D.GetScreenSize().y, 0.5f);
    aVertex[0].fRHW = 1.0f;
    aVertex[0].Color = tbColor(1.0f, 0.8f, 0.8f);
    aVertex[0].vTex0 = tbVector2(0.0f, 1.0f);

    aVertex[1].vPosition = tbVector3(0.0f, 0.0f, 0.0f);
    aVertex[1].fRHW = 1.0f;
    aVertex[1].Color = tbColor(0.8f, 1.0f, 0.8f);
    aVertex[1].vTex0 = tbVector2(0.0f, 0.0f);

    aVertex[2].vPosition = tbVector3(D3D.GetScreenSize().x, D3D.GetScreenSize().y, 0.5f);
    aVertex[2].fRHW = 1.0f;
    aVertex[2].Color = tbColor(0.8f, 0.8f, 1.0f);
    aVertex[2].vTex0 = tbVector2(1.0f, 1.0f);

    aVertex[3].vPosition = tbVector3(D3D.GetScreenSize().x, 0.0f, 0.5f);
    aVertex[3].fRHW = 1.0f;
    aVertex[3].Color = tbColor(1.0f, 1.0f, 0.8f);
    aVertex[3].vTex0 = tbVector2(1.0f, 0.0f);

    D3D->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, aVertex, sizeof(STitleVertex));

    g_pTicTacToe->m_pFont->Begin();
    g_pTicTacToe->m_pFont->DrawText(tbVector2(0.5f, 0.5f), "Druecken Sie Enter", TB_FF_ALIGN_HCENTER | TB_FF_ALIGN_VCENTER | TB_FF_RELATIVE | TB_FF_RELATIVESCALING);
    g_pTicTacToe->m_pFont->End();

    D3D->EndScene();

    return TB_OK;
}

Intro.h

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<TriBase.h>
class CIntro
{
public:
  PDIRECT3DTEXTURE9 m_pBackground;

  inline CIntro() {ZeroMemory(this,sizeof(CIntro));}

  tbResult Init();
  tbResult Exit();
  tbResult Load();
  tbResult Unload();
  tbResult Move(float fTime);
  tbResult Render(float fTime);
};

MainMenu.cpp

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "TicTacToe.h"
struct SMainMenuVertex
{
    tbVector3           vPosition;
    float               fRHW;
    D3DCOLOR            Color;
    tbVector2           vTex0;
    static const DWORD  dwFVF;
};

const DWORD SMainMenuVertex::dwFVF = D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1;

tbResult CMainMenu::Init()
{
    if(Load()) TB_ERROR("Fehler beim Initialisieren des Menues", TB_ERROR);

    m_iCursor = 0;
    return TB_OK;
}

tbResult CMainMenu::Exit()
{
    Unload();
    return TB_OK;
}
tbResult CMainMenu::Load()
{
    m_pBackground = tbTextureManager::Instance().GetTexture("Data\\MainMenu.jpg");
    if(m_pBackground == NULL) TB_ERROR("Fehler beim Laden der Textur", TB_ERROR);

    return TB_OK;
}
tbResult CMainMenu::Unload()
{
    tbTextureManager::Instance().ReleaseTexture(m_pBackground);
    return TB_OK;
}
tbResult CMainMenu::Move(float fTime)
{
    if(g_pbButtons[TB_KEY_UP])
    {
        m_iCursor++; 
        tbDelay(80);
    }
    if(g_pbButtons[TB_KEY_DOWN]) 
    {
        m_iCursor--; 
        tbDelay(80);
    }
    if(m_iCursor > 2) m_iCursor = 0;
    if(m_iCursor < 0) m_iCursor = 1;
    if(g_pbButtons[TB_KEY_SPACE]||g_pbButtons[TB_KEY_RETURN])
    {
        switch(m_iCursor)
        {
        case 0: PostQuitMessage(0);
            break;
        case 1: PostQuitMessage(0);
            break;
        }
    }

    return TB_OK;
}
tbResult CMainMenu::Render(float fTime)
{
    SMainMenuVertex aVertex[4];
    char*               MenuEntry[2] = {"Spiel starten",                                     
                                        "Spiel beenden"};
    tbVector2           vPosition;
    tbColor             Color;

    tbDirect3D& D3D = tbDirect3D::Instance();
    D3D->Clear(0 , 0 , D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, tbColor(0.0f,0.0f,0.0f), 1.0f, 0);
    D3D->BeginScene();

    D3D.SetFVF(SMainMenuVertex::dwFVF);
    D3D.SetTexture(0, m_pBackground);
    D3D.SetRS(D3DRS_ZENABLE, D3DZB_FALSE);

    aVertex[0].vPosition = tbVector3(0.0f, D3D.GetScreenSize().y, 0.5f);
    aVertex[0].fRHW = 1.0f;
    aVertex[0].Color = tbColor(1.0f, 0.8f, 0.8f);
    aVertex[0].vTex0 = tbVector2(0.0f, 1.0f);

    aVertex[1].vPosition = tbVector3(0.0f, 0.0f, 0.0f);
    aVertex[1].fRHW = 1.0f;
    aVertex[1].Color = tbColor(0.8f, 1.0f, 0.8f);
    aVertex[1].vTex0 = tbVector2(0.0f, 0.0f);

    aVertex[2].vPosition = tbVector3(D3D.GetScreenSize().x, D3D.GetScreenSize().y, 0.5f);
    aVertex[2].fRHW = 1.0f;
    aVertex[2].Color = tbColor(0.8f, 0.8f, 1.0f);
    aVertex[2].vTex0 = tbVector2(1.0f, 1.0f);

    aVertex[3].vPosition = tbVector3(D3D.GetScreenSize().x, 0.0f, 0.5f);
    aVertex[3].fRHW = 1.0f;
    aVertex[3].Color = tbColor(1.0f, 1.0f, 0.8f);
    aVertex[3].vTex0 = tbVector2(1.0f, 0.0f);

    D3D->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, aVertex, sizeof(SMainMenuVertex));
    //__________________________________________________________________________________//

    g_pTicTacToe->m_pFont->Begin();
    for(int iEntry = 0; iEntry < 2; iEntry++)
    {
    vPosition.x = 0.5f;
    vPosition.y = 0.4f + (float)(iEntry) * 0.125f;
    if(m_iCursor == iEntry)
    {
        Color = tbColor(0.3f,0.8f,0.0f);
    }
    else
    {
        Color = tbColor(0.5f,0.0f,0.0f);
    }
    g_pTicTacToe->m_pFont->DrawText(vPosition,MenuEntry[iEntry],TB_FF_ALIGN_HCENTER | TB_FF_ALIGN_HCENTER | TB_FF_RELATIVE | TB_FF_RELATIVESCALING,
                                    -1, Color, Color, tbVector2(1.5f, 1.5f));
    }
    g_pTicTacToe->m_pFont->End();

    D3D->EndScene();
    return TB_OK;
}

MainMenu.h

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<TriBase.h>

class CMainMenu
{
public:
    PDIRECT3DTEXTURE9 m_pBackground;
    int m_iCursor;

    inline CMainMenu() {ZeroMemory(this, sizeof(CMainMenu));}

    tbResult Init();
    tbResult Exit();
    tbResult Load();
    tbResult Unload();
    tbResult Move(float fTime);
    tbResult Render(float fTime);
};


mfg

carli

unregistriert

2

16.11.2009, 17:00

ist es hier so üblich, dass man Seitenweise Quelltext postet?
Wenn ja, ich geb euch mal mein Projekt (20.000 Zeilen aufwärts) ;)

GR-PA

Treue Seele

Beiträge: 326

Wohnort: Daheim

Beruf: Faulenzer

  • Private Nachricht senden

3

16.11.2009, 17:00

C-/C++-Quelltext

1
2
3
4
5
6
switch(m_GameStat)
    {
    case GS_INTRO:     m_pIntro->Move(fTime);
    case GS_MAINMENU:  m_pMainMenu->Move(fTime);
  //case GS_GAME:      m_pGame->Move(fTime);

    } 

die Lösung heißt: break; ...
;)

Hier genauso:

C-/C++-Quelltext

1
2
3
4
5
6
switch(m_GameStat)
    {
    case GS_INTRO:     m_pIntro->Render(fTime);
    case GS_MAINMENU:  m_pMainMenu->Render(fTime);
    //case GS_GAME:      m_pGame->Render(fTime);

    } 
Signaturen werden überbewertet

4

16.11.2009, 17:10

@crali: Ich weiß nicht. Mach es erst zum zweiten Mal. Sollte ich die lieber irgendwo uploaden?
@GR-PA: Vielen Dank! So klappt's. =)

NachoMan

Community-Fossil

Beiträge: 3 885

Wohnort: Berlin

Beruf: (Nachhilfe)Lehrer (Mathematik, C++, Java, C#)

  • Private Nachricht senden

5

16.11.2009, 17:14

naja meistens kann man den fehler mit logischen denken eingrenzen(besonders bei objektorientierten quellcode)... dann brauchst du nicht alles posten.
"Der erste Trunk aus dem Becher der Erkenntnis macht einem zum Atheist, doch auf dem Grund des Bechers wartet Gott." - Werner Heisenberg
Biete Privatunterricht in Berlin und Online.
Kommt jemand mit Nach oMan?

GR-PA

Treue Seele

Beiträge: 326

Wohnort: Daheim

Beruf: Faulenzer

  • Private Nachricht senden

6

16.11.2009, 17:41

Oder du kannst deinen Code hier hochladen.
Signaturen werden überbewertet

7

16.11.2009, 18:08

sagen wir mal so: die wenigsten leute haben bock, seitenweise Quelltext durchzukauen, um einen fehler in deinem ersten programm zu finden. Das erste was du lernen soltlest, ist deshalb, den fehler auf eine überschaubare menge quelltext einzugrenzen, wenn z.B. das Intro übersprungen wird, wäre der entsprechende stelle die Zeile, die das intro anzeigen soll, sowie die definitionen und relevanten änderungen aller objekten, die ausschließlich dafür, bzw. an dieser Stelle zum ersten mal sichtbar verwendet werden.

8

16.11.2009, 20:46

Alles klar. Ich werd's versuchen.

mfg

9

16.11.2009, 21:33

Noch mal eine Frage:
Wie kann man ein Model nach träglich texturieren?

Also ich möchte es gerne laden.
Dann etwas damit machen und es zu einem bestimmten
Zeitpunkt texturieren.
Geht das?

mfg

10

16.11.2009, 21:37

Machst halt im ModellConverter zwei effekte.
Der erste ist der Ganz normale, der Zweite einer, der keine Texturen setzt.
Dann bei Model->Render () entsprechendes bei iFrom und iTo, also mit Texturen Render (0, 1, ...) ohne (1, 2) oder sowas.

Werbeanzeige