创建地图可以使用一个二维数组来创建地图上的各种素材。
    两次for循环,获取他地形的x和y的坐标。用一组key值来确定是什么类型
    代码如下:

    1. TankWar.prototype.createMap = function (id) {
    2. console.log(this.application)
    3. this.mapContainer = new PIXI.Container();
    4. this.mapContainer.position.set(14,10);
    5. if(this.currentStage !=0){
    6. const currentStageRow = stage[`stage${this.currentStage}`];
    7. for(let row =0;row<currentStageRow.length;row++){
    8. const currentStageColumn = stage[`stage${this.currentStage}`][row];
    9. console.log(currentStageColumn)
    10. for(let col = 0;col<currentStageColumn.length;col++){
    11. if(currentStageColumn[col] === 1) {
    12. const wall = new PIXI.Sprite(id.textures['map-dixing-qiang.png']);
    13. wall.position.set( col * 16,row * 16);
    14. wall.scale.set(2,2);
    15. wall.anchor.set(0.5,0.5);
    16. this.mapContainer.addChild(wall);
    17. console.log(currentStageColumn[col])
    18. console.log(wall.x,wall.y)
    19. }
    20. if(currentStageColumn[col] === 2){
    21. const grass = new PIXI.Sprite(id.textures['map-dixing-cao.png']);
    22. wall.position.set( col * 16,row * 16);
    23. wall.scale.set(2,2);
    24. wall.anchor.set(0.5,0.5);
    25. this.mapContainer.addChild(wall);
    26. console.log(currentStageColumn[col])
    27. console.log(wall.x,wall.y)
    28. }
    29. if(currentStageColumn[col] === 3){
    30. const wall = new PIXI.Sprite(id.textures['map-dixing-gang.png']);
    31. wall.position.set( col * 16,row * 16);
    32. wall.scale.set(2,2);
    33. wall.anchor.set(0.5,0.5);
    34. this.mapContainer.addChild(wall);
    35. console.log(currentStageColumn[col])
    36. console.log(wall.x,wall.y)
    37. }
    38. if(currentStageColumn[col] === 4){
    39. const river = new PIXI.Sprite(id.textures['map-dixing-heliu.png']);
    40. wall.position.set( col * 16,row * 16);
    41. wall.scale.set(2,2);
    42. wall.anchor.set(0.5,0.5);
    43. this.mapContainer.addChild(wall);
    44. console.log(currentStageColumn[col])
    45. console.log(wall.x,wall.y)
    46. }
    47. }
    48. }
    49. }
    50. this.application.stage.addChild(this.mapContainer);
    51. }