子弹发射地方应该是从坦克面向的方向且炮口发出的。
    这里需要微调子弹x,y的坐标。因为graphics默认左上角.

    1. TankWar.prototype.fire = function () {
    2. const { upIsDown, leftIsDown, downIsDown, rightIsDown } =
    3. this.direction;
    4. const { vx, vy } = defaultSpeed;
    5. const {x,y,width,height} = this.player;
    6. const gunX = x+width;
    7. const gunY = y+height;
    8. if ((this.gun.children.length === 0 && this.gun.children < 2) ) {
    9. const graphics = new PIXI.Graphics();
    10. graphics.beginFill(0xffffff);
    11. graphics.drawRect(0, 0, 3, 3);
    12. graphics.endFill();
    13. this.gun.addChild(graphics);
    14. if (!upIsDown) {
    15. console.log(graphics);
    16. graphics.vx = 0;
    17. graphics.vy = 4;
    18. graphics.x = gunX - width/2 - 2;
    19. graphics.y = gunY;
    20. }
    21. else if (!leftIsDown){
    22. graphics.vx = 4;
    23. graphics.vy = 0;
    24. graphics.x = gunX;
    25. graphics.y = gunY - height/2 - 2;
    26. }
    27. else if(!rightIsDown){
    28. graphics.vx = -4;
    29. graphics.vy = 0;
    30. graphics.x = gunX - width - 2;
    31. graphics.y = gunY - height/2 - 2;
    32. }
    33. else if(!downIsDown){
    34. graphics.vx = 0;
    35. graphics.vy = -4;
    36. graphics.x = gunX - width/2 - 3;
    37. graphics.y = gunY - height - 2;
    38. }
    39. }
    40. };