Mapping sprite-frame indices by team selection (Construct 3)

Not favoritedFavorited Favorited 0 favourites
  • 8 posts
From the Asset Store
Two types of minimap: "full map" and "player is the center" (square map and radial map)
  • Hi Everyone,

    I’m working on a Candy-Crush-style game that loads most of its data from JSON. I have two teams, and I’d like to switch which range of sprite-frames is used based on a SelectTeam value:

    If SelectTeam = 0, use frames [0, 1, 2, 3, 4, 5]

    If SelectTeam = 1, use frames [6, 7, 8, 9, 10, 11]

    What I really want is to take the original frame index (say i from 0 to 5) and map it dynamically so that when SelectTeam = 1, it becomes i + 6 (e.g. 0→6, 1→7, 2→8, etc.), and make that the new, persistent frame number at runtime. I’ve tried a few different event setups (arrays, At() expressions, setting animation frame, etc.), but none have given me a permanent mapping.

    How can I best implement this in Construct 3 so that the sprite always shows the correct team’s frames? Any sample events or tips would be much appreciated—thanks in advance!

  • I mean it sounds like you have the right idea.

    For example you could use tokenat to map 0-5 to another value, and do it differently per team.

    Compare Team=0
    — Frame = int(tokenat(“0,1,2,3,4,5”, index, “,”))
    Else
    Compare Team=1
    — Frame = int(tokenat(“6,7,8,9,10,11”, index, “,”))

    Or you can reduce that to just:

    Frame =6*team+index

    If that makes sense.

  • 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 a lot easier to have two animations with frames 0-5, one animation for each team?

  • Thank you for your feedback. I tried creating 2 separate sprites and testing with frames 0–5, but it didn’t work. The (6 * SelectTeam + index) approach worked to some extent, but I couldn’t get consistent results :( . I’ll still give the "tokenat" method another try. Thanks again!

  • I mean it sounds like you have the right idea.

    For example you could use tokenat to map 0-5 to another value, and do it differently per team.

    Compare Team=0
    — Frame = int(tokenat(“0,1,2,3,4,5”, index, “,”))
    Else
    Compare Team=1
    — Frame = int(tokenat(“6,7,8,9,10,11”, index, “,”))

    Or you can reduce that to just:

    Frame =6*team+index

    If that makes sense.

    I'm not very good with code, so please correct me if I'm wrong.

    I couldn't find any variable called index, so I used LoopIndex instead.

    But when SelectTeam is 1, all the images show only frame 6 — it doesn't distribute across (6,7,8,9,10,11).

    What is the correct way to do it?

  • Index is the initial frame index you refer to in your initial post.

  • I tried creating 2 separate sprites and testing with frames 0–5, but it didn’t work.

    Not two sprites. One sprite, but with two animations - "Team1" and "Team2". Both animations consisting of 6 frames.

  • The issue is resolved now. The template I was working with had a lot of arrays and JSON structures, so it was quite complex and took some time.

    In short, I ended up combining all the sprites into a single animation. Then I adjusted all the variable references across the game so that they matched the corresponding frames in that sprite. It was a major and time-consuming change, but it worked out in the end.

    Thank you very much for your help—your insights were truly valuable. :)

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