khleug35 Posted July 20, 2019 Share Posted July 20, 2019 Hello EveryOne How to get the TextureFrame number on Animation?? Thanks you very much this.sheet = new game.SpriteSheet('panda.png', 150 ,111); this.sprite = new game.Animation(this.sheet.textures); this.sprite.addAnim('attack', [43,44,45,46,47,48], { speed: 12, loop: false }); if(this.sprite.xxxxxxxxx.textureframe == 46){ // // dosomething....... } My solution is that, but I don't know Is it the best way to solve the problem?? Thanks if(this.sprite.currentAnim == this.sprite.anims['attack']){ for(var i =0; i < this.sprite.anims.attack.textures.length;i++){ if(i ===4){ // [43,44,45,46,47,48] = [0,1,2,3,4,5,6] due to I want to get frame 46, so i type 4. //doSomething } } } It is very easy to get the TextureFrame in Phaser 3, How about Panda2, Thank you //Phaser 3 if (this.sprite.anims.currentFrame.textureFrame === 46){ // dosomething } Quote Link to comment Share on other sites More sharing options...
Wolfsbane Posted July 22, 2019 Share Posted July 22, 2019 Yo! If you've got a tiny Panda file example project? Just so I can open it on my pc, and open it up in Debug and see what options are there. Quote Link to comment Share on other sites More sharing options...
khleug35 Posted July 22, 2019 Author Share Posted July 22, 2019 @Wolfsbane Thank you for reply, The following is my simple project I try to use chrome console debug to find the answer but still no idea, thx game.module( 'game.main' ) .body(function() { game.addAsset('player.png'); game.createScene('Main', { init: function() { this.sheet = new game.SpriteSheet('player.png', 149 ,237); this.anim = new game.Animation(this.sheet.textures); this.anim.addAnim('run', [3, 4, 5, 6, 7, 8, 9]); this.anim.play('run'); this.anim.addTo(this.stage); console.log(this.anim); } }); }); I can't upload the 'player.png' to this forum. so plz kindly download the 'player.png' to this link , thx https://www.panda2.io/content/examples/media/player.png Quote Link to comment Share on other sites More sharing options...
Wolfsbane Posted July 24, 2019 Share Posted July 24, 2019 On 7/20/2019 at 6:33 PM, khleug35 said: My solution is that, but I don't know Is it the best way to solve the problem?? Thanks if(this.sprite.currentAnim == this.sprite.anims['attack']){ for(var i =0; i < this.sprite.anims.attack.textures.length;i++){ if(i ===4){ // [43,44,45,46,47,48] = [0,1,2,3,4,5,6] due to I want to get frame 46, so i type 4. //doSomething } } } No need to do this at least: anim has an attribute currentFrame. So you can simply do: if (this.anim.currentFrame === 4){ //currentFrame will start from 0-size of animation. // dosomething } I took a look, and we really don't seem to have the textureFrame==46 style.. It's convenient, but if you're going to hard-code a number in there, I much prefer just hard coding to the 0,1,2,3 convention. Think of this: You know you're animation framing is going to be 0=first frame, 1=second frame. Now: If you update your spritesheet.png, and suddenly If you hard-code in =46, and then the image changes, then both the image, and your code has to change. Does that make sense? khleug35 1 Quote Link to comment Share on other sites More sharing options...
khleug35 Posted August 17, 2019 Author Share Posted August 17, 2019 @Wolfsbane sorry for reply lately, Thank you for your answer and advice, really thanks. Wolfsbane 1 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.