Jump to content

Mr TwinkleToes


Recommended Posts

having a problem with the collisionbox for the moving platform it moves but does not change the size to be the size of the image, its the size of the area then the platform has to move through(left to right) here is the image with the hitbox bounds on



now here is the code don't know why its not doing what it should do


 floating Plataform
 ----------------- */
game.movingPlatforms = me.Entity.extend({
    init: function(x, y, settings) {
        // define this here instead of tiled
        settings.image = "platform_2";

       //values from tiled on the size of the area to move within
        var area_width = settings.width;
        var area_height = settings.height;;
        //sprite area
        settings.width = settings.framewidth = 64;
        settings.height = settings.frameheight = 32;

        this._super(me.Entity, 'init', [x, y , settings]);

        this.body.collisionType = me.collision.types.WORLD_SHAPE;
        this.body.setCollisionMask(me.collision.types.WORLD_SHAPE | me.collision.types.PLAYER_OBJECT);
        // set start/end position based on the initial area size
        initial_start_pos_x = this.pos.x;
        this.startX = initial_start_pos_x;
        this.endX   = this.startX + area_width - settings.framewidth;;
        this.pos.x  = this.startX + area_width;
        // manually update the entity bounds as we manually change the position
        // to remember which side we were walking
        this.walkLeft = false;
        this.alwaysUpdate = true;

        // velocity
        this.body.setVelocity(2, 5);
    update : function (dt) 
        this.body.gravity = 0;
        if (this.walkLeft && this.pos.x <= this.startX) 
            this.walkLeft = false;
        else if (!this.walkLeft && this.pos.x >= this.endX) 
            this.walkLeft = true;
        // make it walk
        this.body.vel.x += (this.walkLeft) ? -this.body.accel.x * me.timer.tick : this.body.accel.x * me.timer.tick;
        // update the body movement

        // handle collisions against other shapes

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


have not a clue as to why the collision box is not the right size



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