X Tutup
Skip to content
This repository was archived by the owner on Jan 4, 2023. It is now read-only.

Commit cce4e71

Browse files
committed
Fixing tilemap drawing issues (#458 and #456) plus reverted logic to fix screenshot issue (#457).
1 parent 6aa7fb6 commit cce4e71

File tree

3 files changed

+61
-49
lines changed

3 files changed

+61
-49
lines changed

SDK/Player/Chips/Game/GameChip.Draw.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void DrawSprite(int id, int x, int y, bool flipH = false,
153153

154154
if (drawMode == DrawMode.Tile)
155155
{
156-
Tile(x, y, id, colorOffset);
156+
Tile(x, y, id, colorOffset, null, flipH, flipV);
157157
}
158158
else
159159
{

SDK/Player/Chips/Game/GameChip.MetaSprite.cs

Lines changed: 59 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -189,53 +189,57 @@ public void DrawMetaSprite(SpriteCollection spriteCollection, int x, int y, bool
189189
var total = tmpSpritesData.Count;
190190
var id = 0;
191191

192-
// When rendering in Tile Mode, switch to grid layout
193-
if (drawMode == DrawMode.Tile)
194-
{
195-
// TODO added this so C# code isn't corrupted, need to check performance impact
196-
if (tmpIDs.Length != total) Array.Resize(ref tmpIDs, total);
197-
198-
var i = 0;
199-
200-
for (i = 0; i < total; i++)
201-
{
202-
tmpIDs[i] = tmpSpritesData[i].Id;
203-
}
204-
205-
var width = (int)Math.Ceiling((double)spriteCollection.Bounds.Width / SpriteChip.DefaultSpriteSize);
206-
207-
var height = (int)Math.Ceiling((double)total / width);
208-
209-
if (flipH || flipV) Utilities.FlipPixelData(ref tmpIDs, width, height, flipH, flipV);
210-
211-
// TODO need to offset the bounds based on the scroll position before testing against it
212-
for (i = 0; i < total; i++)
213-
{
214-
// Set the sprite id
215-
id = tmpIDs[i];
216-
217-
// TODO should also test that the sprite is not greater than the total sprites (from a cached value)
218-
// Test to see if the sprite is within range
219-
if (id > -1)
220-
{
221-
var pos = CalculatePosition(i, width);
222-
223-
DrawSprite(
224-
id,
225-
pos.X + x,
226-
pos.Y + y,
227-
flipH,
228-
flipV,
229-
drawMode,
230-
_currentSpriteData.ColorOffset + colorOffset);
231-
}
232-
}
233-
}
234-
else
235-
{
192+
// // When rendering in Tile Mode, switch to grid layout
193+
// if (drawMode == DrawMode.Tile)
194+
// {
195+
// // TODO added this so C# code isn't corrupted, need to check performance impact
196+
// if (tmpIDs.Length != total) Array.Resize(ref tmpIDs, total);
197+
198+
// var i = 0;
199+
200+
// for (i = 0; i < total; i++)
201+
// {
202+
// tmpIDs[i] = tmpSpritesData[i].Id;
203+
// }
204+
205+
// var width = (int)Math.Ceiling((double)spriteCollection.Bounds.Width / SpriteChip.DefaultSpriteSize);
206+
207+
// var height = (int)Math.Ceiling((double)total / width);
208+
209+
// if (flipH || flipV) Utilities.FlipPixelData(ref tmpIDs, width, height, flipH, flipV);
210+
211+
// // TODO need to offset the bounds based on the scroll position before testing against it
212+
// for (i = 0; i < total; i++)
213+
// {
214+
// // Set the sprite id
215+
// id = tmpIDs[i];
216+
217+
// // TODO should also test that the sprite is not greater than the total sprites (from a cached value)
218+
// // Test to see if the sprite is within range
219+
// if (id > -1)
220+
// {
221+
// var pos = CalculatePosition(i, width);
222+
223+
// DrawSprite(
224+
// id,
225+
// pos.X + x,
226+
// pos.Y + y,
227+
// flipH,
228+
// flipV,
229+
// drawMode,
230+
// _currentSpriteData.ColorOffset + colorOffset);
231+
// }
232+
// }
233+
// }
234+
// else
235+
// {
236236

237237
int startX, startY;
238238
bool tmpFlipH, tmpFlipV;
239+
240+
var spriteSize = SpriteChip.DefaultSpriteSize;
241+
var width = spriteCollection.Bounds.Width;
242+
var height = spriteCollection.Bounds.Height;
239243

240244
// Loop through each of the sprites
241245
for (var i = 0; i < total; i++)
@@ -252,16 +256,24 @@ public void DrawMetaSprite(SpriteCollection spriteCollection, int x, int y, bool
252256

253257
if (flipH)
254258
{
255-
startX = spriteCollection.Bounds.Width - startX - SpriteSize().X;
259+
startX = width - startX - spriteSize;
256260
tmpFlipH = !tmpFlipH;
257261
}
258262

259263
if (flipV)
260264
{
261-
startY = spriteCollection.Bounds.Height - startY - SpriteSize().Y;
265+
startY = height - startY - spriteSize;
262266
tmpFlipV = !tmpFlipV;
263267
}
264268

269+
if (drawMode == DrawMode.Tile){
270+
271+
// Get sprite values
272+
startX = (int)Math.Ceiling((double)startX/ spriteSize);
273+
startY = (int)Math.Ceiling((double)startY / spriteSize);
274+
275+
}
276+
265277
startX += x;
266278
startY += y;
267279

@@ -276,7 +288,7 @@ public void DrawMetaSprite(SpriteCollection spriteCollection, int x, int y, bool
276288
);
277289
}
278290
}
279-
}
291+
// }
280292
}
281293
}
282294
}

SDK/Player/Chips/Graphics/TilemapChip.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ private void RebuildCache()
225225
// Draw the pixel data into the cachedTilemap
226226
Utilities.MergePixels(_tmpPixelData, 0, 0, _tileSize.Width, _tileSize.Height, _tilemapCache,
227227
_pos.X * _tileSize.Width, _pos.Y * _tileSize.Height, _tile.FlipH,
228-
_tile.FlipH, _tile.ColorOffset, false);
228+
_tile.FlipV, _tile.ColorOffset, false);
229229
}
230230
}
231231

0 commit comments

Comments
 (0)
X Tutup