【发布时间】:2017-02-27 03:49:49
【问题描述】:
所以我一直在关注使用 SFML 在 C++ 中开发游戏的视频教程,但遇到了错误。我在这个网站上描述了这个问题: http://en.sfml-dev.org/forums/index.php?topic=21589.0 (我知道我知道分享链接不好,但我不打算在不久的将来删除它。) 对于亮点,错误是: C:/Program Files/CodeBlocks/MinGW/lib/gcc/mingw32/4.9.2/include/c++/bits/stl_map.h:504:59:错误:没有匹配函数调用'Animation::Animation()'
我认为造成冲突的那一行是: std::map 动画列表;
我的 Animation 类及其功能如下所示: 类 Animation,然后是 public,然后是构造函数:
// Animation class
class Animation
{
public:
std::vector<IntRect> Frames, Frames_flip;
float CurrentFrame, Speed;
bool Flip, IsPlaying;
Sprite sprite;
Animation(Texture &t, int x, int y, int w, int h, int Count, float speed, int Step)
{
Speed = speed;
sprite.setTexture(t);
CurrentFrame = 0;
IsPlaying = true;
Flip = false;
for (int i = 0; i < Count; i++)
{
Frames.push_back( IntRect(x+i*Step,y,w,h));
Frames_flip.push_back( IntRect(x+i*Step+w,y,-w,h));
}
}
void Tick(float Time)
{
if (!IsPlaying) return;
CurrentFrame += Speed * Time;
if (CurrentFrame> Frames.size())
CurrentFrame -= Frames.size();
int i = CurrentFrame;
sprite.setTextureRect( Frames[i] );
if (Flip) sprite.setTextureRect( Frames_flip[i] );
}
};
// Animation Manager Class
class AnimationManager
{
public:
String CurrentAnim;
std::map<String, Animation> animList;
AnimationManager()
{
}
void Create(String Name, Texture &t, int x, int y, int w, int h, int Count, float Speed, int Step)
{
animList[Name] = Animation(t,x,y,w,h,Count,Speed,Step);
CurrentAnim = Name;
}
void Draw(RenderWindow &window, int x = 0, int y = 0)
{
animList[CurrentAnim].sprite.setPosition(x,y);
window.draw(animList[CurrentAnim].sprite);
}
void Set(String name) { CurrentAnim = name; }
void flip (bool b) { animList[CurrentAnim].Flip = b; }
void tick(float Time) {animList[CurrentAnim].Tick(Time); }
void pause () {animList[CurrentAnim].IsPlaying = false;}
void play () {animList[CurrentAnim].IsPlaying = true;}
};
【问题讨论】:
-
我认为造成冲突的那一行是:std::map animList; 那一行字面上并没有出现在你的代码中
-
你检查链接了吗,还有更多的代码。
-
没有。你检查How to Ask了吗?即,创建一个minimal reproducible example
-
抱歉,这看起来很刻薄,但这并不意味着 -_- 只是提供相关链接。相关代码应始终出现在您的问题中,而不是出现在可能出现故障等的第三方网站上
-
它会扩展成一个巨大的代码块,但我想这样就可以了。
标签: c++ codeblocks sfml