Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Actually I have my player entity with 64x64 sprite animation and 18x60 hitbox also the map is maded by 16x16 tiles. When my player goes some way he can pass through blocks (but not all of them). For example there are 4 situations:

Good (player can't pass the tile with isSolid property on collision layer)

enter image description here

Good (player can't pass the tile with isSolid property on collision layer)

enter image description here

Bad (player pass the tile with isSolid property on collision layer)

enter image description here

Bad (player pass the tile with isSolid property on collision layer)

enter image description here

Looks like melonJS checks only corners of hitbox instead of whole rectangle. Can anyone help me in this situation.

UPD: my PlayerEntity.

var PlayerEntity = me.ObjectEntity.extend({
    init: function(x, y, settings) {
            settings.image = "player";
            settings.spritewidth = 64;
            settings.spriteheight = 64;
            this.parent(x, y, settings);
            this.setVelocity(3, 10);
            this.updateColRect(23, 18, 4, 60);
            me.game.viewport.follow(this.pos, me.game.viewport.AXIS.BOTH);
            this.direction = 'stand2';
            this.addAnimation("run", [0,1,2,3,4,5,6,7,8,9]);
            this.addAnimation("stand", [33]);
            this.addAnimation("stand2", [44]);
            this.addAnimation("jump", [29,29,29,29,29,29,29,29,27,27]);
            this.addAnimation("jump2", [26,27,27,27,29,29,27,27,26]);
    },
    update: function() {
            hadSpeed = this.vel.y != 0 || this.vel.x != 0 ;
            if(hadSpeed)
                this.animationspeed = me.sys.fps / 10;

            if (me.input.isKeyPressed('left')) {
                this.jumping ? this.setCurrentAnimation('jump2') : this.setCurrentAnimation('run');
                this.flipX(false);
                this.vel.x = -this.accel.x * me.timer.tick;
                this.direction = 'left';
            }
            ...
            right/jump etc goes here
            ...
            updated = this.updateMovement();
            if (!hadSpeed) this.setCurrentAnimation('stand');
            if (updated) this.parent(this);
            return updated;
    }
});
share|improve this question
    
Looking in the source code for MelonJS it appears that it does perform a proper bounding box collision check. melonjs.org/build/melonJS-0.9.4.js search for overlaps : function(r). Are you sure you marked the boxes as collide and not platform? Does onCollision get triggered on the sprite? Post your relevant code, the bug is most likely in your code or level, not in the framework. –  Daniel Carlsson Oct 10 '12 at 14:55
    
Not sure what you mean. I take the code from official tutorial. Anyway I made an update of my question. –  Arthur Halma Oct 10 '12 at 21:35
    
Add onCollision: function() {alert("collided")} and see if it gets triggered, and from what I saw you can mark blocks as platforms or solid, platform would allow you to enter them from the side or below and cause the problem. –  Daniel Carlsson Oct 11 '12 at 0:44
    
I added your line of code to my PlayerEntity but it never triggered. Also all my blocks have isSolid flag. I have no chance to change framwork code so I need somehow to ovveride checkCollision method (with proper logic) in my PlayerEntity. Also I found that it is an general bug for melonJs –  Arthur Halma Oct 11 '12 at 6:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.