Defects in Tilesheet.drawTiles

1. In flash version, rotation behaves weird, image are stretched. 2. In flash version, the non-transformed (that means useScale & useRotation etc. are all false) tiles are drawed without considering the center point.

  • Forums
  • »
  • Bugs
  • »
  • Defects in Tilesheet.drawTiles
Viewing 1 to 13 (13 Total)
Defects in Tilesheet.drawTiles

rocks

rocks
Total Posts: 35
Joined: October 10, 2011

1. In flash version, rotation behaves weird, image are stretched.
2. In flash version, the non-transformed (that means useScale & useRotation etc. are all false) tiles are drawed without considering the center point.

Tags:
Posted on February 08, 2012 at 12:48 AM

rocks

rocks
Total Posts: 35
Joined: October 10, 2011

Re: Defects in Tilesheet.drawTiles

My fix to defect1:
...
if (rotation != 0)
{
var kx = tilePoint.x * tileWidth;
var ky = tilePoint.y * tileHeight;
var akx = (1 - tilePoint.x) * tileWidth;
var aky = (1 - tilePoint.y) * tileHeight;
var ca = Math.cos(rotation);
var sa = Math.sin(rotation);
var xc = kx * ca, xs = kx * sa, yc = ky * ca, ys = ky * sa;
var axc = akx * ca, axs = akx * sa, ayc = aky * ca, ays = aky * sa;
vertices[offset8] = x - (xc + ys);
vertices[offset8 + 1] = y - (-xs + yc);
vertices[offset8 + 2] = x + axc - ys;
vertices[offset8 + 3] = y - (axs + yc);
vertices[offset8 + 4] = x - (xc - ays);
vertices[offset8 + 5] = y + xs + ayc;
vertices[offset8 + 6] = x + axc + ays;
vertices[offset8 + 7] = y + (-axs + ayc);
}
...

Posted on February 08, 2012 at 3:25 AM

rocks

rocks
Total Posts: 35
Joined: October 10, 2011

Re: Defects in Tilesheet.drawTiles

My fix to defect 2:
...
var tile = tiles[tileID];
var centerPoint = tilePoints[tileID];
var ox = centerPoint.x * tile.width, oy = centerPoint.y * tile.height;

var scale = 1.0;
var rotation = 0.0;
var alpha = 1.0;

matrix.tx = x - tile.x - ox;
matrix.ty = y - tile.y - oy;

// need to add support for rotation, alpha, scale and RGB

graphics.beginBitmapFill (nmeBitmap, matrix, false, smooth);
graphics.drawRect (x - ox, y - oy, tile.width, tile.height);
...

Posted on February 08, 2012 at 3:26 AM

Philippe

Philippe
Total Posts: 261
Joined: September 08, 2011

Re: Defects in Tilesheet.drawTiles

Thanks for the patch, it seems to work fine smiling

Posted on February 08, 2012 at 9:57 AM

rocks

rocks
Total Posts: 35
Joined: October 10, 2011

Re: Defects in Tilesheet.drawTiles

I've just made some changes in Tilesheet.hx to fix these two defects for flash target, and I also added an implementation of color-transform (i.e. to enable TILE_RGB & TILE_ALPHA flags). It's doing the color-transform on the copies of original bitmap data, so might not be a fast approach, but at least now drawTiles behaves the same across the targets.
Please see attachment.

Attachments: Tilesheet.hx.txt
Posted on February 08, 2012 at 10:06 AM

Philippe

Philippe
Total Posts: 261
Joined: September 08, 2011

Re: Defects in Tilesheet.drawTiles

Ah interesting approach of the color transforms.

Actually I had the idea to keep a single bitmap but to pre-compute a few alpha/colors inside a larger bitmap so you keep one image and one batch draw and limit the number of copies of the original bitmap - then the renderer would figure the closest copy of the bitmap to use.

Posted on February 08, 2012 at 10:18 AM

singmajesty

singmajesty
Total Posts: 2147
Joined: August 25, 2011

Re: Defects in Tilesheet.drawTiles

Thanks! I've just integrated these changes into SVN.

Also, I updated the settings for the site, so it should allow Haxe file attachments without having to change the extension smiling

Posted on February 08, 2012 at 11:13 AM

rocks

rocks
Total Posts: 35
Joined: October 10, 2011

Re: Defects in Tilesheet.drawTiles

Hi, please use this optimized version.

Attachments: Tilesheet.hx
Posted on February 10, 2012 at 3:23 AM

Philippe

Philippe
Total Posts: 261
Joined: September 08, 2011

Re: Defects in Tilesheet.drawTiles

@rocks, as much as your fix were totally correct, I don't think the coloring solution is good as is: it's kind of clever but just not efficient and still broken.
I've tried it in my nme-bunnymark and:
- it's running massively slower,
- only one (the last?) bunny is visible.

Another (minor) problem is whitespace: your class mixes space and tabs indentation.

Posted on February 10, 2012 at 7:29 AM

rocks

rocks
Total Posts: 35
Joined: October 10, 2011

Re: Defects in Tilesheet.drawTiles

Thanks Philippe,
Have you tried the optimized version? in this version the copy copying is change-based, while in previous version it's frame-based.
Yes even after the optimization, it's still a slow approach, I'm thinking about your idea.
I cannot re-produce the defect - only one (the last?) bunny is visible, can you please send me your project for testing? Thanks!
Here's my email: rockswang@gmail.com

Posted on February 10, 2012 at 12:55 PM

Philippe

Philippe
Total Posts: 261
Joined: September 08, 2011

Re: Defects in Tilesheet.drawTiles

I did try the latest version of your class.

The project is here:
http://github.com/elsassph/nme-bunnymark...

It uses lots of alpha levels and a large quantity of tiles, but the tilesheet is tiny compared to a real world project where you can count on a 2048x2048 PNG with many tiles.

Posted on February 10, 2012 at 1:28 PM

rocks

rocks
Total Posts: 35
Joined: October 10, 2011

Re: Defects in Tilesheet.drawTiles

Hi,
Thanks for the benchmark project, it's really helpful.
I've fixed the defect, now in my machine the demo runs on 55~60 fps with 250 bunnies, approximately 1/10 of neko target (I can get 55~60 fps in neko with 2500 bunnies).
I've attached the fix as an interim solution, and I am thinking about a faster way, maybe a big image cache of the most frenquently used tiles, so that the render can be done in one or several drawTriangles calls.

Rocks

Attachments: Tilesheet.hx
Posted on February 11, 2012 at 9:56 AM

rocks

rocks
Total Posts: 35
Joined: October 10, 2011

Re: Defects in Tilesheet.drawTiles

Hi,
Thanks for the benchmark project, it's really helpful.
I've fixed the defect, now in my machine the demo runs on 55~60 fps with 250 bunnies, approximately 1/10 of neko target (I can get 55~60 fps in neko with 2500 bunnies).
I've attached the fix as an interim solution, and I am thinking about a faster way, maybe a big image cache of the most frenquently used tiles, so that the render can be done in one or several drawTriangles calls.

Rocks

Posted on February 11, 2012 at 10:00 AM