我已经查看了有关此错误的其他问题,但它们并没有帮助我。我还是 C++ 的新手,我不知道我是否误解了某些东西,滥用了某些东西,或者只是缺少某些东西,但我不知道是什么,我需要一些帮助。我得到的错误是
SpriteImage 没有命名类型
精灵.cpp
#include "Sprite.h"
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <iostream>
#include <vector>
namespace ColdFusion
{
Sprite::Sprite()
{
bufferSize = 100;
}
void Sprite::addToBuffer(SpriteImage img)
{
if(SpriteBuffer->size() == bufferSize)
{
bufferSize *= 2;
SpriteBuffer->resize(bufferSize);
}
SpriteBuffer->push_back(img);
}
SpriteImage Sprite::getFromBuffer(int index) //**Here is the error**
{
return SpriteBuffer[index];
}
void Sprite::removeFromBuffer(int index)
{
SpriteBuffer->erase(SpriteBuffer.begine()+index);
}
void Sprite::removeFromBuffer(SpriteImage index)
{
for(int j = 0; j <= SpriteBuffer->size(); j++)
{
if(SpriteBuffer[j].name == index.name)
{
removeFromBuffer(j);
}
}
}
void Sprite::applyToScreen(SpriteImage img, SDL_Surface* destination)
{
applyImage(img.x, img.y,getImage(img.filepath),destination)
}
SDL_Surface* Sprite::getImage(std::string filepath)
{
SDL_Surface* optimized = NULL;
SDL_Surface* loaded = NULL;
loaded = IMG_Load(filepath.c_str());
if(loaded != NULL)
{
optimized = SDL_DisplayFormat(loaded);
SDL_FreeSurface(loaded);
return optimized;
}
return NULL;
}
void Sprite::applyImage(int x, int y, SDL_Surface* source, SDL_Surface* destination)
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface(source, NULL, destination, &offset);
}
Sprite::~Sprite()
{
}
}
精灵.h
#ifndef SPRITE_H
#define SPRITE_H
#include "SDL/SDL.h"
#include <iostream>
#include <vector>
namespace ColdFusion
{
class Sprite
{
public:
Sprite();
~Sprite();
typedef struct SpriteImage{
int x;
int y;
std::string name;
std::string filepath;
};
void addToBuffer(SpriteImage img);
SpriteImage getFromBuffer(int index);
void removeFromBuffer(int index);
void removeFromBuffer(SpriteImage index);
void applyToScreen(SpriteImage img, SDL_Surface* destination);
protected:
private:
int bufferSize;
std::vector<SpriteImage> SpriteBuffer[100];
SDL_Surface* image;
SDL_Surface* getImage(std::string filepath);
void applyImage(int x, int y, SDL_Surface* source, SDL_Surface* destination);
};
}
#endif