磁贴未打印到屏幕上

时间:2019-03-31 02:05:20

标签: javascript p5.js

我正在尝试创建一个游戏。游戏地图将是充当平铺或单元的相邻三角形的组合。这部分代码应为每个三角形创建一个对象。每个三角形应具有x和y坐标。然后,代码应遍历整个数组,并在draw函数中全部绘制它们。运行该程序后,没有任何显示,甚至没有彩色背景的画布。

请注意,通过删除21到57之间的所有代码并删除draw函数中对Tile类的调用,程序可以完美运行,因此顶部的变量设置没有问题。

我的问题是什么也没显示,但没有收到错误消息。只是出了点问题。

W = 800;
H = 600;
bg = 210;

let tiles = [];

tilesAlong = 16;
tileBase = W/tilesAlong;
tileHeight = ((tileWidth**2)-((tileWidth/2)**2))**0.5;
tilesDown = (round((H/tileHeight)/2))*2;
yOffset = (H-(tilesDown*tileHeight))/2;
tilesTotal = (tilesAlong-1)*(tilesDown-1);

function setup() {
  createCanvas(W, H);
  background(bg);

  tempX = 0;
  tempY = 0;
  tempColor = ["40, 40, 40"];

  id(x, y) {;
    sum = y*tilesDown;
    sum += x;
  }

  while(setup.id(tempX, tempY) < tilesTotal){
   tiles.push(Tile());
   tempX += 1;
   if(tilesAlong < tempX){
     tempX = 0;
     tempY += 1;
   }
  }
}

class Tile {
  constructor() {
    this.x = TempX;
    this.y = TempY;
    this.color = tempColor;
  }

  display() {
    if(this.y/2 == round(this.y/2)){
      if(this.x/2 == round(this.x/2)){
        triangle(tileWidth * this.x/2, tileHeight*(this.y+1), (tileWidth*this.x/2)+(tileWidth/2), (tileHeight*this.y), (tileWidth*(this.x/2+1)), tileHeight*(this.y+1));
      } else{
        triangle(tileWidth * this.x/2, tileHeight*(this.y), (tileWidth*this.x/2)+(tileWidth/2), (tileHeight*(this.y+1)), (tileWidth*(this.x/2+1)), tileHeight*(this.y));
      }
    } else {
      if(this.x/2 == round(this.x/2)){
        triangle(tileWidth * this.x/2, tileHeight*(this.y), (tileWidth*this.x/2)+(tileWidth/2), (tileHeight*(this.y+1)), (tileWidth*((this.x/2)+1)), tileHeight*(this.y));
      } else{
        triangle(tileWidth * this.x/2, tileHeight*(this.y+1), (tileWidth*this.x/2)+(tileWidth/2), (tileHeight*this.y), (tileWidth*((this.x/2)+1)), tileHeight*(this.y+1));
      }  
    }
  }
}

function draw() {
  i = 0
  while(i < tilesTotal){
   Tile[i].display();
   i += 1;
  }
}

0 个答案:

没有答案