Box2D Forums

It is currently Sat May 25, 2013 10:52 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Thu Jun 14, 2012 2:52 pm 
Offline

Joined: Thu Mar 01, 2012 9:31 am
Posts: 153
Is there a global way to set "allowDragging = false" for all objects added to the world or does allowDragging have to be set to false for each object?


Top
 Profile  
 
PostPosted: Fri Jun 15, 2012 8:07 am 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 913
You can set allowDragging = false on the wck.World object. This will disable dragging globally.

Or you could extend BodyShape, override create() to disable dragging conditionally, then extend that instead of BodyShape directly.


Top
 Profile  
 
PostPosted: Fri Jun 15, 2012 1:26 pm 
Offline

Joined: Thu Mar 01, 2012 9:31 am
Posts: 153
Thanks for the suggestions. I forgot to mention that I did see allowDragging in the world class and tried allowDragging = false on the wck.World. There were no errors so I thought it should work but I was able to drag objects.

After I posted my previous post and some thinking, based on your past suggestions, extending BodyShape and setting allowDragging there was one possibility. Of course, as a programmer you tend to go for the simplest solution but if the first method doesn't work then I'll go with the second.

My objects are extending BodyShape and I looked at the BodyShape class and the default allowDragging is set to true. I'm wondering, does your first suggestion actually work or did my engine perhaps introduce something that prevented disabling global dragging. I looked at the WCK demo but couldn't really figure out where to put allowDragging = false for the wck.World to test disabling global drag.


Top
 Profile  
 
PostPosted: Sat Jun 16, 2012 2:02 pm 
Offline

Joined: Thu Mar 01, 2012 9:31 am
Posts: 153
I did a little test. If I create myWorld in Flash with base class wck.World then myWorld.allowDragging = false works as expected. If I declare myWorld = new wck.World in the code then other things I've tested seem to work but not allowDragging. Strange.

When I trace myWorld.allowDragging on StepEvent.STEP it is set to false. Strange.

I did come across something similar with joints (where "drag and drop" works but code doesn't) but I'll post that later.


Top
 Profile  
 
PostPosted: Sun Jun 17, 2012 3:51 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 913
Hmm... I'm going to have to look at allowDragging & make sure it works as intended, been a while.

For now, why don't use just override "handleDragStart(e:Event):void" in your world class so it's an empty function.


Top
 Profile  
 
PostPosted: Sun Jun 17, 2012 5:11 pm 
Offline

Joined: Thu Mar 01, 2012 9:31 am
Posts: 153
That could work. In my current game, I only have one dynamic object so I only have to set one allowDragging. But later on that might be preferable.


Top
 Profile  
 
PostPosted: Tue Jun 19, 2012 1:31 pm 
Offline

Joined: Thu Mar 01, 2012 9:31 am
Posts: 153
Not sure if this has anything to do with the global allowDragging issue but during a quick test all but two of the joint component properties disappeared from the component inspector (Flash CS4). After a restart those came back, but ... sometimes Flash seem to do some strange things.


Top
 Profile  
 
PostPosted: Mon Jul 09, 2012 7:22 pm 
Offline

Joined: Thu Mar 01, 2012 9:31 am
Posts: 153
I took a look at allowDragging again because I was able to change gravity with MyWorld.gravityX and .gravityY. But even when I set
Code:
[Inspectable(defaultValue=true)]
      public var allowDragging:Boolean = true;
in wck.World to false, it doesn't seem to have any effect.

Im wondering, in wck.World:
Code:
public function handleDragStart(e:Event):void {
         var b:BodyShape = Util.findAncestorOfClass(e.target as DisplayObject, BodyShape, true) as BodyShape;
         if(b && b.b2body && b.allowDragging && b.body.allowDragging) {
isn't the last line supposed to check for the wck.World allowDragging? If I add to check for allowDragging also, then it works, even in my class that extends WCK with MyWorld.allowDragging.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group