Get sprite's image dimensions at runtime

Get help using Construct 2

Post » Sat Oct 15, 2011 3:50 am

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,
DavidUgotsta2011-10-15 03:51:03
B
126
S
7
G
4
Posts: 185
Reputation: 7,233

Post » Sat Oct 15, 2011 4:09 am

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.
B
20
S
9
G
6
Posts: 607
Reputation: 6,112

Post » Sat Oct 15, 2011 6:44 am

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?
B
126
S
7
G
4
Posts: 185
Reputation: 7,233

Post » Sat Oct 15, 2011 6:52 am

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.
B
20
S
9
G
6
Posts: 607
Reputation: 6,112

Post » Sat Oct 15, 2011 11:09 am

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
B
126
S
7
G
4
Posts: 185
Reputation: 7,233

Post » Sat Oct 15, 2011 1:54 pm

Sprite has the ImageWidth and ImageHeight expressions which return the size of its image file.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Mon Oct 17, 2011 6:19 am

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
B
126
S
7
G
4
Posts: 185
Reputation: 7,233


Return to How do I....?

Who is online

Users browsing this forum: DiabloOvermind, emoticon, MrWhizm, Skebab, spcsmrf and 17 guests