kucira Posted September 12, 2014 Share Posted September 12, 2014 Hi Pandajs Team. i would like to creating some health bars feature in my game and i need to crop the texture rather than scaling the texture.how i can approach this using pandajs? Thanks. Quote Link to comment Share on other sites More sharing options...
enpu Posted September 13, 2014 Share Posted September 13, 2014 One way would be using mask.var sprite = new game.Sprite('sprite.png');var mask = new game.Graphics();mask.drawRect(0, 0, 200, 200);sprite.mask = mask; awbummer 1 Quote Link to comment Share on other sites More sharing options...
enpu Posted September 13, 2014 Share Posted September 13, 2014 I just added new crop method to Sprite. You can try it from develop branch:https://github.com/ekelokorpi/panda.js/tree/developvar sprite = new game.Sprite('sprite.png');sprite.crop(0, 0, 200, 200); Quote Link to comment Share on other sites More sharing options...
kucira Posted September 13, 2014 Author Share Posted September 13, 2014 Awesome! Thanks enpu. Quote Link to comment Share on other sites More sharing options...
awbummer Posted September 17, 2015 Share Posted September 17, 2015 Hi, I'm having trouble using this method when the sprite that I'm attempting to crop is offset from 0,0. If I set the xy to (0,0) in the following code, things work fine; otherwise the entire sprite disappears: healthbar = game.add.sprite(500, 20, 'healthbar'); healthbar.fixedToCamera = true; healthbar.cropEnabled = true; cropRectangle = new Phaser.Rectangle(healthbar.x, healthbar.y, healthbar.width - 20, healthbar.height); cropRectangle.fixedToCamera = true; healthbar.crop(cropRectangle);Any thoughts? Thanks! Quote Link to comment Share on other sites More sharing options...
awbummer Posted September 17, 2015 Share Posted September 17, 2015 Oooh, I got it. The rectangle coordinates are relative to the sprite. So my rectangle should have been adjusted to this:cropRectangle = new Phaser.Rectangle(0, 0, healthbar.width - 20, healthbar.height); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.