Box2D Forums

It is currently Thu May 23, 2013 1:14 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Dec 21, 2010 11:00 am 
Offline

Joined: Tue Dec 21, 2010 10:49 am
Posts: 2
Hi everyones!

First off, i'm a real noob using box2d! I wanted to know in the BoxMAn exemple the camera follow the player (Boxman). I've been using the BoxMan.as to use as my main class for my hero. All others things have been setup by using flash IDE. But that is i did not was able to find were is the code in all the Demo class to be able to make the camera also follow my player.

Also i've modified the structure of BoxMan to use my own MC'S with animation in it. Here no problems everything works fine. But here it is I would like to be able to replace the b2body.ApplyImpulse(new V2(-0.12, 0), b2body.GetWorldCenter()); to //b2body.SetLinearVelocity(new V2(-2, 0)); but the problem is when my player jump and i hit the left he fly straigth to the left with is walking animation-like hes walking in the air!!!!!! I don't really know to do that! So here my code rigth now :

Code:
   public class BoxMan extends Box {
      
      public var contacts:ContactList;
      
      public override function create():void {
         reportBeginContact = true;
         reportEndContact = true;
         fixedRotation = true;
         super.create();
         listenWhileVisible(world, StepEvent.STEP, parseInput, false, 10);
         listenWhileVisible(this, ContactEvent.BEGIN_CONTACT, handleContact);
         contacts = new ContactList();
         contacts.listenTo(this);
      }
      
      public function handleContact(e:ContactEvent):void {
      }
      
      public function parseInput(e:Event):void {
         var manifold:b2WorldManifold = null;
         var dot:Number = -1;
         if(!contacts.isEmpty()) {
            contacts.forEach(function(keys:Array, c:ContactEvent) {
               var wm:b2WorldManifold = c.getWorldManifold();
               if(wm.normal) {
                  var d:Number = wm.normal.dot(gravity);
                  if(!manifold || d > dot) {
                     manifold = wm;
                     dot = d;
                  }
               }
            });
            contacts.clean();
         }
         var left:Boolean = Input.kd('A', 'LEFT');
         var right:Boolean = Input.kd('D', 'RIGHT');
         var jump:Boolean = Input.kp(' ', 'UP');
         var v:V2;
         if(jump && manifold) {
            v = manifold.normal.clone().multiplyN(-3);
            b2body.ApplyImpulse(v, b2body.GetWorldCenter());
            this.gotoAndStop("jump");
         }
         else if(left) {
            //b2body.ApplyImpulse(new V2(-0.12, 0), b2body.GetWorldCenter());
            b2body.SetLinearVelocity(new V2(-2, 0)); //I've just applied it to the left rigth now!
            this.gotoAndStop("run");
            this.scaleX=1;
         }
         else if(right) {
            b2body.ApplyImpulse(new V2(0.12, 0), b2body.GetWorldCenter());
            this.gotoAndStop("run");
            this.scaleX=-1;
         }
         else {
            this.gotoAndStop("idle");
         }
      }
   }
}


Don't worry everything is include!!! Thanks all in advance!!!!


Top
 Profile  
 
PostPosted: Tue Dec 21, 2010 12:10 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 913
Set the world component property "scrolling" to true.

The world should have a "focusOn" component property. Give your BoxMan an instance name and set the "focusOn" to that name.

Or in the BoxMan "create()" function (after super.create()) you could just do something like world.scrolling = true; world.focus = this;

For the movement issue, just check the manifold variable, like if(manifold) { /* movement code */ }. manifold indicates the box man is touching something. You may also want to check the manifold normal to make sure the contact is "ground like".


Top
 Profile  
 
PostPosted: Tue Dec 21, 2010 12:56 pm 
Offline

Joined: Tue Dec 21, 2010 10:49 am
Posts: 2
Humm so easy when you know it lol! :D Thanks for the info!!!!


Top
 Profile  
 
PostPosted: Sun Jan 09, 2011 7:35 am 
Offline

Joined: Sun Jan 09, 2011 5:49 am
Posts: 6
Set the world component property "scrolling" to true.

The world should have a "focusOn" component property. Give your BoxMan an instance name and set the "focusOn" to that name.

didnt work for me,keeps puting it back to false and emptying the focus on.

and getting error 1046

Or in the BoxMan "create()" function (after super.create()) you could just do something like world.scrolling = true; world.focus = this; also didnt work =\


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 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