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

CanvasRenderer using incorrect asset from spritesheet #122

Closed
jake opened this issue Jun 8, 2021 · 11 comments
Closed

CanvasRenderer using incorrect asset from spritesheet #122

jake opened this issue Jun 8, 2021 · 11 comments

Comments

@jake
Copy link

jake commented Jun 8, 2021

I'm attempting to get pixi.js legacy canvas support working, but having an issue with this library. It seems to be ignoring the x,y position within the spritesheet and just displaying from 0,0.

Here is a slimmed down demo exhibiting the issue: https://codepen.io/jacobbijani/pen/XWMBdXr

Here is the code from that link just in case:

import * as PIXI from "https://cdn.skypack.dev/pixi.js-legacy";
import { CanvasTileRenderer, CompositeTilemap } from "https://cdn.skypack.dev/@pixi/tilemap";

if (!PIXI.utils.isWebGLSupported()) {
  console.log('no webgl, registering canvas plugin')
  PIXI.CanvasRenderer.registerPlugin('tilemap', CanvasTileRenderer);
}

// NOTE: `json` variable is defined in HTML tab

var app = new PIXI.Application({
    width: window.innerWidth,
    height: window.innerHeight,
    backgroundColor: 0x2c3e50
});
document.body.appendChild(app.view);

new PIXI.Spritesheet(PIXI.Texture.from('https://thinko-artifacts.s3.amazonaws.com/codepen/tiles-half.png'), json).parse((sheet) => {
  console.log('sheet loaded', sheet);
  
  const tilemap = new CompositeTilemap();
  app.stage.addChild(tilemap);

  tilemap.clear();
  tilemap.tile('vehicle-engine', 0, 0);
  tilemap.tile('vehicle-tractor', 0, 32);
});

In Chrome I see this, which is what is expected:

Screen Shot 2021-06-08 at 11 26 22 AM

In Firefox, where I have webgl disabled, I see this:

Screen Shot 2021-06-08 at 11 26 15 AM

The red dot is what is at 0,0 of my spritesheet.

Am I doing something wrong, or is this a bug?

@ivanpopelyshev
Copy link
Collaborator

OK, found bug, if you want to try fast fix, apply this to your @pixi/tilemap file in node_modules or where is it 7938df8

also, you wont need to register canvas renderer after this

@jake
Copy link
Author

jake commented Jun 8, 2021

thanks for the prompt response! that does seem to work, but it seems i still need the registerPlugin call for it to work.

if I remove the PIXI.CanvasRenderer.registerPlugin('tilemap', CanvasTileRenderer); then I get a separate error I got prior as well (tileAnim is undefined):

Screen Shot 2021-06-08 at 12 28 43 PM

Screen Shot 2021-06-08 at 12 36 00 PM

when I inspect the breakpoint there, it seems my tileAnim is actually null. presumably since both this.tileAnim is null and renderer.plugins.tilemap.tileAnim is undefined.

perhaps registerPlugin is still just required? or maybe the tileAnim fallback a few lines up is missing something?

@ivanpopelyshev
Copy link
Collaborator

ivanpopelyshev commented Jun 8, 2021

oh right because Tilemap doesnt have tileAnim by default... :) Just register it, it costs nothing anyway

@jake
Copy link
Author

jake commented Jun 8, 2021

great! btw, it took me a bit of sleuthing to realize I needed to register that. seems like its only documented in the actual tilemap/src/CanvasTileRenderer.ts source. a section in the readme on "enabling canvas support" might be worthwhile. I'd write it but honestly I'm not sure I have a full enough grasp on how it works just yet :)

@ivanpopelyshev
Copy link
Collaborator

ivanpopelyshev commented Jun 9, 2021

Anyway, its fixed in latest release, but still needs to register plugin
thank you for the report!

@jake
Copy link
Author

jake commented Jun 9, 2021

sounds good. when will it be published to npm?

@ivanpopelyshev
Copy link
Collaborator

it wasnt? Oh, I just have to call @ShukantPal again. I cant build new version for some reason :(

@jake
Copy link
Author

jake commented Jun 9, 2021

correct, on github and npm the latest version is still 3.2.0

@jake
Copy link
Author

jake commented Jun 14, 2021

@ShukantPal sorry to be annoying, but any update on publishing a new build to npm? hoping to get this integrated in my game upstream.

thanks!

@ShukantPal
Copy link
Member

I'll look into this today. Was gone on vacation.

@ShukantPal
Copy link
Member

https://github.com/pixijs/tilemap/releases/tag/v3.2.1

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

3 participants