Jump to content

Mr TwinkleToes


Recommended Posts

have a moving platform created in the lvl, but need to create a collision area so the my player can stand on it, when i use the this.body.kinematic = false;, the platform can be moved out of the way, not what i wanted need to be able to jump on it removed the this .body.kinematic = false; from the code now can not interact with the platform in any way, so need to have a way to have a collision body so that can stand on object, but when add the kinematic the platform behaves in a way that is not what i want, the code for what i currently have is given below

 *  moving platforms Entity
game.MovingPlatformEntity = me.Sprite.extend(
      init: function (x, y, settings)
         // save the area size as defined in Tiled
         width = settings.width;

         // define this here instead of tiled
         settings.image = "platform_2";

         // adjust the size setting information to match the sprite size
         // so that the entity object is created with the right size
         settings.framewidth = settings.width = 64;
         settings.frameheight = settings.height = 32;

         // call the parent constructor
         this._super(me.Sprite, 'init', [x, y , settings]);
         // add a physic body
         this.body = new me.Body(this);
         // turn off gravity
         this.body.gravity = 0;

         // add a default collision shape
         this.body.addShape(new me.Rect(0, 0, this.width, this.height));

         // configure max speed and friction
         this.body.setMaxVelocity(settings.platform_movment_speed, 6);

         // set start/end position based on the initial area size
         x = this.pos.x;
         this.startX = x;
         this.pos.x = this.endX = x + width - this.width;
         //this.pos.x  = x + width - this.width;

         // manually update the entity bounds as we manually change the position

         // to remember which side we were walking
         this.platform_move_left = false;

         // make it "alive"
         this.alive = true;

         this.alwaysUpdate = true;

     // manage the enemy movement
    update : function (dt)
        if (this.alive)
            if (this.platform_move_left && this.pos.x <= this.startX)
                this.platform_move_left = false;
                this.body.force.x = this.body.maxVel.x;
            else if (!this.platform_move_left && this.pos.x >= this.endX)
                this.platform_move_left = true;
                this.body.force.x = -this.body.maxVel.x;
            this.body.force.x = 0;
        // turn off gravity
        this.body.gravity = 0;
        // check & update movement

        // handle collisions against other shapes

        // return true if we moved or if the renderable was updated
        return (this._super(me.Sprite, 'update', [dt]) || this.body.vel.x !== 0 || this.body.vel.y !== 0);

      * colision handler
      * (called when colliding with other objects)
     onCollision : function (response, other) 


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...