Sprite size and pozition
by Kostiantyn Teterin · in Torque Game Builder · 12/12/2005 (9:12 pm) · 1 replies
Hello all!
Well, I give up! I thought that Torque2D will speed up my development speed, and now I try to solve a simple problem for 3 days :( My task is simple. I want to create menu buttons from bitmaps, and to make them "jump" when player put mouse cursor over them - a 10-15 minutes task for C++ or BlitzBasic!
First of all, I tried to solve this problem with GuiBitmapCtrl. But it seems to be impossible to catch event when mouse cursor is over it, and I can't recompile T2D on my mac so I am unable to change code of controls to add mouse events to them. Then I tried to solve this problem with static sprites, and now I am totally messed... This is the code:
datablock fxImageMapDatablock2D(menuButtonImageMap)
{
mode = cell;
cellWidth = 297;
cellHeight = 54;
textureName = "~/client/img/buttons";
};
$btStartGame = new fxStaticSprite2D() {
scenegraph = t2dSceneGraph;
};
$btStartGame.setSize("297 54");
$btStartGame.setPosition(sceneWindow2D.getWorldPoint("174 228"));
$btStartGame.setImageMap(menuButtonImageMap);
$btStartGame.setFrame(0);
And what I have on the screen is a sprite in a very big scale (just 2 letters from the text on the whole screen).
Its terrible! Why they don't just make sprite size and position in pixels? :(
And how to solve this problem?
Any help? :(
Well, I give up! I thought that Torque2D will speed up my development speed, and now I try to solve a simple problem for 3 days :( My task is simple. I want to create menu buttons from bitmaps, and to make them "jump" when player put mouse cursor over them - a 10-15 minutes task for C++ or BlitzBasic!
First of all, I tried to solve this problem with GuiBitmapCtrl. But it seems to be impossible to catch event when mouse cursor is over it, and I can't recompile T2D on my mac so I am unable to change code of controls to add mouse events to them. Then I tried to solve this problem with static sprites, and now I am totally messed... This is the code:
datablock fxImageMapDatablock2D(menuButtonImageMap)
{
mode = cell;
cellWidth = 297;
cellHeight = 54;
textureName = "~/client/img/buttons";
};
$btStartGame = new fxStaticSprite2D() {
scenegraph = t2dSceneGraph;
};
$btStartGame.setSize("297 54");
$btStartGame.setPosition(sceneWindow2D.getWorldPoint("174 228"));
$btStartGame.setImageMap(menuButtonImageMap);
$btStartGame.setFrame(0);
And what I have on the screen is a sprite in a very big scale (just 2 letters from the text on the whole screen).
Its terrible! Why they don't just make sprite size and position in pixels? :(
And how to solve this problem?
Any help? :(
About the author
Associate Melv May
I don't want to sound accusing or anything but have you gone through the tutorial documentation that explains some of the concepts to get you started? If you've not then you should find that this helps alot.
The sprite/size units are not in any real unit. If you are using the default camera, it views an area 100x75 which, unless your resolution is 100x75, won't equate to pixels. You are free to specify the coordinate system you like as the documentation shows. If you want 800x600 then set your camera view to 800x600 and not the default 100x75. This should take you around 5 seconds. ;) Does this make sense? For instance, if you had two cameras looking at the same scene but they used a different field of view, the objects would both look different.
You can easily change this dynamically in the scene-window callback (as shown in the reference doco) so that the coordinates match the physical screen resolution. Even this is a couple of lines; something similar to:-
// When the T2D window has changed... function sceneWindow2D::onExtentChange( %this, %newExtent ) { // Set my view to be the Screen-Resolution sceneWindow2D.setCurrentCameraPosition( "0 0" SPC getWords(%newExtent, 2, 3) ); }Also, the use of "sceneWindow2D.getWorldPoint("174 228")" shows that you're getting confused over coordinates. If you understood this stuff, you could do it in 2 minutes, not 10-15. ;)
The following links on TDN may help as well:
GUI Button
Object Selection#1
Object Selection#2
Object Selection#3
Good luck,
- Melv.