ImpactJS-Scene-Manager
                                
                                
                                
                                    ImpactJS-Scene-Manager copied to clipboard
                            
                            
                            
                        level
i created this simple scene. but i can't get collisions in LevelMain to work. what am i doing wrong ?
ig.module(
    'game.scenes.mainScene'
)
.requires(
    'impact.entity',
    'game.entities.ent1',
    'game.entities.en2',
    'game.levels.main',
    'plugins.scene_manager'
)
.defines(function(){
    MainScene = Scene.extend({
        init: function( title ) {
            this.parent();
            this.clearColor = '#126';
            ig.input.bind(ig.KEY.MOUSE1,'eat');
            this.loadLevel(LevelMain);
        }
    });
});
                                    
                                    
                                    
                                
Hi, sorry you are having issues with collisions and the scene manager.
Are you attempting to implement dynamic, or static collisions?
Static Collision: i'm more or less adapting the 'Pong' example to use Scene Manager en2 has : collides: ig.Entity.COLLIDES.ACTIVE, i don't get what's missing
obviously the level has a collision layer with few blocks in it
Is there possibly a typo? I see you have "ent1" and and "en2". Can you please post some code from both of these entities? It will help us get closer to a solution.
here is the code: the level is big: i have standard collision tile around the border scene:
    ig.module(
        'game.scenes.ranaScene'
    )
    .requires(
        'impact.entity',
        'game.entities.rana',
        'game.entities.zanzara',
        'game.levels.rana',
        'plugins.scene_manager'
    )
    .defines(function(){
        RanaScene = Scene.extend({
            init: function( title ) {
                this.parent('');
                this.clearColor = '#126';
                ig.input.bind(ig.KEY.MOUSE1,'eat');
                this.loadLevel(LevelRana);
            }
        });
    });
rana.js
  ig.module(
    'game.entities.rana'
  )
  .requires(
    'impact.entity',
    'game.entities.zanzara'
  )
  .defines(function() {
      EntityRana = ig.Entity.extend({
        size:{x:48,y:48},
        animSheet: new ig.AnimationSheet('media/rana.png',48,48),
        init:function (x,y,settings) {
          this.parent(x,y,settings);
          this.addAnim('idle',1,[0]);
        },
        update:function() {
          if(ig.input.state('eat')){
            var point = {
              pos:{
                x:ig.input.mouse.x-24,
                y:ig.input.mouse.y-24
              },
              size:{
                x:48,
                y:48
              }
            };
            //console.log(this.angleTo(point));
            //console.log(this.distanceTo(point));
            this.currentAnim.angle = this.angleTo(point) + Math.PI/2;
          }
          //
          this.parent();
        }
      });
  });
zanzara (the colliding one)
  ig.module(
    'game.entities.zanzara'
  )
  .requires(
    'impact.entity'
  )
  .defines(function() {
      EntityZanzara = ig.Entity.extend({
        size:{x:48,y:48},
        collides: ig.Entity.COLLIDES.ACTIVE,
        bounciness:1.1,
        animSheet: new ig.AnimationSheet('media/zanzara.png',48,48),
        init:function (x,y,settings) {
          this.parent(x,y,settings);
          this.addAnim('idle',1,[0]);
          this.addAnim('dead',1,[1]);
          this.vel.x = (Math.random()-0.5)*6000;
          this.vel.y = (Math.random()-0.5)*5000;
        },
        update:function () {
          // movimento zanzara
          if(ig.input.state('eat')){
            if (this.inFocus()){
              this.vel.x =0;
              this.vel.y =0;
              this.collides=0;
              this.currentAnim = this.anims.dead;
            }
          }
          this.parent();
        },
        inFocus: function() {
          return (
             (this.pos.x <= (ig.input.mouse.x + ig.game.screen.x)) &&
             ((ig.input.mouse.x + ig.game.screen.x) <= this.pos.x + this.size.x) &&
             (this.pos.y <= (ig.input.mouse.y + ig.game.screen.y)) &&
             ((ig.input.mouse.y + ig.game.screen.y) <= this.pos.y + this.size.y)
          );
       }
      });
  });
                                    
                                    
                                    
                                
BTW Dynamic collision (entity on entity) works like a charm
I found out that the collision maps gets somehow resetted to default. by adding this to my Scene collision works, but it's overkill ro reset the collision map on every frame
        update:function (argument) {
            this.parent();
            ig.game.collisionMap = this.collMap;
        },
        loadLevel:function (data) {
            this.parent( data );
            for( var i = 0; i < data.layer.length; i++ ) {
                var ld = data.layer[i];
                if( ld.name == 'collision' ) {
                    this.collMap = new ig.CollisionMap(ld.tilesize, ld.data );
                }
            }
        }
                                    
                                    
                                    
                                
Just to clarify, does this level have a map with the name 'collision'? Sorry if this seems like an obvious question to you. Just want to verify.
sure: as you can see in my workaround i didn't do anything more that constantly resetting ig.game.collisionMap to a 'collision' layer. everything from loadLevel() comes from Impact's game.js#loadLevel()
i changed from this.collisionMap to this.collMap just to be sure it doesn't get resetted
actually you only need this
        update:function () {
            this.parent();
            ig.game.collisionMap = this.collisionMap;
        }
                                    
                                    
                                    
                                
From what I gather based on your workaround, the parsed copy of the collision map is not being set correctly after loading a scene. I'm adding your workaround to the base scene class and pushing a new revision up.
You can make this change yourself on line 53 of scene_manager.js.
While this workaround should fix things for now, this probably means that other objects are not being copied to ig.game properly. I will continue investigating another fix. Please update and ensure that your workaround still functions in the base Scene object.
the strange thing is that if you override Scene#loadLevel with:
loadLevel:function (data) {
            this.parent( data );
            for( var i = 0; i < data.layer.length; i++ ) {
                var ld = data.layer[i];
                if( ld.name == 'collision' ) {
                    ig.game.collisionMap = new ig.CollisionMap(ld.tilesize, ld.data );
                }
            }
        }
it's still not correct... O_O