yordan-kanchelov / pixi-typescript-boilerplate

Template for PixiJS using Typescript and Webpack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Something is wrong with default base path

bySabi opened this issue · comments

Hi @jkanchelov I am testing this template with some simple examples to learn and I have not managed to create a Sprite from a local image.
There seems to be some path problem.

You can test it yourself by replacing "index.ts" with:

import * as PIXI from 'pixi.js';

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

const rabbit = PIXI.Sprite.from('./assets/rabbit.png');
rabbit.anchor.set(0.5);
rabbit.x = app.screen.width / 2;
rabbit.y = app.screen.height / 2;

app.stage.addChild(rabbit);

Sorry it's my fault for not adding window.onload to handle the app's lifecycle.

I have taken the liberty of refactoring the code a little to make it clearer. IMHO the current approach with a single Class that contains everything is much more difficult to maintain.

What I have done is:

  • Move constants like, GAME_WIDTH, GAME_HEIGHT to constants.ts
  • The creation part of the renderer is all boilerplate, it does not change. I've taken it to the get-app.ts module and it works as a Singleton
  • And in index.ts I have left the part that is customized like the functions of Sprites creation like "rabbit" and "bunny", the loading of images and the management of events.

The "index" module is handled by the window.onload callback, which is where the app's life cycle is managed.

It seems clearer to me like that, but it's just my opinion. If you don't think it's correct, tell me the errors, please, to correct them.

This is my fork: https://github.com/bySabi/first-pixi

Sorry for the slow response. For sure your fork is a lot more cleaner what I wanted the boilerplate to have is everything which I consider as important in one place to be easier for someone new to break it down. Not sure if it's right tho

@jkanchelov In the end I have created my own template.

Aside from the changes I mentioned above:

  • remove the rabbit.png import so that Parcel ignores it and now it is copied along with the entire assets folder to dist

This is the repo: https://github.com/bySabi/pixijs-typescript-template
I have put you in the credits :-)