Grandy12 Posted May 29, 2015 Share Posted May 29, 2015 My code (there's more stuff than this, but I only got the parts that should be relevant);function create(){fighters = game.add.group();player = fighters.create(32, game.world.height - 153, 'fei');player.anchor.setTo(0.5, 0.5);player.scale.setTo(2, 2);game.physics.arcade.enable(player);game.camera.follow(player)player.body.collideWorldBounds = false;player.animations.add('walk', [0,1,2,3,4], 10, true);new Shadow(player);}function update() {for (var i = 0; i < fighters.length; i++){ for (var j =0; j < fighters.length; j++){ if (fighters.getAt(i).shadow !== undefined){ var character = fighters.getAt(i); game.physics.arcade.collide(character, character.shadow, fellDown(character), null, this); character.body.gravity.y = 600 + character.shadow.body.velocity.y; if (fighters.getAt(j).shadow !== undefined){ var spriteAY = fighters.getAt(i).shadow.y; var spriteBY = fighters.getAt(j).shadow.y; if (spriteAY > spriteBY){ fighters.getAt(i).moveUp();}}}} if (fighters.getAt(i).shadow !== undefined){ fighters.getAt(i).shadow.sendToBack();}} movement();}function movement(){ player.shadow.body.velocity.y = 0;player.shadow.body.velocity.x = 0;if(player.jumping == false){player.body.velocity.y = 0;player.body.velocity.x = 0;}if (cursors.left.isDown){player.scale.x = -2;player.shadow.body.velocity.x = -150; } else if (cursors.right.isDown){player.scale.x = 2;player.shadow.body.velocity.x = 150; } player.body.x = player.shadow.body.x; if (cursors.up.isDown && player.shadow.body.y > 400){player.shadow.body.velocity.y = -85;} else if (cursors.down.isDown){player.shadow.body.velocity.y = 85; player.body.velocity.y = player.shadow.body.velocity.y } if (jumpKey.isDown){jump(player);};}function jump(character) {if(character.jumping == false){character.body.velocity.y = character.shadow.body.velocity.y - 400;character.jumping = true;}}function fellDown(character){ if (character.jumping){character.jumping = false;character.shadow.body.velocity.x = 0; character.body.velocity.x = 0;}}function Shadow(character){shadow = fighters.create(character.body.position.x, character.body.position.y + character.height / 2 -1, 'shadow');shadow.anchor.setTo(0.5, 0.5);shadow.scale.setTo(2, 2);game.physics.arcade.enable(shadow); if(character == player){shadow.body.collideWorldBounds = true; }shadow.body.setSize(character.width / 2,4,0,6); shadow.body.immovable = true; /character.shadow = shadow;game.debug.body(character.shadow)}What it *should* do, is call the function fellDown whenever a sprite inside the 'fighters' group (that includes the player) collided with his own shadow (provided it has a shadow). Instead, it keeps calling that function all the time. Link to comment Share on other sites More sharing options...
Recommended Posts