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

Something is wrong with default base path #116

Closed
bySabi opened this issue Jun 22, 2020 · 3 comments
Closed

Something is wrong with default base path #116

bySabi opened this issue Jun 22, 2020 · 3 comments

Comments

@bySabi
Copy link

bySabi commented Jun 22, 2020

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);
@bySabi
Copy link
Author

bySabi commented Jun 22, 2020

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

@bySabi bySabi closed this as completed Jun 22, 2020
@yordan-kanchelov
Copy link
Owner

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

@bySabi
Copy link
Author

bySabi commented Jun 24, 2020

@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 :-)

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