Here is my code:

Code: Select all

```
#include "Graphics.h"
#include "Colors.h"
#include <assert.h>
#include <math.h>
namespace SpriteEffect
{
class Scale
{
public:
Scale(float scale = 1.0f)
:scale(scale)
{
assert(scale > 0.0f);
}
void operator()(Color sourceColor, int x, int y, Graphics& gfx)
{
if (sourceColor != chroma)
{
for (int dy = 0; dy < (int)ceil(scale); dy++)
{
for (int dx = 0; dx < (int)ceil(scale); dx++)
{
int resultX = (int)ceil(x * scale + dx);
int resultY = (int)ceil(y * scale + dy);
if (resultX < 0)
{
resultX = 0;
}
if (resultY < 0)
{
resultY = 0;
}
if (resultX >= gfx.ScreenWidth)
{
resultX = gfx.ScreenWidth - 1;
}
if (resultY >= gfx.ScreenHeight)
{
resultY = gfx.ScreenHeight - 1;
}
gfx.PutPixel(resultX, resultY, sourceColor);
}
}
}
}
private:
Color chroma = Colors::Magenta;
float scale;
};
}
```

Code: Select all

`gfx.DrawSprite(position.x, position.y, frames[currentFrame], surface, SpriteEffect::Scale(0.9f));`