Accessing the Camera size in a behavior?
by Ulric Boel · in Torque Game Builder · 07/13/2007 (1:17 am) · 2 replies
Hi there,
I was just trying to create a simple Behavior file allowing to automatically center and extend an image as background but I ran into a trouble...
I was able to set the image position and size manually, but I would like being able to do this manually...wherever the camera could be placed, whatever the camera size is.
How can I get the camera size from within the onBehaviorAdd callback method?
I already tried accessing the sceneWindow2D object, but it does not exist or is not accessible from the behavior callback method...
Is there anyway to achieve what I would like to do? Any idea?
Thanks in advance,
Ulric
I was just trying to create a simple Behavior file allowing to automatically center and extend an image as background but I ran into a trouble...
I was able to set the image position and size manually, but I would like being able to do this manually...wherever the camera could be placed, whatever the camera size is.
How can I get the camera size from within the onBehaviorAdd callback method?
I already tried accessing the sceneWindow2D object, but it does not exist or is not accessible from the behavior callback method...
Is there anyway to achieve what I would like to do? Any idea?
Thanks in advance,
Ulric
#2
Thanks for your quick answer.
After some experimentation, I found out I have to use sceneWindow2D.getWindowExtents() instead of sceneWindow2D.getCurrentCameraSize().
My Background behavior is now working properly when running the game...but not when used in the editor.
From what I read in the documentation the onBehaviorAdd call back is fired also in the TGB editor when assigning the behavior and therefore should work in the same way. This is not entirely true, it seems...the method is called but the result seems to vary depending on the way you code your static sprite resizing and relocation:
- When using setPosition(%posX, %posY) and setSize(sizeX%, %sizeY) nothing happens to the sprite within the editor.
- When using setPositionX(%posX), setPositionY(%posY) and setSizeX(%sizeX), setSizeY(%sizeY), the sprite gets a size (0.000, 0.000) and a position (0.000, 0.000). The same happens when writing directly into the size and position properties.
Perhaps this is a bug...I don't know.
Below is the code I use.
In any case, thanks for your help.
Ulric
Edit: I just found out how to open the console from within the TGB Editor (CTRL+
07/16/2007 (12:12 am)
Hello,Thanks for your quick answer.
After some experimentation, I found out I have to use sceneWindow2D.getWindowExtents() instead of sceneWindow2D.getCurrentCameraSize().
My Background behavior is now working properly when running the game...but not when used in the editor.
From what I read in the documentation the onBehaviorAdd call back is fired also in the TGB editor when assigning the behavior and therefore should work in the same way. This is not entirely true, it seems...the method is called but the result seems to vary depending on the way you code your static sprite resizing and relocation:
- When using setPosition(%posX, %posY) and setSize(sizeX%, %sizeY) nothing happens to the sprite within the editor.
- When using setPositionX(%posX), setPositionY(%posY) and setSizeX(%sizeX), setSizeY(%sizeY), the sprite gets a size (0.000, 0.000) and a position (0.000, 0.000). The same happens when writing directly into the size and position properties.
Perhaps this is a bug...I don't know.
Below is the code I use.
if (!isObject(BackgroundBehavior))
{
%template = new BehaviorTemplate(BackgroundBehavior);
%template.friendlyName = "Background";
%template.behaviorType = "GUI";
%template.description = "Set a static sprite as background, centered on the camera position and sized properly";
}
function BackgroundBehavior::onBehaviorAdd(%this)
{
%temp = sceneWindow2D.getWindowExtents();
%posX = getWord(%temp, 0);
%posY = getWord(%temp, 1);
%sizeX = getWord(%temp, 2);
%sizeY = getWord(%temp, 3);
%this.owner.setPosition(%posX, %posY);
%this.owner.setSize(%sizeX, %sizeY);
%this.owner.layer = 31;
}In any case, thanks for your help.
Ulric
Edit: I just found out how to open the console from within the TGB Editor (CTRL+
Torque Owner Melissa Niiya
If this doesn't work, could you paste a snippet of code?