@Arantor,
Yes, I've basically kept what was in crate.js, as in...
animSheet: new ig.AnimationSheet( 'media/crate.png', 8, 8 ),
@quidmonkey
from
https://github.com/phoboslab/impact-box2d, the readme says...
"Copy the box2d directory into your lib/plugins/ directory and require the plugins.box2d.entity and plugins.box2d.game files. Subclass your game from ig.Box2DGame and your entities from ig.Box2DEntity:"
So I had added the box2d directory and required 'plugins.box2d.entity' and 'plugins.box2d.game' but not 'plugins.box2d.debug'. I did now, but the game still won't load.
I'm confused about whether to need to use the 'box2d' folder as suggested above or the default 'dbox2d' which as overlapping js files like 'entity.js and game.js' but not 'lib.js' and 'debug.js'. Presumably the former two, entity and game js files are identitical?
I've reattached my two files. 1. Main.js and 2. ball.js and perhaps you can see where I've gone wrong?
1. main.js
ig.module(
'game.main'
)
.requires(
'impact.game',
'impact.font',
'plugins.dc.dc',
'plugins.dbox2d.dbox2d',
'game.entities.player',
'game.entities.crate',
'plugins.box2d.entity',
'plugins.box2d.game',
'plugins.box2d.debug',
'game.entities.ball',
'game.levels.test'
)
.defines(function(){
MyGame = ig.Box2DGame.extend({
gravity: 100,
font: new ig.Font( 'media/04b03.font.png' ),
clearColor: '#1b2026',
paused: false,
init: function() {
this.loadLevel( LevelTest );
AppMobi.webview.execute('canvasInit();');
this.debugDrawer = new ig.Box2DDebug( ig.world );
},
loadLevel: function( data ) {
this.parent( data );
for( var i = 0; i < this.backgroundMaps.length; i++ ) {
this.backgroundMaps[i].preRender = true;
}
},
update: function() {
var player = this.getEntitiesByType( EntityPlayer )[0];
if( player ) {
this.screen.x = player.pos.x - ig.system.width/2;
this.screen.y = player.pos.y - ig.system.height/2;
}
this.parent();
},
draw: function() {
this.parent();
this.debugDrawer.draw();
if( !ig.ua.mobile || (typeof top != "undefined" && top.location.href.match('^http://localhost:58888')!=null)) {
this.font.draw( 'Left/Right/Jump: Arrow Keys, F to shoot', 2, 2 );
}
},
pause: function() {
if (ig.system) {
if(ig.game){
ig.game.font.draw('Game Paused',ig.system.width/2,ig.system.height/2,ig.Font.ALIGN.CENTER);
}
ig.system.stopRunLoop.call(ig.system);
}
},
unpause: function() {
if (ig.system ) {
ig.system.startRunLoop.call(ig.system);
}
}
});
if(ig.ua.iPad){ig.main( '#_cvs', MyGame, 60, 256, 187, 4 );}
else{ig.main( '#_cvs', MyGame, 60, 240, 150, 2 );}
});
2. ball.js
ig.module(
'game.entities.ball'
)
.requires(
'plugins.dbox2d.entity'
)
.defines(function(){
EntityBall = ig.Box2DEntity.extend({
size: {x: 16, y: 16},
type: ig.Entity.TYPE.B,
checkAgainst: ig.Entity.TYPE.NONE,
collides: ig.Entity.COLLIDES.NEVER,
animSheet: new ig.AnimationSheet( 'media/crate.png', 8, 8 ),
createBody: function() {
var bodyDef = new b2.BodyDef();
bodyDef.position.Set(
(this.pos.x + this.size.x / 2) * b2.SCALE,
(this.pos.y + this.size.y / 2) * b2.SCALE
);
this.body = ig.world.CreateBody(bodyDef);
var shapeDef = new b2.CircleDef();
shapeDef.radius = 8 * b2.SCALE;
shapeDef.density = 1;
this.body.CreateShape(shapeDef);
this.body.SetMassFromShapes();
},
init: function( x, y, settings ) {
this.addAnim( 'idle', 1, [0] );
this.parent( x, y, settings );
}
});
});
Thanks if you take a lot at it. Any thoughts are appreciated.