Game Development Community

onMouseDragged doesnt work after upgrading to 1.3

by Hitesh Patel · in iTorque 2D · 01/07/2010 (11:19 am) · 43 replies

I have upgraded to 1.3 and i have to say my game load time is cut in to half. It only takes 6 secs to load, excellent. But there are two problems:

1. In my game i need to drag objects to move them around. Before i used to be able to do this fine but with 1.3 dont seem to be able. I think its something to with the bug fix about onMouseUp. I saw the same issue when I tried to apply the bug fixes in the following article http://www.torquepowered.com/community/forums/viewthread/93467 and multitouch resources created by Dave Calabrese

2. When i press the play button in my game the objects are suppose to move, I am using setLinearVeloicty commands to move the objects. But this stopped working as well.

Thanks
#21
01/13/2010 (6:51 pm)
The changes mentioned above become obvious if you open the mainScreen.gui file of your project (its in game/gui ) and look at the Block that creates your t2dSceneWindow.

If you don't want to mess with it manually you can basically just copy that block from the iPhoneExample project

I'm not 100% sure if it was all but basically one of the things I attempted and the only one I can bring in relation to the input.
#22
01/18/2010 (7:52 pm)
I'm getting close to just putting a function in the game to get onMouseDragged to work. It almost works, I think the getWorldPoint is incorrect:

function oniPhoneTouchMove( %touchCount, %touchX, %touchY )  
{  
   %worldPos = sceneWindow2D.getWorldPoint( %touchX SPC %touchY );
   %scenegraph = sceneWindow2D.getSceneGraph();
   %objects = %scenegraph.pickPoint(%worldPos.x, %worldPos.y);
   for (%i = 0; %i < getWordCount(%objects); %i++)
   {
      %object = getWord(%objects, %i);
      //If it uses mouse events and onMouseDragged
      if (%object.getUseMouseEvents() && isMethod(%object.class, onMouseDragged)) 
         %object.onMouseDragged(%object, %worldPos, 0, %touchCount);
   }
}
#23
01/28/2010 (12:19 pm)
Has anybody got any updates on this????
#24
01/28/2010 (12:25 pm)
Check your mainscreen.gui file if the extends it uses are correct for your game
#25
01/28/2010 (12:41 pm)
I am sorry i didnt update the post. I tried it as per your earlier suggestion but it didnt make any difference. So at the moment i am still using 1.2.
#26
01/28/2010 (5:21 pm)
Finally figured it out! I've tested it and this workaround works. I forgot that oniPhoneTouchMove gets multiple touches. Here's the code, just put it somewhere in the game:

function oniPhoneTouchMove( %touchCount, %touchX, %touchY )  
{
   %pos = getWord(%touchX, 0) SPC getWord(%touchY, 0);   //To get the first touch
   %worldPos = sceneWindow2D.getWorldPoint(%pos);
   %scenegraph = sceneWindow2D.getSceneGraph();
   %objects = %scenegraph.pickPoint(%worldPos.x, %worldPos.y);
   for (%i = 0; %i < getWordCount(%objects); %i++)
   {
      %object = getWord(%objects, %i);
      //If it uses mouse events and onMouseDragged
      if (%object.getUseMouseEvents() && isMethod(%object.class, onMouseDragged)) 
         %object.onMouseDragged(0, %worldPos, 1);
         //Assumes class::onMouseDragged(%this, %modifier, %worldPos, %clicks)
   }
}
#27
01/28/2010 (5:27 pm)
I didn't need any workaround code to have mouse events working again.

was just a matter of fixing all the old 1.2 scripts to be 1.3 compliant (adding in the dummy callbacks for oniPhoneTouchxy into main.cs, fixing the gui extent and min extent ...)

the sample project basically shows you what you need (it also shows that the mouse evnets work when you have setup the stuff correctly)
#28
01/28/2010 (5:54 pm)
Wait, you're saying you can get onMouseDragged to work if you follow the sample project? How? I understand that the old scripts need to be effectively updated, but more importantly I need, and I think the torque community needs, onMouseDragged to just work.
#29
01/28/2010 (6:01 pm)
it just works

check out the sample project and you see it works
#30
01/28/2010 (6:43 pm)
No, it really doesn't just work. If I put in the following code in game.cs:

function leftArrow::onMouseDragged (%this, %modifier, %worldPos, %clicks)
{
     %this.setPosition(%worldPos);
}

