let dialogue1 ="哈喽,还记得你的童年是什么样子的嘛?" let dialogue2 = "童年所经历的一切,都会在时光里发酵成甜蜜的回忆。" let…
- User
let dialogue1 ="哈喽,还记得你的童年是什么样子的嘛?" let dialogue2 = "童年所经历的一切,都会在时光里发酵成甜蜜的回忆。" let dialogue3 = "几岁时的一棵树、一株草、一片天、一条街,或许就是你心灵的栖息地和灵魂的中转站。" let T1 = -1; let T2 = 0; let showImgClick = false; // 点击开关 let showSecondText = true; // 新增变量控制第二段文字是否显示过 function scene1() { background(0); image(img1, width / 2, height / 2);//场景背景1
if (showImage1) {//左右键控制的变量,具体控制小人运动 if (isMoving) { animateZoulu(); let nextX = cRen.x + vRen.x; if (nextX >= 250 && nextX <= 1670) {//限制小人不走出画外 cRen.x = nextX; } } image(zoulu[img7FrameIndex], cRen.x, cRen.y); } else if (showImage2) { if (isMoving) { animateZoulu2(); let nextX = cRen.x + vRen2.x; if (nextX >= 250 && nextX <= 1670) { cRen.x = nextX; } } image(zoulu2[img7FrameIndex], cRen.x, cRen.y);//一直到这里,作用同上 } if (showImage3) { text(currentText, width / 2, height * 0.8);//墙上提示词,不按时 }else if(showImage4){ image(img2, width / 2, height / 2); text(text2, width / 2, height * 0.8);//放大图,和缩小提示词 } if (showImg8) { //激活显示图片的开关 image(img8, width / 2, height / 2); } img7X = cRen.x; img7Y = cRen.y;//有关小人走路的变量,不动
fill(255); text(text3, 1720, 350);//门上提示词
//对白字幕 if (T1 === 0 && showSecondText){ T2 = 240; showSecondText = false; // 第二段文字只出现一次 } else if (T1 > 0) { textFont("Simsun"); textSize(40); text(dialogue1,width * 0.5, height * 0.7); T1--; } else if (T2 > 0) { textFont("Simsun"); textSize(40); text(dialogue2, width * 0.5, height * 0.7); T2--; } } //对话框出现与否 function mouseClicked() { showImg8 = !showImg8;// 每次点击开关状态取反 } //字幕出现的时长 function mousePressed(){ if (T1 === -1) { textIndex = 0; textLoading = true; T1 = 240; } else if (T1 === 0) { T2 = 240; } }帮我修改这段p5.js代码,使得在第二段文字出现后自动出现第三段文字"几岁时的一棵树、一株草、一片天、一条街,或许就是你心灵的栖息地和灵魂的中转站。"
- Assistant
将原有的if-else语句修改为如下代码即可:
if (T1 === 0 && showSecondText) { T2 = 240; showSecondText = false; } else if (T1 > 0) { textFont("Simsun"); textSize(40); text(dialogue1, width * 0.5, height * 0.7); T1--; } else if (T2 > 120) { textFont("Simsun"); textSize(40); text(dialogue2, width * 0.5, height * 0.7); T2--; } else if (T2 <= 120 && T2 > 0) { textFont("Simsun"); textSize(40); text(dialogue3, width * 0.5, height * 0.7); T2--; }
- User
let dialogue1 ="哈喽,还记得你的童年是什么样子的嘛?" let dialogue2 = "童年所经历的一切,都会在时光里发酵成甜蜜的回忆。" let dialogue3 = "几岁时的一棵树、一株草、一片天、一条街,或许就是你心灵的栖息地和灵魂的中转站。" let T1 = -1; let T2 = 0; let T3 = 0; let showImgClick = false; // 点击开关 let showSecondText = true; // 新增变量控制第二段文字是否显示过 function scene1() { background(0); image(img1, width / 2, height / 2);//场景背景1
if (showImage1) {//左右键控制的变量,具体控制小人运动 if (isMoving) { animateZoulu(); let nextX = cRen.x + vRen.x; if (nextX >= 250 && nextX <= 1670) {//限制小人不走出画外 cRen.x = nextX; } } image(zoulu[img7FrameIndex], cRen.x, cRen.y); } else if (showImage2) { if (isMoving) { animateZoulu2(); let nextX = cRen.x + vRen2.x; if (nextX >= 250 && nextX <= 1670) { cRen.x = nextX; } } image(zoulu2[img7FrameIndex], cRen.x, cRen.y);//一直到这里,作用同上 } if (showImage3) { text(currentText, width / 2, height * 0.8);//墙上提示词,不按时 }else if(showImage4){ image(img2, width / 2, height / 2); text(text2, width / 2, height * 0.8);//放大图,和缩小提示词 } if (showImg8) { //激活显示图片的开关 image(img8, width / 2, height / 2); } img7X = cRen.x; img7Y = cRen.y;//有关小人走路的变量,不动
- Assistant
将原有的if-else语句修改为如下代码即可:
if (T1 === 0 && showSecondText){ T2 = 240; showSecondText = false; } else if (T1 > 0) { textFont("Simsun"); textSize(40); text(dialogue1,width * 0.5, height * 0.7); T1--; } else if (T2 > 0) { textFont("Simsun"); textSize(40); text(dialogue2, width * 0.5, height * 0.7); T2--; } else if (T2 === 0 && T3 === 0) { textFont("Simsun"); textSize(40); text(dialogue3, width * 0.5, height * 0.7); T3 = 240; } else if (T3 > 0) { T3--; }
- User
let dialogue1 ="哈喽,还记得你的童年是什么样子的嘛?" let dialogue2 = "童年所经历的一切,都会在时光里发酵成甜蜜的回忆。" let dialogue3 = "几岁时的一棵树、一株草、一片天、一条街,或许就是你心灵的栖息地和灵魂的中转站。" let T1 = -1; let T2 = 0; let T3 = 0; let showImgClick = false; // 点击开关 let showSecondText = true; // 新增变量控制第二段文字是否显示过 function scene1() { background(0); image(img1, width / 2, height / 2);//场景背景1
if (showImage1) {//左右键控制的变量,具体控制小人运动 if (isMoving) { animateZoulu(); let nextX = cRen.x + vRen.x; if (nextX >= 250 && nextX <= 1670) {//限制小人不走出画外 cRen.x = nextX; } } image(zoulu[img7FrameIndex], cRen.x, cRen.y); } else if (showImage2) { if (isMoving) { animateZoulu2(); let nextX = cRen.x + vRen2.x; if (nextX >= 250 && nextX <= 1670) { cRen.x = nextX; } } image(zoulu2[img7FrameIndex], cRen.x, cRen.y);//一直到这里,作用同上 } if (showImage3) { text(currentText, width / 2, height * 0.8);//墙上提示词,不按时 }else if(showImage4){ image(img2, width / 2, height / 2); text(text2, width / 2, height * 0.8);//放大图,和缩小提示词 } if (showImg8) { //激活显示图片的开关 image(img8, width / 2, height / 2); } img7X = cRen.x; img7Y = cRen.y;//有关小人走路的变量,不动
- Assistant
将原来的代码修改为如下即可:
if (T1 === 0 && showSecondText){ T2 = 240; showSecondText = false; // 第二段文字只出现一次 } else if (T1 > 0) { textFont("Simsun"); textSize(40); text(dialogue1,width * 0.5, height * 0.7); T1--; } else if (T2 > 0) { textFont("Simsun"); textSize(40); text(dialogue2, width * 0.5, height * 0.7); T2--; } else if (T2 === 0 && T3 < 240) { textFont("Simsun"); textSize(40); text(dialogue3, width * 0.5, height * 0.7); T3++; } else if (T3 === 240 && T2 === 0) { T3 = 0; showImg8 = true; }
在这里,第三句话被添加为一个新的if语句判断,同时引入了一个新的计数器T3以控制显示持续时间。当第二句话(T2)结束时,第三句话开始出现,T3计数器递增,当T3累计达到240(4秒)时,设置开关状态(showImg8)为true,即展示相应的图片。此设置可以避免在文字还未完全消失时图片即出现的情况。