Using pixel coordinate size instead of torque coordinate size
by rwillis · in Torque X 2D · 11/09/2007 (9:11 pm) · 2 replies
If I have a T2dStaticSprite and want to set the size of it exactly to it's width and height in pixels, how do I do that? It seems like the Size property for a T2dStaticSprite scales the sprite up to a specified amount of the game screen instead of setting the size in pixels. i.e. if i have a sprite thats 50 px by 50 px and I set the Size parameter to "new Vector2(50,50)" then instead of it showing up 50 px by 50 px in-game it instead shows up as having length 50% of the length of the screen and height 50% of the height of the screen. So how do I set the size of the T2dStaticSprite in pixels?
About the author
Torque Owner Kevin Keathley
Non-Default Studio Name
Another method would be for you to query the size of the viewport and mathematically calculate how large each game world coordinate is using that, then applying the appropriate gameworld coordinate size to your sprite. For example, if the viewportwidth is 100 pixels and viewport height is 100 pixels and they are 1 world coordinate each, then 1 coord would equal 100 pixels, 1 pixel would equal 1/100 world coord. Then 50 pixels would be .5 world coordinates. You really only have to do that initially because if the game resizes then it should resize all of your sprites accordingly as well (keeping the same scale).
The idea behind TorqueX and Torque2D though is to make it resolution independent at some point. If you design everything in one of the builders then for the most part you get WYSIWYG, meaning it should look right at any resolution regardless of the physical pixel size.
If you are creating new sprites outside the TGB/TXB (programmatically), then you could create a template of the appropriate size initially in TGB/TXB and then just clone that. All the clones will be the same size as the template if I remember correctly.
I hope some of that helps. I had to use pixel sizes at some point as well, but I was using them to size viewports on the screen for 1 to 4 players (full display, half and half, and quarters). I usually just size the sprites to look appropriate in TXB and then let the engine handle the rest.