I'll notice the left arrow move when dragging on a Mac or Windows, but when I put it on the iPhone, it does nothing. Granted you could use oniPhoneTouchMove to make it work. It is very difficult, however, to convert games that have onMouseDragged (which returns the object that it is dragging and checks for usable mouseEvents) to oniPhoneTouchMove.
#31
01/29/2010 (10:23 am)
Looking further into this, it seems to work perfect everywhere except on device?

I didnt see any problems, ill re test and see what happens :)
#32
01/29/2010 (5:40 pm)
Correct. I think it even worked on the iPhone Simulator, but not on the iPhone itself.
#33
02/04/2010 (11:17 am)
It wasn't working on the simulator or Iphone for me. Joe's oniPhoneTouchMove() does seem to restore the drag functionality. Thanks Joe! Hope this can be corrected to not need the code section though because it should work out of the box like it does for win/mac.
#34
02/10/2010 (7:30 pm)
Hey Joe,

thanks for your workaround code! I'm implementing dragging in my game and am bummed out that it's not working in the simulator or device. I entered your code and now I am able to drag, but just for a short distance. Basically, the object I'm dragging does not keep up with the mouse. It will move a little bit, and then stop, even if the mouse continues moving.

I'll see if I can figure out a solution to this.
#35
02/11/2010 (12:52 pm)
@Rachel
Make sure you copied the code from the second post, as I had that problem with the first post. I'm sure that running the workaround script-side is slow and it would be better implemented through source, but I'm not going to mess around with the source code for something that will probably be fixed in the near future.
#36
02/11/2010 (6:26 pm)
You're talking about this code, right:

function oniPhoneTouchMove( %touchCount, %touchX, %touchY )    
{  
   %pos = getWord(%touchX, 0) SPC getWord(%touchY, 0);   //To get the first touch  
   %worldPos = sceneWindow2D.getWorldPoint(%pos);  
   %scenegraph = sceneWindow2D.getSceneGraph();  
   %objects = %scenegraph.pickPoint(%worldPos.x, %worldPos.y);  
   for (%i = 0; %i < getWordCount(%objects); %i++)  
   {  
      %object = getWord(%objects, %i);  
      //If it uses mouse events and onMouseDragged  
      if (%object.getUseMouseEvents() && isMethod(%object.class, onMouseDragged))   
         %object.onMouseDragged(0, %worldPos, 1);  
         //Assumes class::onMouseDragged(%this, %modifier, %worldPos, %clicks)  
   }  
}

That's what I placed into the game. Unfortunately the object I'm dragging doesn't keep up with the mouse, so soon the mouse isn't over the object any more, causing the object to no longer be dragged. I really hope they fix this problem soon for the software so I can test my game better on the device. What a bummer...
#37
02/12/2010 (3:28 pm)
Hmm, I don't seem to be having that problem. So you're saying it will drag perfectly on the screen on Mac and Windows, but not on the iPhone?
#38
02/16/2010 (3:40 pm)
Yes, that's correct. Sorry for the late reply, been away for a few days.
#39
03/25/2010 (12:06 pm)
If you are like me and do most of your dev on a windows workstation, you can add back the mouse events and simply include a #ifndef TORQUE_OS_IPHONE statement in guiButtonBaseCtrl.cc. This would of saved a lot of us some trouble. You can then do the same thing in the script files so you can have a portion of the script code that works in windows and a portion that works on the iphone. This is the whole point of being able to build your project on Windows or on a Mac.

Here's an example:

in guiButtonBaseCtrl.cc
void GuiButtonBaseCtrl::onMouseUp(const GuiEvent &event)
{
   if (! mActive)
      return;

   mouseUnlock();

#ifndef TORQUE_OS_IPHONE

   setUpdate();

   if(mUseMouseEvents)
      Con::executef( this, 1, "onMouseUp" );

#endif

   //if we released the mouse within this control, perform the action
   if (mDepressed)
      onAction();

   mDepressed = false;
}

in Torque Script
if( $platform $= "iPhone" ){}
#40
03/25/2010 (4:51 pm)
I wanted to also request that the next revision have the mouse events added back so they will work in the windows build. Removing functionality for one platform so another will work is not a fix. This is why we have compiler flags and etc. If you need to add more code then that's what you do, you don't just rip code out and call it a day. It boggles the mind that 1.3.x was released this way. Someone dropped the ball and wasted a lot of game developers time. I read the reason for ripping out the code and I find it novice. This is not how you roll out code.