Jonty Posted January 9, 2017 Share Posted January 9, 2017 Hi guys, I'm wondering if there's an easy way to obtain the source height for a tileSprite image. I know for a basic sprite you can just use sprite.height once it's been placed, but that's because you don't need to declare a height initially. If you are to do it for a tileSprite you will just get the height you have preset yourself. The only way I've managed to do it is by placing the tileSprite image as a basic sprite outside of the game area and then using that, like below: getSpriteHeight = this.game.add.sprite(-1000, -1000, 'tileSpriteSrc'); myTileSprite = this.game.add.tileSprite(0, 0, 500, getSpriteHeight.height, 'tileSpriteSrc'); But I'm wondering if there's an easier/cleaner method that doesn't involve me placing unnecessary assets outside the game area. Thanks. Link to comment Share on other sites More sharing options...
samme Posted January 9, 2017 Share Posted January 9, 2017 Should be in tileSprite.texture.frame.height Link to comment Share on other sites More sharing options...
Jonty Posted January 11, 2017 Author Share Posted January 11, 2017 Hi Samme, Thanks for getting back. That's great, thanks! That has worked on getting the height of source, but only after the tileSprite is created. Is there a way to get immediately so I don't have to put a default first and then apply the real height afterwards? Or is that the only way to go? Like below: myTileSprite = this.game.add.tileSprite(0, 0, 500, 100, 'tileSpriteSrc'); myTileSprite.height = myTileSprite.texture.frame.height Thanks. Link to comment Share on other sites More sharing options...
samme Posted January 11, 2017 Share Posted January 11, 2017 For a single-frame image I think it's game.cache.getFrame('key').height Link to comment Share on other sites More sharing options...
Jonty Posted January 12, 2017 Author Share Posted January 12, 2017 That's great, thanks. Appreciate the help. samme 1 Link to comment Share on other sites More sharing options...
Recommended Posts