Jump to content

Texture Coordinates (UV), how change?


Riddik
 Share

Recommended Posts

Phaser doesn't really operate on this kind of low level, however you can change the anchor of the sprite with, for instance, sprite.anchor.setTo(0.5, 0.5) which will set the anchor to the center. If you use a TileSprite you can simulate texture panning by using tilePosition.x and tilePosition.y.

 

I believe you may be able to alter texture coordinates directly by delving into the pixi source code, but I think you may run into issues getting it working in both canvas and webGL, which is why I imagine this feature isn't directly implemented in the first place.

Link to comment
Share on other sites

Oк, thank you very much!

 

And what do you think about the idea to recreate sprite with the new tex coordinates in runtime (performance)?  

I just want to animate lifebar. Scale not suitable.

Link to comment
Share on other sites

It depends what you're trying to do - if you want to crop the bar, then see this example: http://examples.phaser.io/_site/view_full.html?d=sprites&f=horizontal+crop.js&t=horizontal%20crop

 

If on the other hand you have a series of separate images to show the lifebar at certain stages, you'd be better off using a sprite sheet or texture atlas, giving each stage a numbered name (i.e. "lifebar-100", "lifebar-90"... "lifebar-10" etc) and then changing the frame name dynamically:

// assuming your player health goes from 0 to 100 and your frames are in steps of 10lifeBarSprite.frameName = "lifebar-" + Math.round(player.health/10)*10;
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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