Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Heaps #1

Closed
Redmega opened this issue Oct 2, 2019 · 4 comments
Closed

Using Heaps #1

Redmega opened this issue Oct 2, 2019 · 4 comments

Comments

@Redmega
Copy link
Contributor

Redmega commented Oct 2, 2019

Heaps doesn't have textures from bytes, so I'm doing a bit of a workaround here.

private static function createTile(bytes:Bytes, width:Int, height:Int, colorDepth:ColorDepth):Tile {
  return hxd.res.Any.fromBytes(bytes.toString(), bytes).toTile();
}

I get back what seems like valid data, but I'm unsure how to get the underlying tiles to work. I'm left with Error: Unsupported texture format from res.Any trying to resolve it as an Image.

I have no idea how to create a texture from the bytes and set its textureFormat based on the colorDepth returned.

@Redmega
Copy link
Contributor Author

Redmega commented Oct 5, 2019

Update:

Based on recommendations from the Haxe Discord (thanks to @potatoelixir), I have updated my code to use hxd.Pixels.

private static function createTile(bytes:Bytes, width:Int, height:Int, colorDepth:ColorDepth):Tile {
  var pixels = new Pixels(width, height, bytes, PixelFormat.RGBA);
  return Tile.fromPixels(pixels);
}

I'm no longer crashing, so I'm guessing something went right there. The RGBA pixel format is the only thing that worked properly, so I'm ignoring colorDepth for now. However, when rendering, I actually only get a single pink pixel. I'm assuming the next part of the problem exists in how I'm actually using the generated Aseprite instance.

  var tiles:Array<Tile> = [];

  // var tiles = FOBSpriteSheet.gridFlatten(32);

  Aseprite.parseFile(FOBSpriteBytes).frames.map(frame -> 
    frame.cels.map(cel -> tiles.push(cel.texture))
  );

  animation = new Anim(tiles, 15, s2d);

I couldn't actually find any example in the wild of code that uses the Asperite file instance or accessing the underlying textures. Any pointers from here?

@Redmega
Copy link
Contributor Author

Redmega commented Oct 5, 2019

Ok, interestingly enough, if I do this:

  Aseprite.parseFile(FOBSpriteBytes).frames.map(frame -> frame.cels.map(cel -> {
    if (cel != null) {
      trace('cel', cel.data.getParameters()[2]);
    }
    var tile = cast(cel.data.getParameters()[2], Tile);
    tiles.push(tile);
    return 0;
  }));

It actually renders! Not sure if grabbing the tile directly from the cel.data parameters is correct, though. However, it doesn't respect the frames 32x32 height, and instead grabs the actual pixel height used? Each frame is 30x28, 30x29, etc. This causes the following issue:

robots

The robot on the top left was rendered from haxe-aseprite, and it is off by a few pixels and so it looks like it's just moving its feet. The robot on the right was rendered with a spritesheet with a uniform 32x32 tile size, and therefore looks like it's bouncing properly.

Manually setting tile size by doing tile.setSize(32, 32) before adding it to the anim doesn't work -- doesn't seem to do anything. I've tried messing with the tile anchor, position, etc. but it doesn't really fix the change in perspective of the animation.

@lunabunn
Copy link

lunabunn commented Oct 5, 2019

I've made a working demo of using Aseprite stuff with Heaps. It's not exactly the most optimized or feature-rich, but it works, and you should be able to customize it however you want it. If this solves your problems, this issue should be closed :)

@Redmega
Copy link
Contributor Author

Redmega commented Oct 5, 2019

Works great! Thanks again @potatoelixir!

For anyone looking to use this for heaps in the future, now there's a clearly defined example for people to follow. 🎉

@Redmega Redmega closed this as completed Oct 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants