Skip to content

Commit

Permalink
Merge pull request #1258 from lairworks/spriteDelegate
Browse files Browse the repository at this point in the history
Add `Sprite` constructors taking a `Delegate`
  • Loading branch information
DanRStevens authored Mar 3, 2025
2 parents e600f8f + a63c25f commit 10cc6bc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 14 additions & 0 deletions NAS2D/Resource/Sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ Sprite::Sprite(const AnimationSet& animationSet, const std::string& initialActio
}


Sprite::Sprite(const std::string& filePath, const std::string& initialAction, Delegate<void()> animationCompleteHandler) :
Sprite(filePath, initialAction)
{
mAnimationCompleteSignal.connect(animationCompleteHandler);
}


Sprite::Sprite(const AnimationSet& animationSet, const std::string& initialAction, Delegate<void()> animationCompleteHandler) :
Sprite(animationSet, initialAction)
{
mAnimationCompleteSignal.connect(animationCompleteHandler);
}


Vector<int> Sprite::size() const
{
return (*mCurrentAction)[mCurrentFrame].bounds.size;
Expand Down
8 changes: 6 additions & 2 deletions NAS2D/Resource/Sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
#pragma once

#include "AnimationSet.h"
#include "../Signal/Signal.h"
#include "../Timer.h"
#include "../Math/Angle.h"
#include "../Renderer/Color.h"
#include "../Signal/Signal.h"
#include "../Signal/Delegate.h"

#include <vector>
#include <string>
Expand All @@ -35,9 +36,12 @@ namespace NAS2D

Sprite(const std::string& filePath, const std::string& initialAction);
Sprite(const AnimationSet& animationSet, const std::string& initialAction);
Sprite(const std::string& filePath, const std::string& initialAction, Delegate<void()> animationCompleteHandler);
Sprite(const AnimationSet& animationSet, const std::string& initialAction, Delegate<void()> animationCompleteHandler);
Sprite(const Sprite&) = default;
Sprite(Sprite&&) = default;
const Sprite& operator=(const Sprite&) = delete;

Sprite& operator=(const Sprite&) = delete;
Sprite& operator=(Sprite&&) = delete;

Vector<int> size() const;
Expand Down

0 comments on commit 10cc6bc

Please sign in to comment.