News:

Don't forget to visit the main site! There's lots of helpful docs, patches, and more!

Main Menu

Sprite malfunctions

Started by liamnajor, February 03, 2017, 01:13:59 PM

Previous topic - Next topic

liamnajor

I am trying to make samus running animations, but they only show transparency, not the image.
the image:
[spoiler][/spoiler]
my code:
[spoiler]window.onload = function() {
    //sets the window size and initualizes the game.
    Crafty.init(900, 500, document.getElementById('game'));
Crafty.background('url(Resources/tilesets/saveroom.bmp)no-repeat center')
    //adds and plays music/sound.
    Crafty.audio.add("Fanfare", "Resources/Sound/AM2R/musFanfare.ogg");
   Crafty.audio.play('Fanfare', 1);
    Crafty.audio.add("Dist. Center", "Resources/Sound/AM2R/musArea5B.ogg");
   var Music = 'Fanfare';
   Crafty.audio.play(Music, 1)
        Crafty.audio.add("item","Resources/Sound/AM2R/musItemGet.ogg")
    Crafty.audio.add("running","Resources/Sound/Samus(zm)/movement/Running.wav")
     Crafty.audio.add("runningt","Resources/Sound/Samus(zm)/movement/Running.wav")
    Crafty.audio.add("flipping","Resources/Sound/Samus(zm)/movement/FlipJump.wav")
   
    //adds and configures spritesheets and tilesets.
   Crafty.sprite(51, 48, "Resources/sprites/redhalberd_galacticfederationtrooper_sheet.png", {troop:[0,0,1,1]});
    Crafty.sprite(51, 48, "Resources/sprites/metroidfusion_samus-basic_sheet.png", {Samus:[0,0,1,1]});
    //upgrade management
    setTimeout(function() {
   Samus.addComponent('Gravity, Multiway, Jumper')
    troop.addComponent('Gravity, Multiway, Jumper')
   Music = 'Dist. Center'
   Crafty.audio.play(Music, -1);
   }, 5500);
   var HighJump = Crafty.e('HighJump, 2D, Canvas, Color, Collision')
     .attr({x: 750, y: 410, w: 25, h: 25})
   .color('blue')
   .checkHits('Samus, troop')
   .bind("HitOn", function() {
        Samus.hasHighJump = true;
      Crafty.audio.pause (Music)
      Crafty.audio.play('item', 1)
      HighJump.destroy()
      Samus.removeComponent('Gravity, Multiway, Jumper')
      setTimeout(function() {
   Samus.addComponent('Gravity, Multiway, Jumper')
    Crafty.audio.remove('item')
   Crafty.audio.unpause(Music);
   }, 5500);
    });
   var SpaceJump = Crafty.e('SpaceJump, 2D, Canvas, Color, Collision')
     .attr({x: 800, y: 400, w: 25, h: 25})
   .color('red')
   .checkHits('Samus, troop')
   .bind("HitOn", function() {
        Samus.hasSpaceJump = true;
      Crafty.audio.pause (Music)
        Crafty.audio.add("item","Resources/Sound/AM2R/musItemGet.ogg")
      Crafty.audio.play('item', 1)
      SpaceJump.destroy()
      setTimeout(function() {
   Samus.addComponent('Gravity, Multiway, Jumper')
    Crafty.audio.remove('item')
   Crafty.audio.unpause(Music);
   }, 5500);
    });
    //adds and configures player characters
    //player 1
   var Samus = Crafty.e('2D, Canvas, Jumper, Gravity, SpriteAnimation, Collision, Multiway, Samus')
      .attr({x: 120, y: 430, w: 65, h: 65})
    .multiway(300, {RIGHT_ARROW: 0, LEFT_ARROW: 180})
    .jumper(600, ['Z'])
    .gravity('Floor')
    .gravityConst(1500)
    .reel('Runl', 10000, [[10, 5], [10, 6], [10, 7], [10, 8], [11, 5], [11, 6], [11, 7], [11, 8], [12, 5], [12, 6]])
    .bind("CheckJumping", function(ground) {
    if (!ground && Samus.hasSpaceJump) {
        Samus.canJump = true;
    }
   if (Samus.hasHighJump === true) {
      Samus.jumper(900, ['Z']);
   }
})
    //Sprite animations for player 1
    ;
    //player 2
    var troop = Crafty.e('2D, Canvas, Multiway, Jumper, Gravity, SpriteAnimation, Collision, troop')
      .attr({x: 40, y: 430, w: 50, h: 65})
    .multiway(300, {H: 0, F: 180})
    .jumper(600, ['9'])
    .gravity('Floor')
    .gravityConst(1500)
    .bind("CheckJumping", function(ground) {
    if (!ground && Samus.hasSpaceJump) {
        troop.canJump = true;
    }
   if (Samus.hasHighJump === true) {
        troop.jumper(900, ['9']);
   }
})
    //Sprite animations for player 2
    ;
    //terrain management
    var floor = Crafty.e('Floor, Terrain, 2D, Collision, Canvas, Color')
      .attr({x: 0, y: 460, w: 900, h: 30})
    .color('green');
    var wall = Crafty.e('Wall, Terrain, 2D, Canvas, Color')
      .attr({x: 0, y: 0, w: 30, h: 900})
    .color('green');
    //camara management
    Crafty.viewport.follow(Samus, 0, 0);
    //control management
    Samus.bind('KeyDown', function(e) {
    if(e.key == Crafty.keys.LEFT_ARROW) {
        Samus.sprite(2, 6)
        Crafty.audio.play('running', -1)
        Samus.animate('Runl', -1);
    }
    if (e.key == Crafty.keys.RIGHT_ARROW) {
        Samus.sprite(2, 3)
        Crafty.audio.play('running', -1);
    }
    if (e.key == Crafty.keys.RIGHT_ARROW && e.key == Crafty.keys.Z) {
        Samus.sprite(3, 3)
        Crafty.audio.play('flipping', -1);
    }
  });
    Samus.bind('KeyUp', function(e, ground) {
    if(e.key == Crafty.keys.LEFT_ARROW) {
        Samus.sprite(3, 6)
        Crafty.audio.stop('running')
        Crafty.audio.stop('flipping');
    } else if (e.key == Crafty.keys.RIGHT_ARROW) {
        Samus.sprite(3, 3)
        Crafty.audio.stop('running')
        Crafty.audio.stop('flipping');
    }
  });
    troop.bind('KeyDown', function(e) {
    if(e.key == Crafty.keys.F) {
        troop.sprite(3, 6)
        Crafty.audio.play('runningt', -1);
    }
    if (e.key == Crafty.keys.H) {
        troop.sprite(3, 3)
        Crafty.audio.play('runningt', -1);
    }
  });
    troop.bind('KeyUp', function(e, ground) {
    if(e.key == Crafty.keys.F) {
        troop.sprite(3, 6)
        Crafty.audio.stop('runningt')
        Crafty.audio.stop('flipping');
    } else if (e.key == Crafty.keys.H) {
        troop.sprite(3, 3)
        Crafty.audio.stop('runningt')
        Crafty.audio.stop('flipping');
    }
  });
};[/spoiler]