Riddik Posted June 20, 2014 Share Posted June 20, 2014 Hi!Please tell, how change the texture coordinates in the sprite? Link to comment Share on other sites More sharing options...
lewster32 Posted June 20, 2014 Share Posted June 20, 2014 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 More sharing options...
Riddik Posted June 20, 2014 Author Share Posted June 20, 2014 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 More sharing options...
lewster32 Posted June 20, 2014 Share Posted June 20, 2014 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; Riddik 1 Link to comment Share on other sites More sharing options...
Riddik Posted June 20, 2014 Author Share Posted June 20, 2014 Сrop the bar - exactly what I need!Thank you very much! Link to comment Share on other sites More sharing options...
Recommended Posts