AS3 2.1 Port (Alchemy), WCK Update and Kinematic Demos

@Frnk

normals sound like the most generic way to test if a collision is in a downward direction.
however y position would be a valid method as well, and probably be easier for you to add a buffer to to get around this problem.

y positions of box2d shapes are generally centered so you would need to account for height as well.

here is a link where y position is used instead of normals.
http://www.emanueleferonato.com/2010/03 ... ka-clouds/
thanks, sketch, i will try this.

While figuring this out i got really tired of the trace command, not beeing able to follow dynamic objects etc.
So I have added a bubbleTalk method to the BodyShape class.

Code:
BodyShape.as
...

      public function bubbleTalk(_t:String, _alpha:Number, _bubble:Boolean, _traceText:Boolean, _timeout:uint):void {
         // create new text bubble
         var bt:BubbleTalk = new BubbleTalk (this, stage, world, _t, _alpha, _bubble, _traceText, _timeout);
         world.addChild(bt);         
      }


Now all objects can talk in a text bubble that removes itsself after _timeout in seconds.
The text bubble follows dynamic objects and also stays horizontal on rotating objects. (It was funny when it rotated with the object ^^)

Here's an example if debugDraw is on, kinda helps me to customize it quickly for different debugging scenarios:
The code added to the BodyShape constructor is
Code:
         if (world.debugDraw)
         {
            var bubbleText:String = ("My name is: " + this.name + "\nI am a \"" + getQualifiedClassName(this) +"\"" + "\nPos:" + this.x + "," + this.y);
            this.bubbleTalk( bubbleText, 1 , true, false,  100);
         }
I'm also gonna use this for story and game instructions etc.
It's easy to make an object talk something on collision:
Code:
e.relatedObject.bubbleTalk("Hey you touched me" , 1, true, false,  120);


I'm thinking about extending it some, so text can be set in the component window (string, color, style etc). Also adding sensor symbols that can trigger target objects to talk something (e.g. you walk through a door but the Parrot says "Nooooooo Arrrrrr".

It's attached if someone thinks its usefull or wants to extend.

Cheers



*Update*
I noticed that BodyShape.height and BodyShape.width are actually changing if the object rotates 😮
Now positions are fixed, also the speech bubble is now a library object that can be drawn in the editor
Frnk:

Re: performance lag with the distance joint: What Connector type are you using? I wonder if that's the bottleneck.

Re: "conflict exists" error: Usually this can be solved by changing instance names. Flash is really dumb about auto creating the variables for these on classes.

Re: Platforms: I'm with sketchbook - normals are the best way to do it. You can also tweak the threshold of the normal Platform.as:

Code:
e.contact.SetSensor(n.y > -0.8);


Or even try "rounding" the edges of your platform.

Re: Talk Bubbles: I actually really like this.

It looks like you've almost got a game running (from your screenshots). You should post a demo.
@mayobutter

Thanks for fixing the joints, it allso fixed the debug draw problem. I couldn't call GetReactionForce on created weld/friction joints before, works perfectly now.

Quote:
I set up a simple project to test contact event reporting. It appears to be working as advertised (I only get the events I'm interested in). If you can PM me a full project that demonstrates your bug, I'll take a look at it.


It's easy to see in action, just add traces in b2world like this:

Code:
      public function BeginContact(c:int, a:b2Fixture, b:b2Fixture):void {
         trace("BeginContact");
         if(m_contactListener) {
            m_contactListener.BeginContact(new b2Contact(c, a, b));
         }
      }
      public function EndContact(c:int, a:b2Fixture, b:b2Fixture):void {
         trace("EndContact");
         if(m_contactListener) {
            m_contactListener.EndContact(new b2Contact(c, a, b));
         }
      }
      public function PreSolve(c:int, a:b2Fixture, b:b2Fixture, o:int):void {
         trace("PreSolve");
         if(m_contactListener) {
            m_contactListener.PreSolve(new b2Contact(c, a, b), new b2Manifold(o));
         }
      }
      public function PostSolve(c:int, a:b2Fixture, b:b2Fixture, i:int):void {
         trace("PostSolve");
         if(m_contactListener) {
            m_contactListener.PostSolve(new b2Contact(c, a, b), new b2ContactImpulse(i));
         }
      }


Then run the none wck testbed, you will get a stream of traces from all the contact callbacks that shouldn't be happening.

I seem to have found the problem though. When a fixture is created, its seems the contact reports are default set to true! (this might actualy be because of the way wck contacts work... not sure)

I have a wrapper for creating fixtures so all i do is set all four reports to false after the fixture is created, and everything is working perfectly.

Thanks again.
[quote="mayobutter"]RyuMaster: Not sure why saving the demo corrupts it. Flash CS4? For a while CS4 had problems with big projects, but they released a free patch that fixed it. Might be the issue.

Yes, flash CS4, patched to the latest. Damn it, I know something isn't right, but I have no clue where to start. HMMMMMMMM. Well, since I'm the only one getting that odd behaviour, I'll try firsty to understand, why characters stops moving (manBox), because that is the only thing which gets corrupted, and maybe then I will be able tell you more specific info.
I've updated bubbleTalk a little. It uses now all graphics, text style and formatting from the library symbol, and adjusts the bubble size to the output text automatically. Bubbles work now correctly for assembled objects / subshapes. Bubbles disappear if object is removed. Also the function call is easier with only one mandatory parameter, the rest is optional.
The shortest call would be
Code:
this.bubbleTalk("Hello");

If you want, you can assign a different bubblestyle (library object name), default is BubbleStyle1
If timeout(in seconds) is 0, the bubble will never dissappear unless object.bubble.remove() is called or the object itsslef is removed
mouseFlag makes bubbles appear on top if mouseover event is triggered (helpfull for debugDraw when you have overlapping bubbles)
If talkX and talkY is defined, it lets bubbles appear on those coordinates instead of the caller's coordinates.
[code]
Bodyshape.as
...
public function bubbleTalk(
_t:String,
_timeout:Number = 3,
_bubbleStyle:String = "BubbleStyle1",
_mouseFlag:Boolean = false,
_talkX:int = 0,
_talkY:int = 0):void
Is there an easier function in wck to determine wether an object is a subshape or has subshapes?
What i've used so far is this (i guess it won't work for subshapes of subshapes)
Code:
         if ( getQualifiedSuperclassName(_bodyParent) != "wck::World")         
         {            
            //object is subshape, use parent's coordinates instead
            _b.x = _bodyParent.x;
            _b.y = _bodyParent.y;
         }
Working on a new component, i noticed that if you enter a text (String) into the component inspector, it replaces \n with \\n
so that the linebreaks dont work anymore.
Here's a suggestion for misc.Util:
Code:
public static function fixLineBreak (text:String):String {

   // replace \\n with \n because flash component inspector is modifying the string
   var correctedText:String = text.replace(/\\n/g, "\n");
   return correctedText;
}

Cheers
Frnk wrote:
Is there an easier function in wck to determine wether an object is a subshape or has subshapes?
What i've used so far is this (i guess it won't work for subshapes of subshapes)


Yes, "selfBody" indicates if the BodyShape is the root BodyShape (it is acting as a body). If selfBody == false, you know there is a parent BodyShape. Also "body" always points to the root BodyShape, even if it is self. So in any BodyShape, if you access body.b2body, you always know that is the right b2Body.

If you're just looking for world coordinates though, you can use:

Util.localizePoint(world, this);

Original thread: https://box2d.org/forum/viewtopic.php?t=4105