[SOLVED] Strange Goings-On With Object Classes
by Orion the Hunter · in Torque Game Builder · 09/06/2013 (9:47 am) · 5 replies
I've been working on a level-select scene where it looks something like this:
I've made the function's do various things onMouseOver, but the odd thing is, none of it works. :(
Here is the code that detects the mouse events and does different things to the level-buttons.
And here is the scene's code, itself!
You'll probably see that with the tilemaps, I didn't enable mouseEvents, so just try the first thing, the sceneObject and you'll see it's not functional. I'm also getting this error:
Does that mean I can't have a tilemap and a sceneobject all share the same class or something?
I've made the function's do various things onMouseOver, but the odd thing is, none of it works. :(
Here is the code that detects the mouse events and does different things to the level-buttons.
function goToLevelSelect()
{
canvas.pushDialog(sceneWindowGui);
MenuSceneWindow.loadLevel( expandFilename("game/data/levels/LevelSelect.t2d") );
}
function getQuedLevel()
{
%level = "~/data/levels/" @ $QuedLevel @ ".t2d";
return %level;
}
function LevelButtonClass::onMouseEnter(%this)
{
%this.mouseInTrigger = 1;
playSound(MLBO);
%this.Owner.blendColor = "1 1 1 0.5";
}
function LevelButtonClass::onMouseDown(%this)
{
%this.Owner.blendColor = "0.5 0.5 0.5 1";
}
function LevelButtonClass::onMouseUp(%this)
{
%this.Owner.blendColor = "1 1 1 1";
if(%this.mouseInTrigger)
{
canvas.pushDialog(QuedLevelGui);
$quedLevel = %this.Owner;
}
}
function LevelButtonClass::onMouseDragged(%this)
{
%this.mouseInTrigger = 0;
%this.Owner.blendColor = "1 1 1 1";
}
function startSelectedLevel()
{
_newGame();
sceneWindow2D.loadLevel(expandFilename(getQuedLevel()));
}And here is the scene's code, itself!
%levelContent = new t2dSceneGraph() {
canSaveDynamicFields = "1";
UseLayerSorting = "1";
layerSortMode0 = "Normal";
layerSortMode1 = "Normal";
layerSortMode2 = "Normal";
layerSortMode3 = "Normal";
layerSortMode4 = "Normal";
layerSortMode5 = "Normal";
layerSortMode6 = "Normal";
layerSortMode7 = "Normal";
layerSortMode8 = "Normal";
layerSortMode9 = "Normal";
layerSortMode10 = "Normal";
layerSortMode11 = "Normal";
layerSortMode12 = "Normal";
layerSortMode13 = "Normal";
layerSortMode14 = "Normal";
layerSortMode15 = "Normal";
layerSortMode16 = "Normal";
layerSortMode17 = "Normal";
layerSortMode18 = "Normal";
layerSortMode19 = "Normal";
layerSortMode20 = "Normal";
layerSortMode21 = "Normal";
layerSortMode22 = "Normal";
layerSortMode23 = "Normal";
layerSortMode24 = "Normal";
layerSortMode25 = "Normal";
layerSortMode26 = "Normal";
layerSortMode27 = "Normal";
layerSortMode28 = "Normal";
layerSortMode29 = "Normal";
layerSortMode30 = "Normal";
layerSortMode31 = "Normal";
DebugRendering = "0";
cameraPosition = "0 0";
cameraSize = "200 150";
new t2dStaticSprite() {
imageMap = "sky_duskImageMap";
frame = "0";
sourceRect = "0 0 0 0";
canSaveDynamicFields = "1";
size = "200.000 150.000";
Layer = "31";
BlendColor = "0 0.792157 1 1";
mountID = "2";
};
new t2dTileLayer(Level2) {
LayerFile = "~/data/tilemaps/Parallax/TP2.lyr";
canSaveDynamicFields = "1";
class = "LevelButtonClass";
Position = "-40.000 -55.000";
size = "30.000 30.000";
Layer = "14";
CollisionMaxIterations = "1";
mountID = "3";
};
new t2dTileLayer(Level4) {
LayerFile = "~/data/tilemaps/Parallax/TP2.lyr";
canSaveDynamicFields = "1";
class = "LevelButtonClass";
Position = "40.000 -55.000";
size = "30.000 30.000";
Layer = "14";
CollisionMaxIterations = "1";
mountID = "4";
};
new t2dTileLayer(Level3) {
LayerFile = "~/data/tilemaps/Parallax/TP2.lyr";
canSaveDynamicFields = "1";
class = "LevelButtonClass";
Position = "0.000 -55.000";
size = "30.000 30.000";
Layer = "14";
CollisionMaxIterations = "1";
mountID = "5";
};
new t2dTileLayer(Level9) {
LayerFile = "~/data/tilemaps/Parallax/TP2.lyr";
canSaveDynamicFields = "1";
class = "LevelButtonClass";
Position = "40.000 0.000";
size = "30.000 30.000";
Layer = "14";
CollisionMaxIterations = "1";
mountID = "6";
};
new t2dTileLayer(Level8) {
LayerFile = "~/data/tilemaps/Parallax/TP2.lyr";
canSaveDynamicFields = "1";
class = "LevelButtonClass";
Position = "40.000 55.000";
size = "30.000 30.000";
Layer = "14";
CollisionMaxIterations = "1";
mountID = "7";
};
new t2dTileLayer(Level5) {
LayerFile = "~/data/tilemaps/Parallax/TP2.lyr";
canSaveDynamicFields = "1";
class = "LevelButtonClass";
Position = "80.000 -55.000";
size = "30.000 30.000";
Layer = "14";
CollisionMaxIterations = "1";
mountID = "8";
};
new t2dTileLayer(Level7) {
LayerFile = "~/data/tilemaps/Parallax/TP2.lyr";
canSaveDynamicFields = "1";
class = "LevelButtonClass";
Position = "-40.000 0.000";
size = "30.000 30.000";
Layer = "14";
CollisionMaxIterations = "1";
mountID = "9";
};
new t2dTileLayer(Level6) {
LayerFile = "~/data/tilemaps/Parallax/TP2.lyr";
canSaveDynamicFields = "1";
class = "LevelButtonClass";
Position = "-80.000 0.000";
size = "30.000 30.000";
Layer = "14";
CollisionMaxIterations = "1";
mountID = "10";
};
new t2dTileLayer(Level10) {
LayerFile = "~/data/tilemaps/Parallax/TP2.lyr";
canSaveDynamicFields = "1";
class = "LevelButtonClass";
Position = "80.000 0.000";
size = "30.000 30.000";
Layer = "14";
CollisionMaxIterations = "1";
mountID = "11";
};
new t2dTileLayer(Level11) {
LayerFile = "~/data/tilemaps/Parallax/TP2.lyr";
canSaveDynamicFields = "1";
class = "LevelButtonClass";
Position = "-80.000 55.000";
size = "30.000 30.000";
Layer = "14";
CollisionMaxIterations = "1";
mountID = "12";
};
new t2dTileLayer(Level12) {
LayerFile = "~/data/tilemaps/Parallax/TP2.lyr";
canSaveDynamicFields = "1";
class = "LevelButtonClass";
Position = "-40.000 55.000";
size = "30.000 30.000";
Layer = "14";
CollisionMaxIterations = "1";
mountID = "13";
};
new t2dTileLayer(Level13) {
LayerFile = "~/data/tilemaps/Parallax/TP2.lyr";
canSaveDynamicFields = "1";
class = "LevelButtonClass";
Position = "0.000 55.000";
size = "30.000 30.000";
Layer = "14";
CollisionMaxIterations = "1";
mountID = "14";
};
new t2dTileLayer(Level14) {
LayerFile = "~/data/tilemaps/Parallax/TP2.lyr";
canSaveDynamicFields = "1";
class = "LevelButtonClass";
Position = "40.000 55.000";
size = "30.000 30.000";
Layer = "14";
CollisionMaxIterations = "1";
mountID = "15";
};
new t2dParticleEffect() {
effectFile = "~/data/particles/SpeedshotExplode.eff";
useEffectCollisions = "1";
effectMode = "INFINITE";
effectTime = "100";
canSaveDynamicFields = "1";
Position = "80.000 55.000";
size = "32.000 32.000";
SortPoint = "0.038 0.042";
Layer = "16";
CollisionMaxIterations = "1";
mountID = "16";
};
new t2dTileLayer(Boss1) {
LayerFile = "~/data/tilemaps/Parallax/TP2.lyr";
canSaveDynamicFields = "1";
class = "LevelButtonClass";
Position = "80.000 55.000";
size = "30.000 30.000";
Layer = "1";
CollisionMaxIterations = "1";
SrcBlendFactor = "ONE_MINUS_SRC_ALPHA";
DstBlendFactor = "SRC_COLOR";
BlendColor = "0.482353 0.482353 0.482353 1";
mountID = "17";
};
new t2dStaticSprite(Level1) {
imageMap = "PlatImageMap";
frame = "0";
sourceRect = "0 0 0 0";
canSaveDynamicFields = "1";
UseMouseEvents = "1";
Position = "-80.000 -55.000";
size = "30.000 30.000";
WorldLimitMin = "-455.000 -430.000";
WorldLimitMax = "295.000 320.000";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
CollisionCallback = "1";
mountID = "18";
};
new t2dTileLayer(Level8) {
LayerFile = "~/data/tilemaps/Parallax/TP2.lyr";
canSaveDynamicFields = "1";
class = "LevelButtonClass";
size = "30.000 30.000";
Layer = "14";
CollisionMaxIterations = "1";
mountID = "19";
};
new t2dTextObject() {
canSaveDynamicFields = "1";
Position = "-80.300 -54.000";
size = "23.400 8.000";
BlendColor = "0 0.615686 1 1";
text = "Level 1";
font = "Arial Rounded MT Bold";
wordWrap = "0";
hideOverflow = "1";
textAlign = "Left";
lineHeight = "8";
aspectRatio = "1";
lineSpacing = "0";
characterSpacing = "0";
autoSize = "1";
fontSizes = "40";
textColor = "0 0.615686 1 1";
bilinearFilter = "0";
snapToInteger = "0";
noUnicode = "0";
hideOverlap = "0";
mountID = "20";
};
new t2dTextObject() {
canSaveDynamicFields = "1";
Position = "-40.300 -54.000";
size = "23.400 8.000";
BlendColor = "0 0.615686 1 1";
text = "Level 2";
font = "Arial Rounded MT Bold";
wordWrap = "0";
hideOverflow = "1";
textAlign = "Left";
lineHeight = "8";
aspectRatio = "1";
lineSpacing = "0";
characterSpacing = "0";
autoSize = "1";
fontSizes = "40";
textColor = "0 0.615686 1 1";
bilinearFilter = "0";
snapToInteger = "0";
noUnicode = "0";
hideOverlap = "0";
mountID = "21";
};
new t2dTextObject() {
canSaveDynamicFields = "1";
Position = "-0.300 -54.000";
size = "23.400 8.000";
BlendColor = "0 0.615686 1 1";
text = "Level 3";
font = "Arial Rounded MT Bold";
wordWrap = "0";
hideOverflow = "1";
textAlign = "Left";
lineHeight = "8";
aspectRatio = "1";
lineSpacing = "0";
characterSpacing = "0";
autoSize = "1";
fontSizes = "40";
textColor = "0 0.615686 1 1";
bilinearFilter = "0";
snapToInteger = "0";
noUnicode = "0";
hideOverlap = "0";
mountID = "22";
};
new t2dTextObject() {
canSaveDynamicFields = "1";
Position = "39.700 -54.000";
size = "23.400 8.000";
BlendColor = "0 0.615686 1 1";
text = "Level 4";
font = "Arial Rounded MT Bold";
wordWrap = "0";
hideOverflow = "1";
textAlign = "Left";
lineHeight = "8";
aspectRatio = "1";
lineSpacing = "0";
characterSpacing = "0";
autoSize = "1";
fontSizes = "40";
textColor = "0 0.615686 1 1";
bilinearFilter = "0";
snapToInteger = "0";
noUnicode = "0";
hideOverlap = "0";
mountID = "23";
};
new t2dTextObject() {
canSaveDynamicFields = "1";
Position = "79.700 -54.000";
size = "23.400 8.000";
BlendColor = "0 0.615686 1 1";
text = "Level 5";
font = "Arial Rounded MT Bold";
wordWrap = "0";
hideOverflow = "1";
textAlign = "Left";
lineHeight = "8";
aspectRatio = "1";
lineSpacing = "0";
characterSpacing = "0";
autoSize = "1";
fontSizes = "40";
textColor = "0 0.615686 1 1";
bilinearFilter = "0";
snapToInteger = "0";
noUnicode = "0";
hideOverlap = "0";
mountID = "24";
};
new t2dTextObject() {
canSaveDynamicFields = "1";
Position = "80.700 1.000";
size = "27.400 8.000";
BlendColor = "0 0.615686 1 1";
text = "Level 10";
font = "Arial Rounded MT Bold";
wordWrap = "0";
hideOverflow = "1";
textAlign = "Left";
lineHeight = "8";
aspectRatio = "1";
lineSpacing = "0";
characterSpacing = "0";
autoSize = "1";
fontSizes = "40";
textColor = "0 0.615686 1 1";
bilinearFilter = "0";
snapToInteger = "0";
noUnicode = "0";
hideOverlap = "0";
mountID = "25";
};
new t2dTextObject() {
canSaveDynamicFields = "1";
Position = "-80.300 1.000";
size = "23.400 8.000";
BlendColor = "0 0.615686 1 1";
text = "Level 6";
font = "Arial Rounded MT Bold";
wordWrap = "0";
hideOverflow = "1";
textAlign = "Left";
lineHeight = "8";
aspectRatio = "1";
lineSpacing = "0";
characterSpacing = "0";
autoSize = "1";
fontSizes = "40";
textColor = "0 0.615686 1 1";
bilinearFilter = "0";
snapToInteger = "0";
noUnicode = "0";
hideOverlap = "0";
mountID = "26";
};
new t2dTextObject() {
canSaveDynamicFields = "1";
Position = "-40.300 1.000";
size = "23.400 8.000";
BlendColor = "0 0.615686 1 1";
text = "Level 7";
font = "Arial Rounded MT Bold";
wordWrap = "0";
hideOverflow = "1";
textAlign = "Left";
lineHeight = "8";
aspectRatio = "1";
lineSpacing = "0";
characterSpacing = "0";
autoSize = "1";
fontSizes = "40";
textColor = "0 0.615686 1 1";
bilinearFilter = "0";
snapToInteger = "0";
noUnicode = "0";
hideOverlap = "0";
mountID = "27";
};
new t2dTextObject() {
canSaveDynamicFields = "1";
Position = "-0.300 1.000";
size = "23.400 8.000";
BlendColor = "0 0.615686 1 1";
text = "Level 8";
font = "Arial Rounded MT Bold";
wordWrap = "0";
hideOverflow = "1";
textAlign = "Left";
lineHeight = "8";
aspectRatio = "1";
lineSpacing = "0";
characterSpacing = "0";
autoSize = "1";
fontSizes = "40";
textColor = "0 0.615686 1 1";
bilinearFilter = "0";
snapToInteger = "0";
noUnicode = "0";
hideOverlap = "0";
mountID = "28";
};
new t2dTextObject() {
canSaveDynamicFields = "1";
Position = "39.700 1.000";
size = "23.400 8.000";
BlendColor = "0 0.615686 1 1";
text = "Level 9";
font = "Arial Rounded MT Bold";
wordWrap = "0";
hideOverflow = "1";
textAlign = "Left";
lineHeight = "8";
aspectRatio = "1";
lineSpacing = "0";
characterSpacing = "0";
autoSize = "1";
fontSizes = "40";
textColor = "0 0.615686 1 1";
bilinearFilter = "0";
snapToInteger = "0";
noUnicode = "0";
hideOverlap = "0";
mountID = "29";
};
new t2dTextObject() {
canSaveDynamicFields = "1";
Position = "79.700 56.000";
size = "27.400 8.000";
BlendColor = "0 0.615686 1 1";
text = "Level 16";
font = "Arial Rounded MT Bold";
wordWrap = "0";
hideOverflow = "1";
textAlign = "Left";
lineHeight = "8";
aspectRatio = "1";
lineSpacing = "0";
characterSpacing = "0";
autoSize = "1";
fontSizes = "40";
textColor = "0 0.615686 1 1";
bilinearFilter = "0";
snapToInteger = "0";
noUnicode = "0";
hideOverlap = "0";
mountID = "30";
};
new t2dTextObject() {
canSaveDynamicFields = "1";
Position = "-80.300 56.000";
size = "27.400 8.000";
BlendColor = "0 0.615686 1 1";
text = "Level 12";
font = "Arial Rounded MT Bold";
wordWrap = "0";
hideOverflow = "1";
textAlign = "Left";
lineHeight = "8";
aspectRatio = "1";
lineSpacing = "0";
characterSpacing = "0";
autoSize = "1";
fontSizes = "40";
textColor = "0 0.615686 1 1";
bilinearFilter = "0";
snapToInteger = "0";
noUnicode = "0";
hideOverlap = "0";
mountID = "31";
};
new t2dTextObject() {
canSaveDynamicFields = "1";
Position = "-40.300 56.000";
size = "27.400 8.000";
BlendColor = "0 0.615686 1 1";
text = "Level 13";
font = "Arial Rounded MT Bold";
wordWrap = "0";
hideOverflow = "1";
textAlign = "Left";
lineHeight = "8";
aspectRatio = "1";
lineSpacing = "0";
characterSpacing = "0";
autoSize = "1";
fontSizes = "40";
textColor = "0 0.615686 1 1";
bilinearFilter = "0";
snapToInteger = "0";
noUnicode = "0";
hideOverlap = "0";
mountID = "32";
};
new t2dTextObject() {
canSaveDynamicFields = "1";
Position = "-0.300 56.000";
size = "27.400 8.000";
BlendColor = "0 0.615686 1 1";
text = "Level 14";
font = "Arial Rounded MT Bold";
wordWrap = "0";
hideOverflow = "1";
textAlign = "Left";
lineHeight = "8";
aspectRatio = "1";
lineSpacing = "0";
characterSpacing = "0";
autoSize = "1";
fontSizes = "40";
textColor = "0 0.615686 1 1";
bilinearFilter = "0";
snapToInteger = "0";
noUnicode = "0";
hideOverlap = "0";
mountID = "33";
};
new t2dTextObject() {
canSaveDynamicFields = "1";
Position = "39.700 56.000";
size = "27.400 8.000";
BlendColor = "0 0.615686 1 1";
text = "Level 15";
font = "Arial Rounded MT Bold";
wordWrap = "0";
hideOverflow = "1";
textAlign = "Left";
lineHeight = "8";
aspectRatio = "1";
lineSpacing = "0";
characterSpacing = "0";
autoSize = "1";
fontSizes = "40";
textColor = "0 0.615686 1 1";
bilinearFilter = "0";
snapToInteger = "0";
noUnicode = "0";
hideOverlap = "0";
mountID = "34";
};
};You'll probably see that with the tilemaps, I didn't enable mouseEvents, so just try the first thing, the sceneObject and you'll see it's not functional. I'm also getting this error:
Quote:Error: cannot change namespace parent linkage of LevelButtonClass from t2dTileLayer to t2dStaticSprite.
Does that mean I can't have a tilemap and a sceneobject all share the same class or something?
#2
09/06/2013 (2:27 pm)
Thanks, I solved the namespace problem. However I am now faced with a new problem. OnMouseEnter and such are stock TGB functions and have worked in the past. I want it so that when your cursor touches one of the level buttons, it is supposed to cut the alpha of that button down to 0.5 so you can tell when the mouse has entered something. However, TGB doesn't seem to want to do that even though I wrote it out to do so in a script. The blend color changes aren't working, but the button hover sound effect does, as does the command to pop up a dialog that asks you if you want to load a level. Any help with this would be appreciated.
#3
09/07/2013 (6:41 am)
Torque can be ticklish about numbers. Try this:// replace this %this.Owner.blendColor = "1 1 1 0.5"; // with this %this.Owner.blendColor = "1.0 1.0 1.0 0.5";That should fix it, cross your fingers (after you type it, of course)....
#4
Thanks for all of your help, everythings working great, now. :)
09/07/2013 (11:01 am)
Actually, the problem was with "%this.Owner". Apparently, it's OK to just write "%this"!Thanks for all of your help, everythings working great, now. :)
#5
09/07/2013 (1:18 pm)
Oh, hell - yeah, the "owner" is for use with behaviors - %this is the behavior instance and %this.owner is the object the behavior is assigned to. In class methods you use %this directly for the object.
Associate Simon Love
As stated, a script class will need to stick with one type of object parent object, either a tilelayer or staticsprite but not both.
As for the OnMouseEnter callbacks, I'm not 100% sure about TGB, but in T2D MIT, these events are not implemented on Sceneobjects. They are implemented on SceneWindow and other gui controls.
The easiest way to get it to work would be to modify the source code and add the onMouseEnter, onMouseLeave callbacks. I think there was a ressource about this posted in the last few months but I can't seem to find it at the moment.