How do I determine sprite overlapping with zIndex?

Not favoritedFavorited Favorited 0 favourites
  • 7 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • I'm working on a solitaire level editor. ChatGPT has been a TREMENDOUS help on this project but we're stuck on something that I thought would be fairly simple. I'm hoping one of you experts can help!

    What I'm Trying to Do:

    When I SAVE my layout I want to iterate through all the cards and, using zIndex, figure out which cards are Covering and which cards are CoveredBy the current card. These will then get saved in instance variables, like this:

    card_spr.Covering = "3, 5, 7" (this card is covering cards 3, 5, and 7)

    card_spr.CoveredBy = "" (this card isn't covered by any cards)

    ChatGPT suggested that I create 2 families with spr_card as the only member. fam_cards has all the instance variables. fam_cards2 is for the inner loop.

    This was working, but I stupidly used Construct 3's UID in my events. This doesn't work for SAVING and LOADING, so I created a new instance variable: fam_cards.CardID and I increment this every time I create a new sprite. (It gets saved with the level.)

    But if I put CardID in the sprite my families can't access it. And if I put it in fam_cards.CardID then I can't reach it with fam_cards2.CardID.

    Any suggestions? Is there an easier way to do this?

    Code Before I made my own "CardID"

    + System: For each fam_cards

    -> fam_cards: Set Covering to ""

    -> fam_cards: Set CoveredBy to ""

    ----+ System: For each fam_cards2

    --------+ fam_cards2: Is overlapping fam_cards

    ------------+ System: fam_cards2.ZIndex < fam_cards.ZIndex

    -------------> fam_cards: Set Covering to fam_cards.Covering & fam_cards2.UID & ","

    ------------+ System: Else

    -------------> fam_cards: Set CoveredBy to fam_cards.CoveredBy & fam_cards2.UID & ","

  • (removed)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Wouldn’t it be simpler to just save the type and position of each card?

    Global text data=“”
    
    On function save
    — set data to “”
    — for each card ordered by card.zindex ascending
    — — add card.x&”,”&card.y&”,”&card.animationframe&”;” to data
    
    Global text tok=“”
    
    On function load
    Repeat tokencount(data,”;”)-1 times
    — set tok to tokenat(data,loopindex,”;”)
    — create card at float(tokenat(tok,0,”,”)), float(tokenat(tok,1,”,”))
    — card: set animation frame to int(tokenat(tok,2,”,”))
  • I made a mistake in my previous comment. This code should work:

  • Thank you dop2000 and ROJOhound!!

    These are SO MUCH easier than the suggestions I was getting from ChatGPT. I spent two days iterating on this problem and it seems like the solution was pretty simple.

    Strangely, I asked ChatGPT to help me create a pretty complex interactive bezier feature for my editor, and this only took an hour or so!

    (I can add or remove cards on the fly, and they will space themselves, with the appropriate angles, along the curve. The three dark circles are handles and the cards adjust as I drag them around! Without the AI I wouldn't even have ATTEMPTED this feature.)

  • Without the AI I wouldn't even have ATTEMPTED this feature.

    Yeah, ChatGPT is getting frighteningly good at programming tasks. Almost ROJOhound-level good :)

  • Wouldn’t it be simpler to just save the type and position of each card?

    I'm already saving the positions, angles, and instance variables for each card. I need to know covering relationships between all the cards as I plan to write a simulator that randomly "plays" each level a thousand times, just using the data. This will give me stats like "average cards remaining" that I can use to help me test my 200+ levels.

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