Sign in to follow this  
soulVampire

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
         this.updateBounds();

         // 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;
            }
        }
        else
        {
            this.body.force.x = 0;
        }
        //this.renderable.flipX(this.walkLeft);
        // turn off gravity
        this.body.gravity = 0;
        // check & update movement
        this.body.update(dt);

        // handle collisions against other shapes
        me.collision.check(this);

        // 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) 
     {
          
     },
});

image.png

Share this post


Link to post
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.

Guest
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.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.