Using Overlaps(object) in Python

This forum is currently in read-only mode.
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • I've run into a problem with the Overlaps condition in Python. In my test file, I've got a moving block (object1) and a stationary block (object2). When the moving block is overlapping the stationary block, I want a text object (text) to display "True." When the moving block is not overlapping the stationary block, I want the text object to display "False."

    I've gotten this to work using the normal events on the event sheet, but I want to do it using a Python script. I've tried the following, but it doesn't work:

    if object1.Overlaps(object2) == True:

    text.Text = "True"

    else:

    text.Text = "False"

    What am I doing wrong? The text object displays "False" even when object1 is overlapping object2. Overlaps doesn't seem to work how I expect it to. Does anyone have any suggestions about how to get this to work? Any help would be greatly appreciated.

    -Zumbooruk

  • object2 should be in quotes:

    object1.Overlaps("object2")[/code:2x3quw2v]
    but that, although correct, causes construct to crash.
    
    Use OverlapsOffset instead:
    [code:2x3quw2v]if object1.OverlapsOffset("object2",0,0):
       Text.Text = "True"
    else:
       Text.Text = "False"[/code:2x3quw2v]
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks! OverlapsOffset works perfectly.

    I was starting to go crazy. I was trying Overlaps with double quotes, single quotes, and without quotes -- none of which works.

    -Zumbooruk

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)