Jump to content

Updating sprite texture from a loaded resource


TonyFirgun
 Share

Recommended Posts

Hello, I'm having trouble setting the texture of a sprite and pointing it to a loaded json resource. Any help would be greatly appreciated

this.spriteSrc = PIXI.gfxLoader.resources['images/models/man.json'].spritesheet
this.sprite.texture = new PIXI.Texture.from(this.spriteSrc.textures['stand_down/0.png'])
Link to comment
Share on other sites

you want a new texture to modify the frame , or you want old one?

1.  "this.sprite.texture = this.spriteSrc.textures['stand_down/0.png']" should do it.

2. "PIXI.Texture.from()" is used to get by name from cache, from every spritesheet, you can just pass your 'stand_down/0.png' there. 

If it doesnt work, please specify more details. Check obvious things like whether your "textures" have that key at all

Link to comment
Share on other sites

54 minutes ago, ivan.popelyshev said:

you want a new texture to modify the frame , or you want old one?

1.  "this.sprite.texture = this.spriteSrc.textures['stand_down/0.png']" should do it.

2. "PIXI.Texture.from()" is used to get by name from cache, from every spritesheet, you can just pass your 'stand_down/0.png' there. 

If it doesnt work, please specify more details. Check obvious things like whether your "textures" have that key at all

Oh thank you a ton, that worked!

I'm still quite a beginner to programming so I'm still trying to grasp my mind around all of this.
Could you recommend me articles/tutorials/books I could read into to help me further my knowledge with pixi and javascript as a beginner? Thank you.

Link to comment
Share on other sites

Find https://www.amazon.com/JavaScript-Definitive-Guide-Activate-Guides/dp/0596805527, there are many pirated versions in internets. Learning Pixi+JS at the same time is hard, because PixiJS team focused on clear internal code, not on clear advancement for people without pre-knowledge. To read that code you need some experience with JS, and to advance faster you have to use chrome devtools like professional who already debugged a few projects and has experience with finding strange JS-related bugs.
 

If you need inputs or physics, or something else that pixi doesnt have from default package - i suggest to move to Phaser. You can always move back to pixi when you have more experience and know which things you need :)

Edited by ivan.popelyshev
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...