简体   繁体   English

If 语句使用移相器 3 库检查“RectangleToRectangle”Javascript 中的 boolean 值

[英]If statement to check boolean value of in "RectangleToRectangle" Javascript using the phaser 3 library

Okay i'm using the phaser 3 library to build a small game.好的,我正在使用 Phaser 3 库构建一个小游戏。 In this game an user has to place game elements on a specific place on the screen.在此游戏中,用户必须将游戏元素放置在屏幕上的特定位置。 If all the elements are in the correct place one point should be added.如果所有元素都在正确的位置,则应添加一个点。 If they are not the game resets to previous state.如果他们不是,游戏将重置为之前的 state。

I have the underlying code:我有底层代码:

First to get the Bounds of the objects首先获取对象的Bounds

var bounds_po_orderid = this.answer_element_po_orderid.getBounds();
var bounds_po_eventid = this.answer_element_po_eventid.getBounds();
var bounds_po_orderdate = this.answer_element_po_orderdate.getBounds();
...............

Second compare if the different bounds intersect:其次比较不同的边界是否相交:

var overl_answerzone_one_bounds_po_orderid  = Phaser.Geom.Intersects.RectangleToRectangle(bounds_po_orderid, bounds_answerzone_one);
var overl_answerzone_one_bounds_po_eventid  = Phaser.Geom.Intersects.RectangleToRectangle(bounds_po_eventid, bounds_answerzone_one);
var overl_answerzone_one_bounds_po_orderdate  = Phaser.Geom.Intersects.RectangleToRectangle(bounds_po_orderdate, bounds_answerzone_one);
var overl_answerzone_one_bounds_po_line_purchaseorderid = Phaser.Geom.Intersects.RectangleToRectangle(bounds_po_line_purchaseorderid, bounds_answerzone_one);

And check if the true/false value when a button is pressed:并检查按下按钮时的真/假值:

this.input.on("gameobjectdown", function (pointer, gameObject) 
    {
        if (gameObject.name == "check_answer_button") 
        {
            if (overl_answerzone_one_bounds_po_orderid ===  true && 
              overl_answerzone_one_bounds_po_eventid === false && 
              overl_answerzone_one_bounds_po_orderdate === false && 
              overl_answerzone_one_bounds_po_line_purchaseorderid === false && 
              overl_answerzone_one_bounds_po_line_orderlineid === false 
             ) 
            {
                this.count = 1
                eventsCenter.emit('update-count', this.count)
            }
            else
            {
                // reset all the controls
            }

The code above doesn't work.上面的代码不起作用。 For some reason when the first element is in the correct place it doesn't matter where the rest of the elements is placed it will say that the if statement can be fired.出于某种原因,当第一个元素位于正确的位置时,元素的 rest 放置在哪里并不重要,它会说可以触发 if 语句。 I tried replacing the "===" with "==".我尝试用“==”替换“===”。 No result.没有结果。 So basically I don't know what i'm doing wrong.所以基本上我不知道我做错了什么。

Assuming this is all the relevant code you need to check that the other elements are in fact in the right spots too.假设这是所有相关代码,您需要检查其他元素是否也在正确的位置。

Right now you are only checking that the first element is in the first answer zone and that none of the other elements are there.现在您只检查第一个元素是否在第一个答案区域中,并且没有其他元素存在。

If you have different answer zonen for the other elements you need to check that they are in their right answer zone.如果您对其他元素有不同的答案区域,您需要检查它们是否在正确的答案区域中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM