Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by akonsu

hello,

I am totally new, maybe this is a trivial question. I am trying to figure out how to restrict the movement of my entity inside the game's view so that when it hits an edge it bounces off? I tried to create a collision map but weltmeister won't let me make it 600x600 (which is the size of my game view).

thanks in advance

konstantin

1 decade ago by gxxaxx

First, my answer is just a work in process. I have issues with it, but it works well enough for now. In overhead it works just fine. In side scroller, the player gets caught on the bottom of the screen bouncing around. Since I always have a proper "floor" in my side scrollers, this has never been an issue.

You'll have to see how this fits into your entities. But it might give you a clue where to look -- or at least I hope it helps.

In my creature entity i have a method like the following:

    noLeaveMap: function() {
        if (this.pos.x >= ig.game.mapWidth - this.size.x/2) {
            this.pos.x = ig.game.mapWidth - this.size.x - 2* this.offset.x;
        } else if (this.pos.x < 0) {
            this.pos.x = 0;
        }
        if (this.pos.y >= ig.game.mapHeight - this.size.y/2) {
            this.pos.y = ig.game.mapHeight - this.size.y - 2* this.offset.y;
        } else if (this.pos.y < 0) {
            this.pos.y = 0;
        }
	},

In my creature update method I have something like:

	update: function() {
		this.doMovement();
		this.noLeaveMap();
		this.parent();
	},
Page 1 of 1
« first « previous next › last »