Game Development Community

onMouseDown Unreliable?

by rennie moffat · in iTorque 2D · 04/07/2011 (12:26 pm) · 10 replies

Hi there,
I am doing some coding in building a project. I am using two secengraphs, but that should not really matter. What does is that I have a behvaior using mouse events and it occasionally gets called. In other words, onMouseDown, over the visible object, I get no return from the mouseDown function which is attached to the owner object, the one I am pressing.

Is there any bug going on that I should know about? The behavior is attached as an echo in the obBehaviorAdd is called. Little miffed.


:S
thanks.

if (!isObject(amlocalBtnBehavior))
{
   %template = new BehaviorTemplate(amlocalBtnBehavior);
   
   %template.friendlyName = "Various Map local Location Btn";
   %template.behaviorType = "Various Map";
   %template.description  = "Alllows InfoSheet to be called up for local";

}

function amlocalBtnBehavior::onBehaviorAdd(%this)
{
	%this.owner.setUseMouseEvents(true);
	$localBtnActive = false;
	$localLocation = %this.owner.position;
	echo("====================================");
	echo("====================================");
	echo("====================================");
	echo("====================================");
	echo("====================================");
	echo("====================================");
	echo("====================================");
	echo("====================================");
	echo("====================================");
	echo("====================================");
	echo("====================================");
	echo("====================================");
	echo("====================================");
}

function amlocalBtnBehavior::onMouseDown( %this, %mod, %worldPos, %mouseClicks)
{
	echo("localBtn onMouseDown");
	echo("M O L L Y G O O D ");
	echo(" M O L L Y G O O D ");
	echo("M O L L Y G O O D ");
	echo(" M O L L Y G O O D ");
	echo("M O L L Y G O O D ");
	echo(" M O L L Y G O O D ");
	echo("M O L L Y G O O D ");
	echo(" M O L L Y G O O D ");	
	
	%localLocalPt = %this.owner.getLocalPoint();
	%localWorldPt = %this.owner.getWorldPoint();
	echo("%localLocalPt" @ %localLocalPt);
	echo("%localWorldPt" @ %localWorldPt);
	
	if($localBtnActive == true)
	{
		$localBtnActive = false;
		echo("$localBtnActive" @ $localBtnActive);
	}
	else if($localBtnActive == false)
	{
		$localBtnActive = true;
		$infoSheet.setPosition($localLocation);
		echo("$localBtnActive" @ $localBtnActive);
	}	
}

function amlocalBtnBehavior::onBehaviorRemove(%this)
{
	$localBtnActive = false;
}

About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
04/07/2011 (12:50 pm)
Works for me every time. Though you have several errors/warnings:

====================================
====================================
====================================
====================================
====================================
====================================
====================================
====================================
====================================
====================================
====================================
====================================
====================================
Loaded compiled script C:/Torque/it2d/trunk/MyProjects/BmpTest/projectFiles/game/data/levels/emptyLevel.t2d. Took 6 ms
localBtn onMouseDown
M O L L Y G O O D 
 M O L L Y G O O D 
M O L L Y G O O D 
 M O L L Y G O O D 
M O L L Y G O O D 
 M O L L Y G O O D 
M O L L Y G O O D 
 M O L L Y G O O D 
game/scripts/behaviors/localButton.cs (43): t2dStaticSprite::getLocalPoint - wrong number of arguments.
game/scripts/behaviors/localButton.cs (43): usage: (float worldX, float worldY) - Returns local-point for object.
Converts a point in world space to object space.
@param worldX The world position x you want to convert into local x.@param worldY The world position y you want to convert into local y.@return (float localX / float local Y) The local position that was converted from the world position passed.
game/scripts/behaviors/localButton.cs (44): t2dStaticSprite::getWorldPoint - wrong number of arguments.
game/scripts/behaviors/localButton.cs (44): usage: (float localX, float localY) - Returns world-point from object.
Converts a point in object space to world space.
@param localX The local x position you want to convert into world x.@param localY The local y position you want to convert into world y.@return (float worldX / float worldY) The world position that was converted from the local position passed.
%localLocalPt
%localWorldPt
game/scripts/behaviors/localButton.cs (56): Unable to find object: '' attempting to call function 'setPosition'
$localBtnActive1

