Hi all,
I am stuck with this weird bug for two days now. All the efforts result no success. I hope any expert can help. I believe the problem is to do with the Director plugin. But not sure.
Basically I am developing a shooting game. There is an arrow in the game which can shoot bullets. The bullet shooting works as expected when the game is loaded for the first time. But If I bring up the menus by clicking a menu button and chose another level to play, the arrow doesn’t spawn a bullet at the first mouse click but spawn bullets on the subsequence clicks.
Besides the menu button, I also have a reload button and next level button. All these two buttons are working fine. When reloaded or going to the next level, the arrow’s behavior is perfect. Only this Menu button is not working.
When the menu button is clicked, it changes the game’s state to menu state and show the world choice menu on which you can choose the world, then choose a level in the world. Once the level button is clicked, the level choice menu is hidden and the level is loaded. Then the problem comes in. First click, no bullet.
Please note, I am using the Director Plugin by Boneheadmed (
https://github.com/boneheadmed/Director) to manage the levels. The world choice menu and level choice menu is created using jquery and DOM elements.
Here are the relevant code snippets:
button click to hide the menu, change the game state and reset all the game variables
$("#btnPark1").click(
function(){
$("#menuLevelsPark").hide();
ig.game.gameStateInParkLevelMenu=false;
ig.game.myDirector.loadLevel(0);
ig.game.currentLevelVars = clone( ig.game.levelVars[ 0 ] );
ig.game.generateBtnAndMenu();
ig.game.lives=ig.game.livesB+ig.game.currentLevelVars.lives;
ig.game.powerUpNum=ig.game.powerUpNumB+ig.game.currentLevelVars.powerUpNum;
ig.game.iceCreamNum=ig.game.iceCreamNumB+ig.game.currentLevelVars.iceCreamNum;
ig.game.archNum=ig.game.archNumB+ig.game.currentLevelVars.archNum;
ig.game.gameTimer.reset();
}
);
Arrow to shoot bullet
EntityArrow=ig.Entity.extend({
animSheet: new ig.AnimationSheet( 'media/arrowSpace.png', 50, 100 ),
size: {x: 50, y:100},
offset: {x: 0, y: 0},
flip: false,
zIndex:300,
aPaused:false,
name:'arrow',
//weapon:'splat',
weapon:'bullet',
alphaFactor:0,
collides: ig.Entity.COLLIDES.NEVER,
//checkAgainst: ig.Entity.TYPE.B,
init: function( x, y, settings ) {
this.parent( x, y, settings );
this.addAnim( 'idle', 1, [0] );
},
update:function(){
if(ig.input.pressed('shoot')){
console.log('arrow paused:'+this.aPaused);
}
if(!this.aPaused){
x = this.pos.x+this.size.x/2;
y = this.pos.y+this.size.y;
mx = ig.input.mouse.x;
my = ig.input.mouse.y;
this.alphaFactor+=Math.PI/180;
if(this.alphaFactor>Math.PI){
this.alphaFactor=0;
}
shootingAngle=Math.atan2((my-y),(mx-x))+Math.PI/2;
this.anims.idle.pivot={x:25,y:100};
this.anims.idle.angle=shootingAngle;
this.anims.idle.alpha=0.2+Math.sin(this.alphaFactor);
//console.log(this.anims.idle.alpha);
if(ig.input.pressed('shoot')){
console.log("inner shoot");
}
if( ig.input.pressed( 'shoot' )&&ig.game.getEntitiesByType(EntityBullet).length==0&&ig.game.getEntitiesByType(EntityBulletLittle).length==0){
// console.log("shootPressed: "+ig.input.pressed('shoot'));
// console.log("powerUpClickNum: "+ig.game.powerUpClickNum);
// console.log("BulletNum: "+ig.game.getEntitiesByType(EntityBullet).length);
// console.log("LivesNum: "+ig.game.lives);
if(this.weapon==='bullet'){
if(ig.game.lives>0){
//ig.game.spawnEntity(EntityBullet,330,355);
ig.game.spawnEntity(EntityBullet,335,380);
//ig.game.spawnEntity(EntityIceCream,this.pos.x,this.pos.y);
//ig.game.spawnEntity(EntityBullet,this.pos.x,this.pos.y);
}
}
else if(this.weapon==='powerUp'){
if(ig.game.powerUpNum>0){
ig.game.spawnEntity(EntityPowerUpW,335,380);
}
}
else if(this.weapon==='splat'){
if(ig.game.archNum>0){
//alert('splat');
ig.game.spawnEntity(EntityPowerUpM,335,380);
}
}
//else{
// return;
// }
}
}//end of paused condition
this.parent();
},
});
Any hero can help to find this monster bug?