Get sprite's image dimensions at runtime

0 favourites
  • 7 posts
From the Asset Store
2d mushroom sprite 2d game character enmy sprite game art
  • Hi everyone,

    Does anyone know of a way to get a sprite's original image dimensions at runtime?

    Basically, if an image is changed at the url, can we get that image's dimensions to adjust for its size?

    Thanks for any input on this,

    David

  • Not sure what you mean by "changed at the url", but you could set the original dimensions to variables at the start of the first layout.

  • Hehe, that does seem very unclear in looking back at it, "changed at the url"!

    What I mean is that if you decide to swap out game images for larger images after the game has been exported, is there a way to get the new image's dimensions?

  • Ohhh alrighty then. I guess you'll have to try it to see how it reacts. Best case scenario, it'll change automatically to accomodate the new sprite. Worst case, you have to re-export it for it to take effect. I've never tried. <img src="smileys/smiley5.gif" border="0" align="middle" />

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I've tried it myself, and the sprites of course change in the game to whatever graphics you replace them with, but using the dimensions set for the initial sprite. I was hoping there would be a way to change the dimensions to match whatever the original image dimensions are.

    Basically, I was hoping to make a skinnable game, which is possible without changing dimensions, but I could use being able to change those dimensions to match the actual image's dimensions at runtime, where those images may vary.

    Oddly, I just realized a method by which this could be done in my case. I'll post that back here if I can throw together an example quickly enough.

    Thanks for going through this one with me! Much appreciated! :)

    Cheers,

    David

  • Sprite has the ImageWidth and ImageHeight expressions which return the size of its image file.

  • Ah, thanks Ashley, didn't realize that expression provided the file dimensions! It's incredibly useful when doing skinnable/themeable games, something I'm working toward.

    Many thanks too for one amazing app!

    Something about the workflow with this thing entails I can throw ideas together twice as fast as I did with GameMaker. Incidentally, with GameMaker, I usually just went right to the code, which somewhat defeats the purpose. :)

    Cheers,

    David

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)