I've searched this forum for similar topics, but I haven't found any.
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
I'd like to know why? I'm asking because right now I have a problem, because of this little "const", here is a preview of this issue:
Wave.h
class Wave :
public sf::Drawable
{
private:
std::list<Enemy*> enemies;
[...]
public:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
}
In Wave.cpp I would like to draw every enemy in wave.
void Wave::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
std::list<Enemy*>::iterator temp = enemies.begin();
for(temp; temp != currentEnemy; temp++)
{
target.draw(**temp);
}
}
But there is an error:
Error 1 error C2440: 'initializing' : cannot convert from 'std::_List_const_iterator<_Mylist>' to 'std::_List_iterator<_Mylist>'
Looks like one does not simply iterate the const list. ;) (there is a problem with initializing iterator "std::list<Enemy*>::iterator temp = enemies.begin();", without const it works, but it cannot initiate abstract class)
If you have any advices how to workaround this problem, please write them.
PS
Is the AnimatedSprite (https://github.com/SFML/SFML/wiki/Source%3A-AnimatedSprite) included in standard version of SFML, or I have to copy it by myself?
PS2
Sorry for my lame English.
PS8
If the section on forum is wrong, please move this topic (I wasn't sure where to put it).
Try:
std::list<Enemy*>::const_iterator temp = enemies.begin();
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
I'd like to know why?
The reason for this const is always the same: The method does not modify the logical state of the object.
Assuming that the Wave class owns the enemies, is there a certain reason why you use std::list<Enemy*> and not std::list<Enemy>? If there is none, use the latter. It is much simpler and safer to handle, since you don't have to care about memory management.
Is the AnimatedSprite (https://github.com/SFML/SFML/wiki/Source%3A-AnimatedSprite) included in standard version of SFML, or I have to copy it by myself?
It is not part of SFML, same for the other codes on the Wiki. By the way, you could also have a look at the Animation module in Thor (http://www.bromeon.ch/libraries/thor/v2.0/doc/group___animation.html) -- it is slightly more complex, but allows also other animations than different texture rects, such as color gradients. It depends on what you need, I think to begin AnimatedSprite is a good choice.