【问题标题】:how do you scan if there is something active in javascript如果javascript中有活动的东西,你如何扫描
【发布时间】:2019-04-15 23:14:23
【问题描述】:

stage3 在 stage 2 之后。我想知道如何判断 mouseIsPressed 和 stage2 是否处于活动状态。

我已经尝试过if(mouseIsPressed&&stage2===true){so on}

var hp=100;
var name=["boromon","telemon","heptamon","coromon"];
var boromon={
eyecolor:"blue",
skincolor:[0,0,255],
abilitys:["beam of life","blinding bite","stare strike"]
};
var enemy=[hp,name[1]];
fill(255, 0, 0);
text(name[0]+" wants to be your freind"+"                               click to accept",10,10);
var currentCharacter=[];


fill(41, 23, 23);
text(currentCharacter,10,10);
var stage2=function(){
background(255, 0, 0);
text(currentCharacter+" is now your freind                          click to continue",10,10);

};

var stage3=function(){
background(0, 174, 255);
var star=getImage("space/star");
image(star,10,10);
image(star,10,10);
image(star,10,10);
image(star,10,10);
};


draw=function() {
    if(mouseIsPressed)
{currentCharacter=name[0];}

if (mouseIsPressed){
    stage2();

if(mouseIsPressed){stage3();}
}
};

我想每次按下鼠标,输出都不一样

【问题讨论】:

  • 您需要搜索“javascript, event listeners”的引用。您可以将页面设置为“侦听”用户何时按下鼠标的事件,并进行相应的处理,而不是使用一个变量来说明是否按下了鼠标。
  • 我建议看一下 MDN 指南,尤其是 developer.mozilla.org/en-US/docs/Learn/JavaScript/…

标签: javascript function object


【解决方案1】:

你还没有定义 mouseIsPressed - 让它变得更简单:

var mouseIsPressed = 0;
document.body.onmousedown = () => ++mouseIsPressed;
document.body.onmouseup = () => --mouseIsPressed;

【讨论】:

  • 谢谢,但我需要了解如何查看它所在的页面,例如 stage2 或 stage3
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-10
  • 2023-03-23
  • 1970-01-01
  • 1970-01-01
  • 2018-10-01
  • 2017-09-10
  • 1970-01-01
相关资源
最近更新 更多