OneLoneCoder/olcPixelGameEngine

'olc::Sprite::Sprite(const olc::Sprite &)': attempting to reference a deleted function

Kotambail-Hegde opened this issue · 3 comments

The below code snippet is causing the issue
class Sprite
{
public:
Sprite();
Sprite(const std::string& sImageFile, olc::ResourcePack* pack = nullptr);
Sprite(int32_t w, int32_t h);
Sprite(const olc::Sprite&) = delete;
~Sprite();

and the issue gets resolved, if the snippet is modified to
class Sprite
{
public:
Sprite();
Sprite(const std::string& sImageFile, olc::ResourcePack* pack = nullptr);
Sprite(int32_t w, int32_t h);
Sprite(const olc::Sprite&) = default;
~Sprite();

I believe this is a deliberate design choice by javid

A quote from javid himself, in response to a similar inquiry/request on the discord server

To deliberately discourage the copying of sprites
If you're copying sprites without thought, you've a significant design flaw

Edit: I've just been made aware of the Duplicate function which exists to allow those bent on making copies of sprite data. You can use that.

From olxPixelGameEngine.h, the olc::Sprite Delcaration

		olc::Sprite* Duplicate();
		olc::Sprite* Duplicate(const olc::vi2d& vPos, const olc::vi2d& vSize);

@Kotambail-Hegde I ran into this same issue when following the NES tutorial by Javidx9. Here's the notes of how you might deal with this situation. Mabye of use for you:

NES and PGE compatibility - olcSprite vars to pointers.pdf

Got it. Will look into "Duplicate" instead of using the Copy Constructor. I will close the issue since the design is intentional.
Thanks