Jump to content

Pixi Loader not working


norbu
 Share

Recommended Posts

Hi

When i load my textures with the loader and add this to the stage it's not showing. But when i create a texture with PIXI.Texture then works perfectly.

I load in the game.js file the main-scene.js, in the main-scene.js i add some sprites when i create the texture in the mainscene it works fine but when i use the resources from the loader i get no error but the sprite is not displayed.

What i'm doing wrong?

Thank you

game.js

import * as Pixi from 'pixi.js'

import MainScene from './scenes/main-scene/main-scene'

export default class Game extends Pixi.Application {
  constructor (vueContext, config) {
    super()
    // Contexts
    this.vue = vueContext
    this.config = config

    // Add Game view to site
    this.vue.$el.appendChild(this.view)

    // Scenes
    this.scenes = {}

    // Main Scene
    this.scenes.mainScene = new MainScene(this, this.vue, this.config)
    this.stage.addChild(this.scenes.mainScene)

    this.load()
  }
  load () {
    this.loader.add('sprite2', '/static/game/images/sprite2.png')
    this.loader.load(this.setup())
  }
  setup () {
    // Setup Scenes
    this.scenes.mainScene.setup(this.loader.resources)
  }
  run () {
  }
  destroy () {
  }
}

main-scene.js

 

import * as Pixi from 'pixi.js'
import Scene from './../../engine/scene'

export default class MainScene extends Scene {
  constructor (context, vueContext, config) {
    super()
    // Set Contexts
    this.game = context
    this.vue = vueContext
    this.config = config
  }
  setup (resources) {
    // This is wokring
    let Texture = Pixi.Texture.fromImage('/static/game/images/sprite1.png')
    let sprite1 = new Pixi.Sprite(Texture)
    this.addChild(sprite1)

    // This is not working
    let sprite2 = new Pixi.Sprite(resources.sprite2.texture)
    this.addChild(sprite2)
  }
}
Link to comment
Share on other sites

Sorry about this post i found the problem, i call the setup method wring in the game.js file

import * as Pixi from 'pixi.js'

import MainScene from './scenes/main-scene/main-scene'

export default class Game extends Pixi.Application {
  constructor (vueContext, config) {
    super()
    // Contexts
    this.vue = vueContext
    this.config = config

    // Add Game view to site
    this.vue.$el.appendChild(this.view)

    // Scenes
    this.scenes = {}

    // Main Scene
    this.scenes.mainScene = new MainScene(this, this.vue, this.config)
    this.stage.addChild(this.scenes.mainScene)

    this.load()
  }
  load () {
    this.loader.add('sprite2', '/static/game/images/sprite2.png')
    this.loader.load((loader, resources) => {
      this.setup(resources)
    })
  }
  setup (resources) {
    // Setup Scenes
    this.scenes.mainScene.setup(resources)
  }
  run () {
  }
  destroy () {
  }
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...