加工 |我的 class 没有呼叫另一个 class
Processing | My class isn't calling the other class
void setup(){}
老实说,我不知道这个顶部是做什么的,最初我的 class 'Stuff' 甚至没有出现,因为它一直说它不存在,所以有人做了那个无效设置的事情它奏效了吗?我是新手,所以如果我触发了某人,我深表歉意。
class TarotGame1
{
Stuff game = new Stuff();
}
我照常打电话给class
class Stuff
{
东西的构造函数class
Stuff()
{
tarotCircle();
tarotCircle();
tarotSquare();
tarotDiamond();
tarotPacMan();
rngSelect1();
rngSelect2();
rngSelect3();
rngSelect4();
}
//Tarot for Circle
void tarotCircle()
{
size(800,600);
rectMode(CENTER);
fill(#2c3e50);
rect(width / 2, height / 2, 300, 400, 60);
noFill();
fill(#16a085);
rect(width / 2, height / 2, 250, 350, 60);
noFill();
fill(#c0392b);
ellipse(width /2, 250, 100, 100);
noFill();
textSize(32);
fill(#c0392b);
text("Circle", 360, 350);
noFill();
}
//Tarot for Square
void tarotSquare()
{
rectMode(CENTER);
fill(#2c3e50);
rect(width / 2, height / 2, 300, 400, 60);
noFill();
fill(#16a085);
rect(width / 2, height / 2, 250, 350, 60);
noFill();
fill(#c0392b);
rect(width / 2, 225, 100, 100);
noFill();
textSize(32);
fill(#c0392b);
text("Rectangle", 330, 350);
noFill();
}
//Tarot for Diamond
void tarotDiamond()
{
rectMode(CENTER);
fill(#8e44ad);
rect(width / 2, height / 2, 300, 400, 60);
noFill();
fill(#16a085);
rect(width / 2, height / 2, 250, 350, 60);
noFill();
fill(#27ae60);
beginShape(TRIANGLE_FAN);
vertex(57.5 + 340, 50+ 200);
vertex(57.5+340, 15+ 200);
vertex(92+ 340, 50+ 200);
vertex(57.5+ 340, 85+ 200);
vertex(22+ 340, 50+ 200);
vertex(57.5+ 340, 15+ 200);
endShape();
noFill();
textSize(32);
fill(#c0392b);
text("Diamond", 330, 350);
noFill();
}
//Tarot for Pac-Man
void tarotPacMan()
{
rectMode(CENTER);
fill(#2c3e50);
rect(width / 2, height / 2, 300, 400, 60);
noFill();
fill(#16a085);
rect(width / 2, height / 2, 250, 350, 60);
noFill();
fill(#f1c40f);
arc(width / 2, 250, 80, 80, 0, PI+2.5, PIE);
noFill();
textSize(32);
fill(#c0392b);
text("Pac-Man", 330, 350);
noFill();
}
//Randomized Selection #1 (Barely Randomized Values)
void rngSelect1()
{
rectMode(CENTER);
fill(#c0392b);
size(800,600);
fill(#f1c40f);
arc(500, 200, 80, 80, 0, PI+2.5, PIE);
noFill();
fill(#27ae60);
beginShape(TRIANGLE_FAN);
vertex(57.5 + 340+ 150, 50+ 200);
vertex(57.5+340, 15+ 200);
vertex(92+ 340+ 150, 50+ 200);
vertex(57.5+ 340, 85+ 200);
vertex(22+ 340, 50+ 200);
vertex(57.5+ 340+ 150, 15+ 200);
endShape();
noFill();
fill(#8e44ad );
rect(width / 2, 225, 100, 100);
noFill();
fill(#c0392b);
ellipse(width /2, 150, 100, 100);
noFill();
textSize(32);
fill(#c0392b);
text("Randomized Selection", 330, 500);
noFill();
}
//Randomized Selection #2 (Somewhat Randomized Values)
void rngSelect2()
{
rectMode(CENTER);
fill(#c0392b);
size(800,600);
fill(#f1c40f);
arc(500, 124, 80, 80, 0, PI+2.5, PIE);
noFill();
fill(#27ae60);
beginShape(TRIANGLE_FAN);
vertex(57.5 + 340+ 75, 50+ 200);
vertex(57.5+340, 35+ 200);
vertex(92+ 340+ 57, 50+ 203);
vertex(57.5+ 56, 85+ 53);
vertex(22+ 57, 50+ 24);
vertex(57.5+ 75+ 150, 15+ 200);
endShape();
noFill();
fill(#8e44ad );
rect(width / 2, 225, 100, 100);
noFill();
fill(#c0392b);
ellipse(width /2, 143, 100, 100);
noFill();
textSize(32);
fill(#c0392b);
text("Randomized Selection", 330, 500);
noFill();
}
//Randomized Selection #3 (More Randomized Values)
void rngSelect3()
{
rectMode(CENTER);
fill(#c0392b);
size(800,600);
fill(#f1c40f);
arc(500, 300, 80, 80, 0, PI+2.5, PIE);
noFill();
fill(#27ae60);
beginShape(TRIANGLE_FAN);
vertex(57.5 + 340+ 75, 50+ 23);
vertex(57.5+340, 35+ 127);
vertex(92+ 340+ 57, 50+ 721);
vertex(57.5+ 56, 85+ 126);
vertex(22+ 57, 50+ 234);
vertex(57.5+ 75+ 150, 15+ 34);
endShape();
noFill();
fill(#8e44ad );
rect(111, 341, 100, 100);
noFill();
fill(#c0392b);
ellipse(231, 180, 100, 100);
noFill();
textSize(32);
fill(#c0392b);
text("Randomized Selection", 330, 500);
noFill();
}
//Randomized Selection #4 (Super Randomized Values)
void rngSelect4()
{
rectMode(CENTER);
fill(#c0392b);
size(800,600);
fill(#f1c40f);
arc(500, 300, 132, 221, 0, PI+2.5, PIE);
noFill();
fill(#27ae60);
beginShape(TRIANGLE_FAN);
vertex(57.5 + 12+ 75, 50+ 23);
vertex(57.5+340, 351+ 127);
vertex(92+ 340+ 577, 50+ 12);
vertex(57.5+ 56, 85+ 136);
vertex(22+ 57, 50+ 234);
vertex(57.5+ 75+ 150, 15+ 13);
endShape();
noFill();
fill(#8e44ad );
rect(123, 461, 111, 425);
noFill();
fill(#c0392b);
ellipse(231, 180, 123, 560);
noFill();
textSize(32);
fill(#c0392b);
text("Randomized Selection", 310, 550);
noFill();
}
}
知道这里的问题是什么吗?如果你把它放在处理中,我只会得到一个空白屏幕。
默认情况下,Processing 不会 "know" 调用您的 class 方法。
与 "standard" Java 中一样,某些方法的名称为 "magic"。在 Java 中,该方法当然是 main
方法,按照惯例,它是应用程序的入口点。
在Processing中,其实有几种方法和这个类似。您提到的 setup
方法在程序开始时被调用一次。在某种程度上,您可以将其视为 main
方法和 class 构造函数之间的交叉——您可以使用它来进行基本设置(例如,屏幕尺寸、您将用于你的程序的持续时间等)。
(setup
和 main
的区别,当然是你不需要显式调用其他生命周期方法来使你的程序运行。
另一个重要的方法是void draw()
。环境每秒自动调用几次。这是您调用大部分逻辑来渲染屏幕的地方;特别是,您预计会定期更改的任何内容都应该放在此处。
(但请注意:请注意您在 draw
方法中所做的工作量,因为它被如此频繁地调用 - 否则您的 UI 将是真正的 "laggy" 似乎挂了)。
像这样获取键盘输入,获取鼠标位置和点击等"magic names"还有其他方法,但是最重要的是void setup()
和void draw()
TL;DR 您应该在 draw()
方法中调用渲染屏幕的逻辑,以便处理 "knows" 那就是 class 用于.
void setup(){}
老实说,我不知道这个顶部是做什么的,最初我的 class 'Stuff' 甚至没有出现,因为它一直说它不存在,所以有人做了那个无效设置的事情它奏效了吗?我是新手,所以如果我触发了某人,我深表歉意。
class TarotGame1
{
Stuff game = new Stuff();
}
我照常打电话给class
class Stuff
{
东西的构造函数class
Stuff()
{
tarotCircle();
tarotCircle();
tarotSquare();
tarotDiamond();
tarotPacMan();
rngSelect1();
rngSelect2();
rngSelect3();
rngSelect4();
}
//Tarot for Circle
void tarotCircle()
{
size(800,600);
rectMode(CENTER);
fill(#2c3e50);
rect(width / 2, height / 2, 300, 400, 60);
noFill();
fill(#16a085);
rect(width / 2, height / 2, 250, 350, 60);
noFill();
fill(#c0392b);
ellipse(width /2, 250, 100, 100);
noFill();
textSize(32);
fill(#c0392b);
text("Circle", 360, 350);
noFill();
}
//Tarot for Square
void tarotSquare()
{
rectMode(CENTER);
fill(#2c3e50);
rect(width / 2, height / 2, 300, 400, 60);
noFill();
fill(#16a085);
rect(width / 2, height / 2, 250, 350, 60);
noFill();
fill(#c0392b);
rect(width / 2, 225, 100, 100);
noFill();
textSize(32);
fill(#c0392b);
text("Rectangle", 330, 350);
noFill();
}
//Tarot for Diamond
void tarotDiamond()
{
rectMode(CENTER);
fill(#8e44ad);
rect(width / 2, height / 2, 300, 400, 60);
noFill();
fill(#16a085);
rect(width / 2, height / 2, 250, 350, 60);
noFill();
fill(#27ae60);
beginShape(TRIANGLE_FAN);
vertex(57.5 + 340, 50+ 200);
vertex(57.5+340, 15+ 200);
vertex(92+ 340, 50+ 200);
vertex(57.5+ 340, 85+ 200);
vertex(22+ 340, 50+ 200);
vertex(57.5+ 340, 15+ 200);
endShape();
noFill();
textSize(32);
fill(#c0392b);
text("Diamond", 330, 350);
noFill();
}
//Tarot for Pac-Man
void tarotPacMan()
{
rectMode(CENTER);
fill(#2c3e50);
rect(width / 2, height / 2, 300, 400, 60);
noFill();
fill(#16a085);
rect(width / 2, height / 2, 250, 350, 60);
noFill();
fill(#f1c40f);
arc(width / 2, 250, 80, 80, 0, PI+2.5, PIE);
noFill();
textSize(32);
fill(#c0392b);
text("Pac-Man", 330, 350);
noFill();
}
//Randomized Selection #1 (Barely Randomized Values)
void rngSelect1()
{
rectMode(CENTER);
fill(#c0392b);
size(800,600);
fill(#f1c40f);
arc(500, 200, 80, 80, 0, PI+2.5, PIE);
noFill();
fill(#27ae60);
beginShape(TRIANGLE_FAN);
vertex(57.5 + 340+ 150, 50+ 200);
vertex(57.5+340, 15+ 200);
vertex(92+ 340+ 150, 50+ 200);
vertex(57.5+ 340, 85+ 200);
vertex(22+ 340, 50+ 200);
vertex(57.5+ 340+ 150, 15+ 200);
endShape();
noFill();
fill(#8e44ad );
rect(width / 2, 225, 100, 100);
noFill();
fill(#c0392b);
ellipse(width /2, 150, 100, 100);
noFill();
textSize(32);
fill(#c0392b);
text("Randomized Selection", 330, 500);
noFill();
}
//Randomized Selection #2 (Somewhat Randomized Values)
void rngSelect2()
{
rectMode(CENTER);
fill(#c0392b);
size(800,600);
fill(#f1c40f);
arc(500, 124, 80, 80, 0, PI+2.5, PIE);
noFill();
fill(#27ae60);
beginShape(TRIANGLE_FAN);
vertex(57.5 + 340+ 75, 50+ 200);
vertex(57.5+340, 35+ 200);
vertex(92+ 340+ 57, 50+ 203);
vertex(57.5+ 56, 85+ 53);
vertex(22+ 57, 50+ 24);
vertex(57.5+ 75+ 150, 15+ 200);
endShape();
noFill();
fill(#8e44ad );
rect(width / 2, 225, 100, 100);
noFill();
fill(#c0392b);
ellipse(width /2, 143, 100, 100);
noFill();
textSize(32);
fill(#c0392b);
text("Randomized Selection", 330, 500);
noFill();
}
//Randomized Selection #3 (More Randomized Values)
void rngSelect3()
{
rectMode(CENTER);
fill(#c0392b);
size(800,600);
fill(#f1c40f);
arc(500, 300, 80, 80, 0, PI+2.5, PIE);
noFill();
fill(#27ae60);
beginShape(TRIANGLE_FAN);
vertex(57.5 + 340+ 75, 50+ 23);
vertex(57.5+340, 35+ 127);
vertex(92+ 340+ 57, 50+ 721);
vertex(57.5+ 56, 85+ 126);
vertex(22+ 57, 50+ 234);
vertex(57.5+ 75+ 150, 15+ 34);
endShape();
noFill();
fill(#8e44ad );
rect(111, 341, 100, 100);
noFill();
fill(#c0392b);
ellipse(231, 180, 100, 100);
noFill();
textSize(32);
fill(#c0392b);
text("Randomized Selection", 330, 500);
noFill();
}
//Randomized Selection #4 (Super Randomized Values)
void rngSelect4()
{
rectMode(CENTER);
fill(#c0392b);
size(800,600);
fill(#f1c40f);
arc(500, 300, 132, 221, 0, PI+2.5, PIE);
noFill();
fill(#27ae60);
beginShape(TRIANGLE_FAN);
vertex(57.5 + 12+ 75, 50+ 23);
vertex(57.5+340, 351+ 127);
vertex(92+ 340+ 577, 50+ 12);
vertex(57.5+ 56, 85+ 136);
vertex(22+ 57, 50+ 234);
vertex(57.5+ 75+ 150, 15+ 13);
endShape();
noFill();
fill(#8e44ad );
rect(123, 461, 111, 425);
noFill();
fill(#c0392b);
ellipse(231, 180, 123, 560);
noFill();
textSize(32);
fill(#c0392b);
text("Randomized Selection", 310, 550);
noFill();
}
}
知道这里的问题是什么吗?如果你把它放在处理中,我只会得到一个空白屏幕。
默认情况下,Processing 不会 "know" 调用您的 class 方法。
与 "standard" Java 中一样,某些方法的名称为 "magic"。在 Java 中,该方法当然是 main
方法,按照惯例,它是应用程序的入口点。
在Processing中,其实有几种方法和这个类似。您提到的 setup
方法在程序开始时被调用一次。在某种程度上,您可以将其视为 main
方法和 class 构造函数之间的交叉——您可以使用它来进行基本设置(例如,屏幕尺寸、您将用于你的程序的持续时间等)。
(setup
和 main
的区别,当然是你不需要显式调用其他生命周期方法来使你的程序运行。
另一个重要的方法是void draw()
。环境每秒自动调用几次。这是您调用大部分逻辑来渲染屏幕的地方;特别是,您预计会定期更改的任何内容都应该放在此处。
(但请注意:请注意您在 draw
方法中所做的工作量,因为它被如此频繁地调用 - 否则您的 UI 将是真正的 "laggy" 似乎挂了)。
像这样获取键盘输入,获取鼠标位置和点击等"magic names"还有其他方法,但是最重要的是void setup()
和void draw()
TL;DR 您应该在 draw()
方法中调用渲染屏幕的逻辑,以便处理 "knows" 那就是 class 用于.