Jump to content

trying to create a sprite


Alebrijes
 Share

Recommended Posts

Hi, I try to load a an image from a sprite sheet, This is my code:
 

loadAssets: function() {    // The coordinates for the sprite sheet    PIXI.loader        .add(['assets/interface.json'])        .once('complete', this.onLoadAssets.bind(this))        .load();},onLoadAssets: function() {    // This is the background image I try to load...    var bgtexture = new PIXI.Texture.fromImage('bg.png');    var paperBG = new PIXI.Sprite(bgtexture);    this.stage.addChild(paperBG);}

 
When I load the page I can see the space should have the image in the screen, but its all black, I cant see the image, What I´m doing wrong ? Thanks for your help!

Link to comment
Share on other sites

http://www.html5gamedevs.com/topic/14524-v3-access-cached-texture-by-name/?p=82661
http://www.html5gamedevs.com/topic/14981-v3-loader-accessing-the-keys/?p=84973
http://www.html5gamedevs.com/topic/15452-loader-usage-pixi-v3/?p=87504

Don't try to mix the loader and fromX() methods, just use the loader. Your callback gets all the loaded assets. Just use them.



loadAssets: function() {    // The coordinates for the sprite sheet    PIXI.loader        .add('interface', 'assets/interface.json')        .once('complete', this.onLoadAssets.bind(this))        .load();},onLoadAssets: function(loader, resources) {    // check out this object, it likely already has texture objects for you to use directly    // they are named based on your sheet, so I am only guessing when I try to use it below    console.log(resources.interface, resources.interface.textures);    var paperBG = new PIXI.Sprite(resources.interface.textures['bg.png']);    this.stage.addChild(paperBG);}
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...