javascript - gameQuery collision detection -


it first time me explore jquery , gamequery building games using javascript, asking sth might naive, cant it.

i developing game space invader, detection collision between player missile , enemies not working.

this code:

the definition enemy class

function enemy(node){     this.node = $(node);     this.pts_value = 0;     return true; } 

this code use add ten enemy sprite next each other. enemies move left , right

$.each(new array(10), function(index, value) {     $("#enemy_group").addsprite("enemy2_"+index,{animation: enemies[2],          posx: index * 55, posy: 0, width: 48, height: 48})     $("#enemy2_"+index).addclass("enemy");     $("#enemy2_"+index)[0].enemy = new enemy($("#enemy2_"+index));     $("#enemy2_"+index)[0].pts_value = 150; }); 

so when need move enemies, move enemies together, move group includes sprites "#enemy_group"

    if(enemy_to_right){         var enemiesnewpos = (parseint($("#enemy_group").css("left"))) + enemy_speed;         if(enemiesnewpos < playground_width - 550){             $("#enemy_group").css("left", ""+enemiesnewpos+"px");         } else {             enemy_to_right = false;         }     } else {         var enemiesnewpos = (parseint($("#enemy_group").css("left"))) - enemy_speed;         if(enemiesnewpos > 0){             $("#enemy_group").css("left", ""+enemiesnewpos+"px");         } else {             enemy_to_right = true;         }     } 

finally collision detection, want remove enemy sprite players missile has hit, each missile sprite has added class names ".playermissiles"

    $(".playermissiles").each(function(){         var posy = parseint($(this).css("top"));          if(posy < 0){             $(this).remove();             return;         }          $(this).css("top", ""+(posy - missile_speed)+"px");         //test collisions         var collided = $(this).collision(".enemy, .group");         if(collided.length > 0){             //an enemy has been hit!             collided.each(function(){                 $(this).setanimation(enemies[0], function(node){$(node).remove();});             })          }     }); 

i following documentation tutorial on gamequery website.

any appreciated, thanks,

i can't see problem code. can give few pointers:

  • did create "enemy_group" addgroup function?
  • is "enemy_group" nested in special custom div ? collision detection work need chain of parent composed of sprites , groups (and tiles map)
  • is "enemy_group" nested in sprite, if it's bad idea because need add selector sprite in methode call , sprite included in colliding element list.
  • the same goes ".playermissiles"

just sure version of gamequery , jquery use? last version github unstable , wouldn't recomend using it, user 0.5.1 instead.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -