Jump to content

Obtaining source height for tileSprite


Jonty
 Share

Recommended Posts

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

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

 Share

  • Recently Browsing   0 members

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