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 ape

I'm seeing something weird when tinkering with the Jump n' Run source. Not sure if it's me or a bug.

Here's what I've done.

In Weltmeister:

1. Created a new level
2. Added a layer called 'main'
3. Linked 'main' to Collision
4. Set 'main' to repeat
5. Left distance at '1'
6. Added a layer called 'collision'
7. Set 'collision' to repeat
8. Drew a row of 'S' tiles horizontally and verified that when repeated they make a solid horizontal line.
9. Added the Player entity somewhere on the left side of the level

When playing the level, the collision map works at first. I can "run" to the right without falling. However, when the Player entity hits the edge of the level on the right, it falls infinitely.

Is this a bug or am I missing something important?

1 decade ago by ape

I've pasted some code that repeats what I've described above. I've modified it so that I only define one array for both the 'main' and 'collision' level's data objects:

ig.module('game.levels.collidetest')
.requires('impact.image')
.defines(function() {
    this.map = [
      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
      [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
      [0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0],
      [0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
      [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
    ];
    LevelCollidetest =
    /*JSON[*/
    {
        "entities": [{
            "type": "EntityPlayer",
            "x": 0,
            "y": 0
        }],
        "layer": [
        {
            "name": "main",
            "width": this.map[0].length,
            "height": this.map.length,
            "linkWithCollision": false,
            "visible": true,
            "tilesetName": "media/tiles.png",
            "repeat": true,
            "distance": "1",
            "tilesize": 8,
            "data": this.map
        },
        {
            "name": "collision",
            "width": this.map[0].length,
            "height": this.map.length,
            "linkWithCollision": false,
            "visible": true,
            "tilesetName": "media/collisiontiles-8x8.png",
            "repeat": true,
            "distance": "1",
            "tilesize": 8,
            "data": this.map
        },]
    }
    /*]JSON*/
    ;
    LevelCollidetestResources = [new ig.Image('media/tiles.png')];
});

1 decade ago by dominic

Well it's a bug that you can set the collision map to repeat in Weltmeister. You shouldn't be able to do that, as collision maps are always non-repeating.

Now, what you can do to achieve the same effect, is moving all your entities by the collision maps size as soon as they move outside of it. E.g.:

var mapSize = this.collisionMap.width * this.collisionMap.tilesize;
for( e in this.entities ) {
	if( e.pos.x < 0 ) {
		e.pos.x += mapSize;
	}
	else if( e.pos.x > mapSize ) {
		e.pos.x -= mapSize;
	}
}

You should actually make your collision map slightly larger than you need by two or three tiles and repeat the beginning of the map for these last two tiles by hand. Then, instead of 0 and mapSize, check for 8 and mapSize - 8. That way you will avoid some quirks at the edge of the collision map, when it would normally trace outside.

I hope that makes sense. Good luck :)

1 decade ago by ape

Now that I think about it, it makes sense that collision maps wouldn't repeat. Background layers, sure. But in a typical side scroller it's rare that you'd have an "infinite" level.

In my case I needed an infinite "ground floor" - probably not typical of most side scrollers.

Your suggestion makes sense. I'll give it a shot.
Page 1 of 1
« first « previous next › last »