[Fixed] Detect object at same X position?

  • Hi,

    I'm building a Infinite Jump like game. You have to jump up a tower. It'll be an improved version of my game Minimal Jump, which you can play here.

    Each floor you have jump on is based on 2 platforms (called platform1 and platform2) with a gap of 160 pixels. I want to set x of a platform, which exits to a side 160 pixels from the other platform, depending on the direction the platform is moving.

    Currently I do the following:

    platform2 has an instance variable called partner_uid, which is set to the UID of the firstly created platform1. It looks like this:

    Local number cur_uid = 0
    System: Create object platform1 at (xpos, ViewportTop("GameLayer")
    System: set cur_uid to platform1.UID
    System: Create object platform2 at (xpos+160, ViewportTop("GameLayer")
    Platform2: Set partner_uid to cur_uid
    

    Now if platform1 vanishs to the right I'll want to set its position to platform2.x-960 (size of the platforms is 800 + 160 for the gap), so it can reenter from the left. The following is my code for this event:

    Platform1: X > 1200
      System: Pick Platform2  where Platform2.partner_uid = Platform1.UID
        Action Platform1: Set X to Platform2.X-960
    

    I repeat this for X < -400 and vice versa for Platform2

    Unfortunaly this doesn't work, the Platform just disappears and doesn't reenter.

    Does anyone have a solution for this? Any help is appreciated.

    Kindest regards,

    Oliver

    (Edit) PS: Oh, just if you wonder, why this works in Minimal Jump: I have a fixed layout height there (with a very small window) and could use the wrap behaviour. This doesn't work, if the floors are randomly generated.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Never mind. I missed some calculations. :-/

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