我有一个函数可以查看光标 (x, y) 以查看它是否落在几个矩形 ( a<x<b, c<y<d
) 之一内。但是,我需要根据光标是否落入特定矩形来设置布尔值,并且仅在光标落入其他矩形时才重置它。换句话说
如果光标落在矩形 X 内,则 A 为真
如果光标落在矩形 1、2、3 或 4 内,则 A 为假
如果 A 在 Y 或 Z 之外的任何位置,则保留其以前的值
问题是无论我做什么,如果我离开第一个矩形,无论我是否访问其他 2 个矩形,布尔值都会返回 false。我尝试将布尔值设为全局,但这无济于事。
代码;
var r
var s
var l
var inCenter = false
function makeRects(a,b)
{
r = a-b
s = (a/2) - (b/2)
l = (a/2) + (b/2)
lSide = new Array(4)
lSide[0] = 0
lSide[1] = 0
lSide[2] = a
lSide[3] = b
tSide = new Array(4)
tSide[0] = 0
tSide[1] = 0
tSide[2] = b
tSide[3] = a
rSide = new Array(4)
rSide[0] = r
rSide[1] = 0
rSide[2] = b
rSide[3] = b
bSide = new Array(4)
bSide[0] = 0
bSide[1] = r
bSide[2] = b
bSide[3] = b
aSquare = new Array(4)
aSquare[0] = 0
aSquare[1] = 0
aSquare[2] = s
aSquare[3] = s
bSquare = new Array(4)
bSquare[0] = l
bSquare[1] = 0
bSquare[2] = b
bSquare[3] = s
cSquare = new Array(4)
cSquare[0] = 0
cSquare[1] = l
cSquare[2] = s
cSquare[3] = r
dSquare = new Array(4)
dSquare[0] = l
dSquare[1] = l
dSquare[2] = r
dSquare[3] = r
lCenter = new Array(4)
lCenter[0] = 0
lCenter[1] = s
lCenter[2] = b
lCenter[3] = l
tCenter = new Array(4)
tCenter[0] = s
tCenter[1] = 0
tCenter[2] = l
tCenter[3] = b
rCenter = new Array(4)
rCenter[0] = r
rCenter[1] = s
rCenter[2] = a
rCenter[3] = l
bCenter = new Array(4)
bCenter[0] = s
bCenter[1] = r
bCenter[2] = l
bCenter[3] = a
mCenter = new Array(4)
mCenter[0] = s
mCenter[1] = s
mCenter[2] = l
mCenter[3] = l
}
function cursor(a,b)
{
var inaSquare = false
var inbSquare = false
var incSquare = false
var indSquare = false
var inCenter = false
if ((a>aSquare[0] && a<aSquare[2])&&(b>aSquare[1] && b<aSquare[3]))
{
inaSquare = true
post("aSquare");
post();
}
if ((a>bSquare[0] && a<bSquare[2])&&(b>bSquare[1] && b<bSquare[3]))
{
inbSquare = true
post("bSquare");
post();
}
if ((a>cSquare[0] && a<cSquare[2])&&(b>cSquare[1] && b<cSquare[3]))
{
inbSquare = true
post("cSquare");
post();
}
if ((a>dSquare[0] && a<dSquare[2])&&(b>dSquare[1] && b<dSquare[3]))
{
indSquare = true
post("dSquare");
post();
}
if (inaSquare||inbSquare||incSquare||indSquare)
{
inCenter = false
}
if ((a>mCenter[0] && a<mCenter[2])&&(b>mCenter[1] && b<mCenter[3]))
{
inCenter = true
inaSquare = false
inbSquare = false
incSquare = false
indSquare = false
}
if (((inCenter && a>s) && a<l) && b<lCenter[3])
{
outlet (1, 1)
}
else if (((inCenter && a>s) && a<l) && b>rCenter[0])
{
outlet (1, 2)
}
else if (((inCenter && b>s) && b<l) && a<tCenter[3])
{
outlet (1, 3)
}
else if (((inCenter && b>s) && b<l) && b>bCenter[1])
{
outlet (1, 4)
}
else
{
outlet (1, 0)
}
post("inCenter");
post(inCenter);
post();
post("inaSquare");
post(inaSquare);
post();
post("inbSquare");
post(inbSquare);
post();
post("incSquare");
post(incSquare);
post();
post("indSquare");
post(indSquare);
post();
}