Skip to content

Commit 5d2df79

Browse files
committed
Stores the size of the decal inside itself. Allows drawing the decal without accessing the sprite and makes it safe to move the sprite used to create de decal.
Update function from decal will also update the size to match the used sprite. UpdateSprite will resize the sprite to the size of the decal.
1 parent 06fc0f8 commit 5d2df79

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

olcPixelGameEngine.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,8 @@ namespace olc
11011101

11021102
public: // But dont touch
11031103
int32_t id = -1;
1104+
int32_t width = 0;
1105+
int32_t height = 0;
11041106
olc::Sprite* sprite = nullptr;
11051107
olc::vf2d vUVScale = { 1.0f, 1.0f };
11061108
};
@@ -2026,6 +2028,8 @@ namespace olc
20262028
{
20272029
id = -1;
20282030
if (spr == nullptr) return;
2031+
width = spr->width;
2032+
height = spr->height;
20292033
sprite = spr;
20302034
id = renderer->CreateTexture(sprite->width, sprite->height, filter, clamp);
20312035
Update();
@@ -2040,14 +2044,17 @@ namespace olc
20402044
void Decal::Update()
20412045
{
20422046
if (sprite == nullptr) return;
2043-
vUVScale = { 1.0f / float(sprite->width), 1.0f / float(sprite->height) };
2047+
width = sprite->width;
2048+
height = sprite->height;
2049+
vUVScale = { 1.0f / float(width), 1.0f / float(height) };
20442050
renderer->ApplyTexture(id);
20452051
renderer->UpdateTexture(id, sprite);
20462052
}
20472053

20482054
void Decal::UpdateSprite()
20492055
{
20502056
if (sprite == nullptr) return;
2057+
sprite->SetSize(width, height);
20512058
renderer->ApplyTexture(id);
20522059
renderer->ReadTexture(id, sprite);
20532060
}
@@ -3227,8 +3234,8 @@ namespace olc
32273234

32283235
olc::vf2d vScreenSpaceDim =
32293236
{
3230-
vScreenSpacePos.x + (2.0f * (float(decal->sprite->width) * vInvScreenSize.x)) * scale.x,
3231-
vScreenSpacePos.y - (2.0f * (float(decal->sprite->height) * vInvScreenSize.y)) * scale.y
3237+
vScreenSpacePos.x + (2.0f * (float(decal->width) * vInvScreenSize.x)) * scale.x,
3238+
vScreenSpacePos.y - (2.0f * (float(decal->height) * vInvScreenSize.y)) * scale.y
32323239
};
32333240

32343241
DecalInstance di;

0 commit comments

Comments
 (0)