Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Andrea Sonny
    @andreasonny83
    can you see the enemy object in there?
    Billy B.
    @Azurasky1
    i just checked and yes
    what is this error here 25enemy.js:29 Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(HTMLImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap)'
    Andrea Sonny
    @andreasonny83
    something wrong inside your Enemy.prototype.draw function
    Billy B.
    @Azurasky1
      Enemy.prototype.draw = function () {
        _game.cv.drawImage(
          _game.enemy.avatar,
          _game.enemy.frame.width * _game.enemy.frame.current,
          _game.enemy.frame.direction * _game.enemy.frame.height,
          _game.enemy.frame.width, _game.enemy.frame.height,
           // centered on canvass
          _game.enemy.pos.x, _game.enemy.pos.y,
          // image size to draw
          _game.enemy.frame.width * _game.scaleFactor,
          _game.enemy.frame.height * _game.scaleFactor
        );
    
        this.drawHealth();
    
      }
    i explicitly assign .enemy.avatar to a new image, then i assign the src to a path
    and when i try to draw it with that function, i get that error
    Andrea Sonny
    @andreasonny83
    show me where you assign _game.enemy.avatar
    Billy B.
    @Azurasky1
    Enemy.prototype.init = function(game, avatar, enemyInfo) {
        _game = game;
        console.log(_game);
    
        _game.enemy.avatar = new Image();
        _game.enemy.avatar.src = avatar;
        console.log(_game.enemy.avatar.src);
    
      _game.enemy.pos = {
          x: Math.floor((Math.random() * 600) + 100) * _game.scaleFactor,
          y: Math.floor((Math.random() * 400) + 100) * _game.scaleFactor
        };
    
        _game.enemy.animation = {
          x: 0,
          y: 0
        };
    
      _game.enemy.frame = {
          current: 0,
          direction: Math.floor((Math.random() * 3)),
          total: enemyInfo.frames,
          width: (enemyInfo.width / enemyInfo.frames),
          height: (enemyInfo.height / enemyInfo.frames)
        };
    
        _game.enemy.health = {
          total: 100,
          current: 100,
          percent: 100
        };
    
        _game.enemy.speed = .05;
        _game.enemy.avatar = null;
        _game.bodies.push(_game.enemy);
    
      }
    
      modules.Enemy = new Enemy();
      window.$modules = modules;
    })(window.$modules || {});
    Andrea Sonny
    @andreasonny83
    and what is avatar ?
    Billy B.
    @Azurasky1
    the path
    a string
    Andrea Sonny
    @andreasonny83
    is that correct?
    Billy B.
    @Azurasky1
    it's passed in when the function is called
    same format as player
    here is the app.js
        app.modules.Player.init(app.game,
          '/images/players/player_00' + player + '.png', {
            frames: 4,
            width: playersInfo[player - 1].width,
            height: playersInfo[player - 1].height
          });
    
    
      app.modules.Enemy.init(app.game,
        '/images/dragons/dragon.png', {
          frames: 10,
          width: (750 / 10),
          height: (560 / 8)
    
        });
    Andrea Sonny
    @andreasonny83
    so, does the dragon.png exists in that path?
    Billy B.
    @Azurasky1
    yes i checked
    Andrea Sonny
    @andreasonny83
    ok, so, inside your Enemy.prototype.draw = function () { function
    console.log(_game.enemy);
    what does it say?
    can you see everything you need?
    avatar, positions, frame, etc?
    Billy B.
    @Azurasky1
    it says that the avatar is null
    all the other stuff is there
    i can't really copy/paste because my console is being spammed by the uncaught typeerror
    i don't rly get why the avatar is null because i clearly defined it within the init
    Andrea Sonny
    @andreasonny83
    weird
    Billy B.
    @Azurasky1
    i'm exhausted i'll figure it out later
    ok
    i made a pull request even though it isn't functional but everything is in the dragon branch
    Andrea Sonny
    @andreasonny83
    ok
    Billy B.
    @Azurasky1
    maybe you can take a look and figure out why it doesn't work
    Andrea Sonny
    @andreasonny83
    sure
    Billy B.
    @Azurasky1
    i'll catch u later it's nap time
    take care :D
    Andrea Sonny
    @andreasonny83
    fixed and merged into develop
    but the dragon image is not good
    the logic support an image with only 4 positions so all the images are screwed up
    Billy B.
    @Azurasky1
    ok
    were u able to figure out why the code didn't work previously
    Andrea Sonny
    @andreasonny83
    Sure, have a look at the code difference in my commit. There were several errors around
    Billy B.
    @Azurasky1
    it doesn't look terribly different to me
    i think im missing something
    Andrea Sonny
    @andreasonny83
    Did you have a look at the code difference in git?
    Billy B.
    @Azurasky1
    yeah i'm looking at it right now
    the drawimage for the enemy is the same, do you know what was causing the error?
    my theory was that it was running before the image had a chance to load
    Andrea Sonny
    @andreasonny83
    Azurasky1/DragonArena@53991c3