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 FriendlyDuck

Sorry for all of the questions - I've been searching most of the afternoon for answers to these questions and can't seem to find anything I can make work. I'm not just being lazy!

I'm trying to make a test game (my first with Impact, my first full stop in fact). I'm using box2d for the physics. Here's a screenshot.

/><br />
<br />
The idea is to stack the bricks to match the shape with the dotted outline. The problem is I have absolutely no idea how I'm going to test that the dotted shape is covered in bricks? I'm guessing something to do with persistent contact with box2d? The main problem I have is knowing where to put the code.<br />
<br />
There's probably a better way to approach it though?<br />
<br />
Also, Every time you hit spacebar, I'm spawning 20 new entities. After about 3 times the game just stops. Is there any way to improve performance? I've tried killing any brick that bounces off screen but it doesn't really seem to help.<br />
<br />
Finally, I'm having trouble getting sounds to work when bricks collide. I stumbled on <a href= this thread but have no idea where to put that code so the brick entity uses it to play a sound?

Here's my Player/brick code.

ig.module(
	'game.entities.player'
)
.requires(
	'impact.entity',
	'impact.sound',
	'plugins.box2d.entity'
)
.defines(function(){

EntityPlayer = ig.Entity.extend({
    size: {x:80, y:80},
	maxVel: {x: 100, y: 150},
	friction: {x: 600, y: 0},
	gravityFactor:0,
	type: ig.Entity.TYPE.A,
	zIndex:99,
    
    animSheet: new ig.AnimationSheet('media/container.png', 80, 80),
    
    init: function( x, y, settings ) {
        this.addAnim('idle', 1, [0]); 
		this.addAnim('containerOpen', 1, [1]);        
        this.parent( x, y, settings );
    },
    
    update: function() {
		
		// move left or right
		if (ig.input.state('left')) { 
			this.vel.x = -100;
			this.currentAnim = this.anims.idle;
		}
		if (ig.input.state('right')) { 
			this.vel.x = +100;
			this.currentAnim = this.anims.idle;
		}
		if (ig.input.pressed('drop')) {
			this.currentAnim = this.anims.containerOpen;
			ig.game.sortEntitiesDeferred();
			for( var i = 0; i < 20; i++ ) {
				var e = ig.game.spawnEntity( EntityBrick, this.pos.x+(i+20), this.pos.y+60, {zIndex:1} );
			}
			ig.game.brickCount = ig.game.brickCount+20;
		}
		
		this.noLeaveMap();
		
        this.parent();
	},
	
	noLeaveMap: function() {
       if (this.pos.x < 0) {
            this.pos.x = 0;
        }
		if (this.pos.x > 80) {
			this.pos.x = 80;	
		}
    }
	
});

// Brick Entity
EntityBrick = ig.Box2DEntity.extend({
	size: {x:11, y:7},
	type: ig.Entity.TYPE.B,
	checkAgainst: ig.Entity.TYPE.NONE,
	collides: ig.Entity.COLLIDES.NONE,
	bounciness:0.2,
	zIndex:99,
	brickSFX: new ig.Sound('media/sounds/brick.ogg' ),
	animSheet: new ig.AnimationSheet('media/brick.png', 11, 7),
    
    init: function(x, y, settings) {
        this.addAnim('idle', 0.5, [0]);        
        this.parent(x, y, settings);
    },
	update: function() {
		
		// If a brick goes off screen, kill it
		if ((this.pos.x < 0) || (this.pos.x > 160)) {
			this.kill();
			ig.game.brickCount = ig.game.brickCount-1;
			this.brickSFX.play();
		}

        this.parent();
	}
});

});

1 decade ago by industrialradio

// in your ig.Game subclass
loadLevel: function( level ) {
this.parent( level );

// Enable the pre-rendered background mode for all
// mobile devices

for( var i = 0; i < this.backgroundMaps.length; i++ ) {
this.backgroundMaps[i].preRender = true;

that should cut down on the drawings
}

}

1 decade ago by FriendlyDuck

I've managed to figure out that the performance issue seems to be when a brick falls off the right of the screen. If a brick goes off the left of the screen it is killed(); as intended. As soon as even one brick goes off the right the game freezes or slows right down.

update: function() {
        
        // If a brick goes off screen, kill it
        if ((this.pos.x < 0) || (this.pos.x > 160)) {
            this.kill();
            ig.game.brickCount = ig.game.brickCount-1;
            this.brickSFX.play();
        }

        this.parent();
    }

and


update: function() {
		// If a brick goes off screen, kill it
		if ((this.pos.x < 0) || (this.pos.x > ig.system.width)) {
			this.kill();
			ig.game.brickCount = ig.game.brickCount-1;
			this.brickSFX.play();
		}
        this.parent();
	}


Both seem to cause the same problem. I get this error in the console - Uncaught TypeError: Cannot read property 'value' of undefined when a brick goes off the right of the screen.
Page 1 of 1
« first « previous next › last »