Game Development Community

Possible to display 'true sized' pixels?

by Backman · in Torque Game Builder · 02/11/2007 (2:51 am) · 9 replies

Ok, not sure if the title is confusing or not but what I'm trying to ask for is if there is an easy way to display a menu that's been drawn to e.g 50*50 pixels, and to display this menu inside the game always at this size, no matter what resolution the game is played at? The game uses zoom functions as well which might complicate things.

I'd prefer not to use TGB's GUI editor, even if that would help..

Thanks in advance.

#1
02/11/2007 (3:59 am)
What you've described should be the default behavior of GuiControls. Your horizSizing should be "right" and vertSizing should be "bottom". It's possible that they've been set to another dynamic sizing option such as "width" and "height" or "relative", so check that out. One thing that might be happening if you are in fact using GuiControls is defining your top level gui control and expecting that not to get resized. Any control that gets pushed directly onto the canvas will always be resized to the size of the canvas. The way I always guis is to define a top level GuiControl that doesn't do anything, and set it's sizings to "width" and "height" (which is unnecessary since it will follow this behavior anyway). Then I stick all my other gui controls inside of it. This gains you a number of benefits, one of which being that none of your visible elements will ever be automatically sized to the canvas dimensions unless you explicitly tell it to.

If you're talking about a scene, it will automatically be sized along with the scene window so if your scene window is set to one of the dynamic sizing options and you're using scene objects for your interface, you'd have to actually resize the scene objects inside your scene graph (which would get annoying and is not recommended for what you want to do).
#2
02/11/2007 (6:15 am)
I think I'm wanting to do something similar to this as well. I do a lot of self asset loading. All my images are sized the scale and res I want, but TGB seems to scale them to something else when I load them. For example on every 800x600 image I have to set scale "200 100". Is there anyway to just scale them to their default scale size based on pixels...

Nic.
#3
02/11/2007 (11:34 am)
If I understand you both correctly, what you want to do is convert pixel coordinates to world coordinates. I briefly explained how I do this in C++ in this thread:
This thread

If you don't have the Pro license and/or aren't that familiar with C++, I could be persuaded to re-write the code in the above thread so that it works in script.

@Nic: Specifically what you're interested in is the t2dDefaultSize() function in the aforementioned thread.

@Richard: If your game zooms in and out, you may want to create 2 overlapping scenes. The bottom scene could be for your game world and the top scene for your TGB based menus.
#4
02/11/2007 (12:05 pm)
Grrrrrrr - pro version again...

Nic.
#5
02/11/2007 (4:26 pm)
Alright, here is a more or less equivalent script version. Note that you can get the pixel size of an imageMap from its datablock. Also, I haven't tested this script yet, so there may be some minor errors. Unfortunately, the script version uses some hard constants. I.E. I haven't found a script version of Platform::getWindowSize() which would reconfigure the window size automatically. Let me know if you have any problems.

[code]
// Example: Set the size of an object to its equivalent pixel size of 64 x 64.
%sceneObject.setSize( t2dDefaultSize("64 64") );
// Place object at screen pixel position 128x128.
%sceneObject.setPosition( t2dWinToScene("128 128") );

// Set this to your window size.
$vWindowSize = "800 600";
// Set this to your world size.
$vWorldSize = "100 75";

//------------------------------------------------------------------------------
// Convert pixel coordinates to world coordinates.
//------------------------------------------------------------------------------
function t2dDefaultSize(%vPixelSize)
{
// Seperate vectors in X / Y components.
%iWindowSizeX = getWord($vWindowSize, 0);
%iWindowSizeY = getWord($vWindowSize, 1);
%iWorldSizeX = getWord($vWorldSize, 0);
%iWorldSizeY = getWord($vWorldSize, 0);
%iPixelSizeX = getWord(%vPixelSize, 0);
%iPixelSizeY = getWord(%vPixelSize, 1);

%iDefaultSizeX = (%iWorldSizeX / %iWindowSizeX) * %iPixelSizeX;
%iDefaultSizeY = (%iWorldSizeY / %iWindowSizeY) * %iPixelSizeY;
return %iDefaultSizeX SPC %iDefaultSizeY;
}

//------------------------------------------------------------------------------
// Convert pixel coordinate to world coordinate.
// Note: you must change WINDOW to the name of your t2dSceneWindow
//------------------------------------------------------------------------------
function t2dWinToScene(%vPixel)
{
return WINDOW.getWorldPoint(%vPixel);
}
#6
02/11/2007 (4:43 pm)
@Mathew,

The current screen resolution, "800x600" in your example above, can be obtained with "getRes()" (a Console Function)

getRes()

Purpose
Gets the current resolution and bit depth of the window.

Return Value - List
The width of the window, the height of the window, and the bitdepth of the window.

Your world size can be obtained with getCurrentCameraArea -- basically, take the absolute value of X1 and X2 and you have the X dimension, same with Y1 and Y2 ...

So if your Camera Area is "-100 100 -100 100" your screen area is "200 200"

So the updated code above can be done as such:

// Example: Set the size of an object to its equivalent pixel size of 64 x 64.
%sceneObject.setSize( t2dDefaultSize("64 64") );
// Place object at screen pixel position 128x128.
%sceneObject.setPosition( t2dSceneToWin("128 128") );

// Set this to your window size.
//$vWindowSize = "800 600";
// Set this to your world size.
//$vWorldSize = "100 75";

//------------------------------------------------------------------------------
// Convert pixel coordinates to world coordinates.
//------------------------------------------------------------------------------
function t2dDefaultSize(%vPixelSize)
{
%vWindowSize = getRes();
%buff = sceneWindow2D.getCurrentCameraArea();
%vWindowSize = mAbs(getWord(%buff, 0)) + mAbs(getWord(%buff, 1)) SPC 
                            mAbs(getWord(%buff, 2)) + mAbs(getWord(%buff, 3))
// Seperate vectors in X / Y components.
%iWindowSizeX = getWord(%vWindowSize, 0);
%iWindowSizeY = getWord(%vWindowSize, 1);
%iWorldSizeX = getWord(%vWorldSize, 0);
%iWorldSizeY = getWord(%vWorldSize, 0);
%iPixelSizeX = getWord(%vPixelSize, 0);
%iPixelSizeY = getWord(%vPixelSize, 1);

%iDefaultSizeX = (%iWorldSizeX / %iWindowSizeX) * %iPixelSizeX;
%iDefaultSizeY = (%iWorldSizeY / %iWindowSizeY) * %iPixelSizeY;
return %iDefaultSizeX SPC %iDefaultSizeY;
}

Granted, this code is untested as I just updated the code in the post textarea on the page -- but the logic should be "good" ...

For performance, so your not repeatedly recalculating all of this, storing the value of %vWindowSize and %vWorldSize in $vWindowSize and $vWorldSize might be optimal ... and then just have a check to see if either of them is "false" (initialize them as false by declaring them as static variables in your script somewhere ) -- if there false, perform the above code, then store the value in the variable ... and at which point, it won't be false anymore ... so we only check the value of the variable rather then recalculate all the values every time we call this ... and you can simply "falsify" the values whenever you call screen functions that change the size of the camera area OR the resolution (in your Options, maybe?)

Hope this helps ...
#7
02/11/2007 (4:46 pm)
Thanks for the update. I really don't use script that much :)
#8
02/11/2007 (4:59 pm)
No problem -- without really knowing that they exist, you wouldn't really be able to find them anyhow ... I just happened to have spent all day yesterday looking for those two things specifically, so I knew them off hand ...
#9
02/15/2007 (3:32 pm)
Thanks all, this will definitely help me getting somewhere.. :)