Fonts 游戏中“myFont=createFont(“Verdana”,48,true);”的字体错误

Fonts 游戏中“myFont=createFont(“Verdana”,48,true);”的字体错误,fonts,processing,Fonts,Processing,遇到错误时,找不到任何名为myFont的内容。使用myFont=createFontVerdana,48,true;在一个游戏程序中,我不确定我是否有输入错误或真正的错误。对程序进行多次校对,但没有任何结果。 如果这是一个打字错误,我会觉得很傻。。。 试图通过收费箱加载,但似乎也不起作用。。。 有课程和课堂部分-将发布这两个部分 卡片: class Cards { int show = 0; // shows the back of the card PImage cardImage;

遇到错误时,找不到任何名为myFont的内容。使用myFont=createFontVerdana,48,true;在一个游戏程序中,我不确定我是否有输入错误或真正的错误。对程序进行多次校对,但没有任何结果。 如果这是一个打字错误,我会觉得很傻。。。 试图通过收费箱加载,但似乎也不起作用。。。 有课程和课堂部分-将发布这两个部分

卡片:

class Cards
{
  int show = 0; // shows the back of the card
  PImage cardImage;

  int cardX = 0;
  int cardY = 0;
  int faceValue = 0;
  int myPoints = 0;

  // card back is 00 so there are '53' cards vs 52

  String[] cardName = {
    "00.png", "01.png", "02.png", "03.png", "04.png", "05.png", "06.png", "07.png", "08.png", "08.png", 
    "09.png", "10.png", "11.png", "12.png", "13.png", "14.png", "15.png", "16.png", "17.png", "18.png", 
    "19.png", "20.png", "21.png", "22.png", "23.png"     
  };

  Cards (int x, int y, int fv, int mp)
  {
    cardX = x;
    cardy = y;
    faceValue = fv;
    myPoints = mp;  //keeps track of the points J=11, Q=12, K=13
  }

  void display()
  {    
    cardImage= loadImage(cardName[show]); //Display loads the images.
    image(cardImage, cardX, cardY);
  }

  void setX(int newX)  //move the card from the deck to the center and 
  {
    cardX = newX;
    show = faceValue;
  }

  int getPoints()  //gets the points from the card values compare the left to the right.
  {
    return (myPoints);
  }
}
节目:

void setup()    
{
  background(0);
  int myY =75;
  int myX1 = 430;  //each pile has its own x value
  int myX2 = 50;
  size(600, 600);
  fill(255, 0, 0);
  myFont = createFont("Verdana", 48, true);
  for (int i = 0; i<20; i++)
  {
    y[i] = myY;
    fv[i] = i+1;
    points [i] = currentPoint;
    currentPoint ++;
    if (currentPoint > 10)  //since only doing 10 cards each side - total 20 change this
    {
      currentPoint=1;  //then resetting at one - counts  -10 and then starts over.
      //so the point value matchs the face value of the cards. ace =1, 2=2, etc j=11, q=12, k=13
    }

    if (i%2==0)    
    {
      x[i] = myX1;
      myY+=2;  //changes the pixels of the cards so they are not all on top of eachother
      // the cards will show slightlu fanned down and to the right with these functions
      myX1+=2;
      myX2+=2;
    }
    else
    {
      x[i] = myX2;
    }
  }

  shuffle(); // shuffle a couple of times
  shuffle();

  for (int i=0; i<20; i++)
  {
    myCard[i] = new Cards (x[i], y[i], fv[i], points[i]);
  }
}

void draw()
{
  background(0);
  textFont(myFont);
  text(leftPoint, 75, 50);
  text(rightPoint, 515, 50);
  rect(200, 400, 200, 100);
  for (int i=0; i<20; i++)
  {
    myCard[i].display();  //display cards on the screen
  }

  if (leftDeck>19)  //CHANGE means went throug all the cards
  {
    if (leftPoint > rightPoint)
    {
      text("Left Wins!", 250, 350);
    }
    else if (leftPoint<rightPoint)
    {
      text("Right Wins!", 250, 350);
    }
    else
    {
      text("you TIED!!!!", 250, 350);
    }
  }
}

void mouseClicked()
{
  if (mouseX<400 && mouseX>200 && mouseY<500 && mouseY>400)
  {
    myCard[leftDeck].setX(190);  //set x value for left card display
    myCard[rightDeck].setX(310); //sets x value for right card display
    if (myCard[leftDeck].getPoints()>myCard[rightDeck].getPoints())
    {
      leftPoint++;
    }
    else if (myCard[leftDeck].getPoints()<myCard[rightDeck].getPoints())
    {
      rightPoint++;
    }  
    leftDeck+=2;
    rightDeck+=2;
  }
}

void shuffle()
{
  int temp = 0;
  int tempPoint =0;
  int rand = 0;
  for (int i=0; i<20; i++)  //CHANGE to 52
  {
    rand = int(random(0, 20));  //showing 20 needs to be 52
    temp = fv[i];
    tempPoint = points[i];
    fv[i] = fv[rand];
    points[i] = points[rand];  //have to move the point value with the facevalue
    fv[rand] = temp;
    points[rand] = tempPoint;
  }
}

这似乎相当明显:错误是告诉您myFont在您调用它的上下文中不存在。这很有意义:在初始化变量之前,您从未用该名称声明过它。在设置和绘图的同一级别的某处,您需要发布:

Font myFont;

因此,当安装程序运行时,有一个名为myFont的实际变量可以保存createFont调用的结果。

如果您要降级问题、程序或信息,至少可以说明原因。我对这一切都是新手,而且我的经验很有限,所以我不会问。记住在你的问题上加上适当的标签。你问的不是字体,而是一个处理程序。还请记住,您正在向其他人寻求帮助,因此请确保您的代码的格式至少合理,即不要使用大量空白作为附录:将来,请只发布相关代码。如果您在myFont上遇到错误,请减少您的问题。例如,将您的文件复制到新目录,在您喜爱的编辑器中打开该目录,并开始删除与您的错误无关的所有内容,然后在您的问题中使用大幅减少的代码。通常,在减少时,您会自己发现问题,甚至不需要再询问Stackoverflow,因此无论您的程序员有多熟练,减少仍然是第2步,就在第1步之后:直接跟踪错误