Outside of that, the onMouseDown works each time I click.
#2
04/07/2011 (12:54 pm)
wierd. It doenst for me. I even removed the extra scenegrapgh, tho that should not matter right?



Anyhow, thanks. Will keep messing about.

What is more odd tho is that I do not get the return


M O L L Y G O O D   
 M O L L Y G O O D   
M O L L Y G O O D   
 M O L L Y G O O D   
M O L L Y G O O D   
 M O L L Y G O O D   
M O L L Y G O O D   
 M O L L Y G O O D



but I do get
$localBtnActive 1
///or ...
$localBtnActive 0


coming from my game script.


:?







Edit:
When using mouseEvents on objects, does anything but the collision boundaries, set or not matter in terms of what triggers the event. In other words, if I have an t2dSceneObject, that is not a sprite of any kind, just an "empty box" if tapped inside that area, should I get a response?
#3
04/07/2011 (12:59 pm)
Not sure what is happening. Looks like you have some more debugging ahead of you.
#4
04/07/2011 (1:18 pm)
right.
thanks.
#5
04/09/2011 (9:08 am)
@Michael,
or whomever,

I am still experienceing glitchy returns on my mouseDown. Let me explain the situation and where it is and is not called.



On the device, I have the scroll working. On a large level, that is scrollable, I have buttons placed in various places. Just for testing I have placed a button (BTN) a 0 SPC 256. When BTN is in the lower half of the devices screen, it tends to call 80 - 90 % of the time. While in the upper half tho, it calls maybe 10 % of the time. I had noticed a thread a while back suggesting a similar lack of response with 1.4.1 and the iPad. Will investigate.


On a side note I have began to simply use the game.cs onTap, if tap coordinates are with in a certain area, to replace the object placement. Seems to work, much better. But still puzzling as to what is happening with the objects and mouse downs.





Here is a video I have recorded to show the issue at work. Each time onMouseDown, for the big green square I am clicking on, I should have the return....


echo("NewYorkBtn onMouseDown");
	echo("N Y  N Y  N Y  N Y ");
	echo(" N Y  N Y  N Y  N Y ");
	echo("N Y  N Y  N Y  N Y ");
	echo(" N Y  N Y  N Y  N Y ");
	echo("N Y  N Y  N Y  N Y ");
	echo(" N Y  N Y  N Y  N Y ");
	echo("N Y  N Y  N Y  N Y ");
	echo(" N Y  N Y  N Y  N Y ");


.... in the video it will appear smaller but you can make out the shape vs all other call backs. As you will see, when the green block is in the lower half of the screen it tends to return. While in the upper half, it tends not to. I have nothing in the code to prevent this from being so. Is there an issue we need to look at?

www.youtube.com/watch?v=qSLLzbsm3lg

Thanks
Ren


#6
04/09/2011 (9:29 am)
I have experienced something similar, when you come to build your app, ensure that you select iPad for the 'Devices' if you're running on an iPad, it'll ask you if you'd like to convert the window or some such message and you MUST say yes.
#7
04/09/2011 (9:32 am)
What if this version is just iPhone. or vice versa? as I think I want to release separate titles for each device.


: Thanks.

This is serious ishness tho dont you think?
#8
04/09/2011 (9:53 am)
What you could do is copy the XCode_iPhone folder and rename it to XCode_iPad or something and keep the project settings separate.
#9
04/09/2011 (9:54 am)
Right,
Thanks.
#10
04/11/2011 (10:40 am)
@Anyone, staff etc.
I am still experiencing much glitchiness with the mouse event calls. Again, I have an object, that is quite large (should not make a difference), whose echo is being returned in the iTGB console but not in XCode.



Any help?


Looking up now.