Game Development Community

SOLVED: onMouseDown acting up (TGB)

by Jonathan R Hopkins · in Technical Issues · 09/16/2009 (6:21 pm) · 1 replies

Solution
Objects must be added to the sceneGraph in order to actually exist and be physically active. Using addToScene to add each object solved the problem.

Problem
This is really confusing. onMouseDown doesn't seem to be working for a certain object class I've made. I have multiple objects in a different situation that use it and it works fine, but these ones, which all share the same class, don't work. I don't get an error, or anything at all. I click, and nothing happens. The following is part of a .cs file:

Note, for simplification purposes, I took out pieces of code that was irrelevant.
new SimSet(clickRegions);

function RegionClass::onMouseDown(%this, %modifier, %worldPosition, %clicks)
   {
   ...
   }

function regionSetup(%camera)
{
   ...
   
   clickRegions.clear();
   
   //Sets up flex regions
   for(%n=0;%n < (%camera.getCount());%n++)
   {
      echo("Checking index: " @ %n);
      %region = %camera.getObject(%n);
      %regionObj = new t2dSceneObject()
      {
         execute = %region.execute;
         class = "RegionClass";
      };
      %regionObj.setUseMouseEvents(true);
      %regionObj.setPosition(%region.x,%region.y);
      %regionObj.setSize(%region.width, %region.height);
      clickRegions.add(%regionObj);
      ...
   }

They have the class. The function is in place. The objects are created properly, sized, and placed. They don't have an image but neither do the similar objects that DO work.

For example, these objects do work:

First it is defined in the scene ".t2d" file.
new t2dSceneObject() {
      canSaveDynamicFields = "1";
      class = "clickRegionCenter";
      useMouseEvents = "1";
      Position = "2.014 -1.000";
      size = "40.102 28.000";
      Layer = "1";
      WorldLimitMin = "-261.383 -560.340";
      WorldLimitMax = "199.832 565.314";
      CollisionCallback = "1";
         mountID = "8";

And here is the corresponding code (Once again irrelevant code is removed):

function clickRegionCenter::onMouseDown(%this, %modifier, %worldPosition, %clicks)
   {
   ...
   }

The big difference between the object that does work (clickRegionCenter) and the one that doesn't (RegionClass) is that clickRegionCenter is pretty much in the same place the whole time and doesn't change, while RegionClass is deleted and re-created for each new scene.

Any ideas?

#1
09/16/2009 (7:11 pm)
Once again I solved the problem myself... Oh well. :) The solution is detailed above.