Hallo ich habe folgendes Problem meine Sprites werden nicht angezeigt.
Die Parameter sind alle korrekt. Und das Sprite sollte auch oft genug gerendert werden 10sek lang. Und es bleib wärend diesen 10sek immer im Bildschirm trozdem sehe ich nichts.
Sprite Class:
|
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
|
#ifndef PARTIKEL2D_H_
#define PARTIKEL2D_H_
#ifdef WIN32
#include <SDL.h>
#include <SDL_opengl.h>
#else
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
#endif
#include "../../extLibs/Vector2D.h"
#include "../fkrClockManager.h"
#include "../fkrRenderManager.h"
class CPartikel2D {
public:
CPartikel2D();
~CPartikel2D();
void Init(Vector2D<float> vPosition, Vector2D<float> m_fSpeed, Vector2D<float> fSpeedUp, SDL_Color cColor/*, SDL_Color cEndColor*/, Vector2D<float> fSize, Vector2D<float> fSizeUp, float fLifeTime);
void Update();
void Render();
bool IsDead() { return m_bIsDead; }
protected:
Vector2D<float> m_vPosition;
Vector2D<float> m_fSpeed;
Vector2D<float> m_fSpeedUp;
SDL_Color m_cColor;
//SDL_Color m_cEndColor;
Vector2D<float> m_fSize;
Vector2D<float> m_fSizeUp;
float m_fLifeTime;
bool m_bIsDead;
};
#endif /*PARTIKEL2D_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
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
|
#include "../includes/build.h"
#ifdef OPENGL
#include "../includes/opengl/Partikel2D.h"
CPartikel2D::CPartikel2D() {
}
CPartikel2D::~CPartikel2D() {
}
void CPartikel2D::Init(Vector2D<float> vPosition, Vector2D<float> fSpeed, Vector2D<float> fSpeedUp, SDL_Color cColor/*, SDL_Color cEndColor*/, Vector2D<float> fSize, Vector2D<float> fSizeUp, float fLifeTime) {
m_vPosition = vPosition;
m_fSpeed = fSpeed;
m_fSpeedUp = fSpeedUp;
m_fSize = fSize;
m_fSizeUp = fSizeUp;
m_cColor = cColor;
//m_cEndColor = cEndColor;
m_fLifeTime = fLifeTime;
//Umwandeln der Koordinaten
m_vPosition.y = g_pFkrRenderManager->GetHeight() - m_vPosition.y;
m_bIsDead = false;
}
void CPartikel2D::Update() {
if(m_bIsDead) return;
float framerate = g_pClock->GetFrameRateM();
m_fSpeed.x += (m_fSpeedUp.x/framerate);
m_fSpeed.y += (m_fSpeedUp.y/framerate);
m_fSize.x += (m_fSizeUp.x/framerate);
m_fSize.y += (m_fSizeUp.y/framerate);
m_vPosition.x += (m_fSpeed.x/framerate);
m_vPosition.y += (m_fSpeed.y/framerate);
m_fLifeTime -= (1.0f/framerate);
if(m_fLifeTime<=0.0f) {
m_bIsDead = true;
}
}
void CPartikel2D::Render() {
if(m_bIsDead) return;
float fRed = 1.0f / 255.0f * (float)m_cColor.r;
float fGreen = 1.0f / 255.0f * (float)m_cColor.g;
float fBlue = 1.0f / 255.0f * (float)m_cColor.b;
//glPushMatrix();
glEnable(GL_BLEND);
glColor3f(fRed,fGreen,fBlue);
glBegin(GL_QUADS);
glVertex2f(m_vPosition.x, m_vPosition.y);
glVertex2f(m_vPosition.x+m_fSize.x, m_vPosition.y);
glVertex2f(m_vPosition.x+m_fSize.x, m_vPosition.y+m_fSize.y);
glVertex2f(m_vPosition.x, m_vPosition.y+m_fSize.y);
glEnd();
//glPopMatrix();
glDisable(GL_BLEND);
}
#endif
|
Die Aufrufs Klasse:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#ifndef EXPLOSION_H_
#define EXPLOSION_H_
#include <fkrLib.h>
class CExplosion {
public:
void Init(float posX, float posY, float lifetime, int anzPartikel);
void UpdateAndRender();
void CleanUp();
bool IsExplosion() { if(m_iAnzPartikel>0) return true; else return false; }
protected:
vector<CPartikel2D*> m_vPartikel;
int m_iAnzPartikel;
Vector2D<float> m_vPosition;
};
#endif /*EXPLOSION_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
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
|
#include "Explosion.h"
void CExplosion::Init(float posX, float posY, float lifetime, int anzPartikel) {
m_iAnzPartikel = anzPartikel;
m_vPosition.x = posX;
m_vPosition.y = posY;
SDL_Color cColor;
Vector2D<float> fSpeed;
Vector2D<float> fSpeedUp;
Vector2D<float> fSize;
Vector2D<float> fSizeUp;
fSpeedUp.x = -50;
fSpeedUp.y = -50;
fSizeUp.x = -2;
fSizeUp.y = -2;
for(int i=0;i<m_iAnzPartikel;i++) {
CPartikel2D* tmpPartikel = new CPartikel2D();
//Farben Generiern
int tmpColor = rand() % 255 + 1;
cColor.r = tmpColor;
tmpColor = rand() % 255 + 1;
cColor.g = tmpColor;
tmpColor = rand() % 255 + 1;
cColor.b = tmpColor;
//Geschwindigkeit und beschleunigung
tmpColor = rand() % 2;
float tmpSpeed = rand() % 300 + 100;
if(tmpColor==0) fSpeed.x = tmpSpeed; else fSpeed.x = tmpSpeed*-1;
tmpColor = rand() % 2;
tmpSpeed = rand() % 300 + 100;
if(tmpColor==0) fSpeed.y = tmpSpeed; else fSpeed.y = tmpSpeed*-1;
//Die Größe
tmpSpeed = rand() % 32 + 16;
fSize.x = tmpSpeed;
tmpSpeed = rand() % 32 + 16;
fSize.y = tmpSpeed;
tmpPartikel->Init(m_vPosition, fSpeed, fSpeedUp, cColor, fSize, fSizeUp, lifetime);
m_vPartikel.push_back(tmpPartikel);
}
}
void CExplosion::CleanUp() {
vector<CPartikel2D*>::iterator it;
for(it = m_vPartikel.begin(); it != m_vPartikel.end(); it++) {
delete *it;
}
m_vPartikel.clear();
m_iAnzPartikel = 0;
}
void CExplosion::UpdateAndRender() {
vector<CPartikel2D*>::iterator it;
bool newIT = false;
for(it = m_vPartikel.begin(); it != m_vPartikel.end(); ) {
if(newIT)
it++;
else
newIT=true;
if(it==m_vPartikel.end())
break;
if((*it)->IsDead()) {
delete *it;
it = m_vPartikel.erase(it);
newIT = false;
}
else {
(*it)->Update();
(*it)->Render();
}
}
}
|
Der Aufruf im Spiel selber:
|
C-/C++-Quelltext
|
1
2
3
4
5
|
if(g_pInputManager->IsKeyPressed(KEY_SPACE)) {
if(m_eTestExplosion.IsExplosion())
m_eTestExplosion.CleanUp();
m_eTestExplosion.Init(g_pInputManager->GetMousePos().x, g_pInputManager->GetMousePos().y, 10, 50);
}
|
Die Render Methode wird aufgerufen. Das habe ich getestete. Die Init Methode auch.