I came up with a solution for a sequenced tween issue I was having!

Not favoritedFavorited Favorited 0 favourites
  • 8 posts
From the Asset Store
Calculate parabolic trajectories and tween objects over them.
  • This forum has been an invaluable resource for me so I am posting this in an attempt to "give back" to the community. (This technique might be used by many of you already but perhaps it will be new to some. It was new to me!)

    The Problem:

    My game has 20 or so instances of a card on the screen. To spin the card I have to sequence multiple tweens together, like this:

    - Get UID of clicked on card

    - Tween xscale from 1 to 0

    - If tween is finished --> change sprite image to back

    - Tween xscale from 0 to 1

    - If tween is finished --> change sprite image to front

    But because there can be multiple tweens happening at the same time the logic was getting confused. For example, before the first tween sequence had completely finished the player might have picked a new card. Now my "On finished" event would reference the wrong instance!

    My Solution:

    When I create a tween I now tag it with the UID of the card that was clicked on. Then I can pick the correct card by parsing the tag.

    The player clicks on a card:

    -> fam_cards: Tween "spin1_" & fam_cards.UID property X Scale to 1...

    Then I can simply check:

    + fam_cards: On Tween "spin1_" & tokenat(fam_cards.Tween.Tags,1,"_") finished

    + System: Pick fam_cards by evaluating fam_cards.UID = int(tokenat(fam_cards.Tween.Tags,1,"_"))

  • I'm waiting for one of the experts to tell me, "You are WAY overcomplicating things. All you need to do is..."

    ;-)

  • If it works, it works and it seems to make sense to you so I say stick with it.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You are WAY overcomplicating things. All you need to do is...

    wackytoaster.at/parachute/cardflip.c3p

    At least that's roughly how I'd do it. But there's obviously more than one way to get to the goal. I've used something similar to your method before for something else, where I stored the UID in a tag.

  • I mean if you’re after alternative ways to flip cards, here’s a way with two instance variables: target and spin.

    On card clicked
    — card: set target to 180-self.target
    
    Every tick
    — card: set spin to lerp(self.spin, self.target, exp(-16*dt))
    — card: set width to self.imageWidth*cos(self.spin)
    — card: set animation to self.width>0?”back”:”front”
  • WackyToaster

    Haha! Unfortunately, I can't open your example. (It says you are using a newer version and won't let me open the file...) Are you using a beta version?

    Before I "fixed the issue" my code was doing this:

    If card clicked on, set global value cardClickedOn
     If random greater than 50 --> start "flip1" tween
     Else --> start "spin1" tween
    
    If flip1 tween is finished start flip2 tween for cardClickedOn
    If spin1 tween is finished start flip2 tween for cardClickedOn
    
    If flip2 tween is finished start flip3 tween for cardClickedOn
    If spin2 tween is finished start flip3 tween for cardClickedOn
    
    If flip3 tween is finished start flip4 tween for cardClickedOn
    If spin3 tween is finished start flip4 tween for cardClickedOn
    

    But I was clicking on new cards before the tweens were finished, so cardClickedOn was no longer the card I was trying to tween.

    I thought about having an instance variable called "Tweening" for each card and iterating through all of them to continue any tweening that had started, but I would have to constantly iterate through every single card.

    Then I hit on the new idea. (Based on an AI suggestion.) Now I just create a bunch of uniquely named tweens that include the UID so I know which card to update.

  • Oh yeah, I'm on the beta branch. You can just open it in the newest beta if you want to take a look.

  • You can put Tween actions in Function and check Asynchronous. and use "wait for previous actions" to ensure that the previous tween animation is completed.

    Here is an old example

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