Fast Frame Swap

13»

Comments

  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2014
    @sawkastee
    @Socks

    How would I get it to display my last image after all frames have finished playing instead of a just a blank white box?
    For something that only plays through once I'd usually just do something like this - a rule that is looking for your last frame before carrying out its rules - and the rules it has are empty (i.e. do nothing) - and in the otherwise section place the stuff you want to happen before you get to the last frame.

    So basically the rule is saying: when the frame number is (in this example) 20 then do nothing (i.e. stop) . . . but until we reach frame 20 then play through the image sequence.

    You can use any frame number you like as the stop point.

    image
  • FajlajpFajlajp Member Posts: 666

    I can´t get the offset to work properly. My images is called Pirate_40 and goes upto Pirate_53
    So it´s 14 frames and I want the framerate to be 10
    So it should be
    Constrain attribute: self.image to "Pirate_"..(floor(( self.Time*10)+40)%14)
    But it dosen´t work, it only plays from another animation which goes from Pirate_0 to Pirate_12
    Any idea how to do?

  • SocksSocks London, UK.Member Posts: 12,822
    edited June 2014

    @Fajlajp said:
    I can´t get the offset to work properly. My images is called Pirate_40 and goes upto Pirate_53
    So it´s 14 frames and I want the framerate to be 10
    So it should be
    Constrain attribute: self.image to "Pirate_"..(floor(( self.Time*10)+40)%14)
    But it dosen´t work, it only plays from another animation which goes from Pirate_0 to Pirate_12

    Any idea how to do?

    . . .

    Quoted from the OP.

    @Socks said:
    ► The above example assumes an image sequence starting on frame '0' and having no file name, just the numbers (so basically an image sequence going 0, 1, 2, 3, 4, 5 . . . etc [see attached file's image sequence for an example of this]). But If your frame doesn't start on 0, but instead starts on 1 then simply add 'plus 1' like this:

    Constrain image to (floor( game.Time *30)%21)+1

    "Pirate_"..floor((self.Time*10)%14)+40

  • FajlajpFajlajp Member Posts: 666

    Sorry, my misstake, I did like that "Pirate_"..floor((self.Time*10)%14)+40

  • FajlajpFajlajp Member Posts: 666

    Just wrote wrong here

  • KovaKova Member Posts: 5

    Hi guys, I tried this, but I get stuck every single time.

    I have 30 fps, 50 images. But I don't know how to stop animation, I'm using it for explosion animation after touch is pressed.

    I got stuck on many issues.
    I can make it to start from first and to run on touch, that part is good.
    I can't make it stop, it runs over and over again, no matter what I do.
    If I remove %50 (it doesn't run at all)

  • SocksSocks London, UK.Member Posts: 12,822

    @Kova said:
    Hi guys, I tried this, but I get stuck every single time.

    I have 30 fps, 50 images. But I don't know how to stop animation, I'm using it for explosion animation after touch is pressed.

    I got stuck on many issues.
    I can make it to start from first and to run on touch, that part is good.
    I can't make it stop, it runs over and over again, no matter what I do.
    If I remove %50 (it doesn't run at all)

    You have probably set it up incorrectly.

  • KovaKova Member Posts: 5

    When I have it alone in project, works fine. When I have some other rules, doesn't work, could you help me setup project. When I touch actor *image to do animation and stop after running once?

  • SocksSocks London, UK.Member Posts: 12,822
    edited October 2014

    @Kova said:
    When I have it alone in project, works fine. When I have some other rules, doesn't work

    Then I would guess the issue might be with the other rules.

    @Kova said:
    When I touch actor *image to do animation and stop after running once?

    I think that's been mentioned a couple of times somewhere in this thread already . . . . hold on . . . yes, it is at the top of this page.

  • KovaKova Member Posts: 5
    edited October 2014

    I found it Socks, I really did, I read all this like 10 times now :(
    Ok, I got it after touch to run once, but it looks like it skipped many frames, as it is 50 images, should be for 25fps (2sec), but it is much shorter. If I loop it then first it skips some, then goes from start, and looks good.

    Maybe it's preview thing as I'm on PC.

  • SocksSocks London, UK.Member Posts: 12,822
    edited October 2014

    @Kova said:
    Maybe it's preview thing as I'm on PC.

    It's impossible to say as I know nothing about your project, maybe test it on an iPad/Phone/Android ?

  • FrantoFranto Member Posts: 779

    Ok, what your saying is. %x Modulus limits up to a certain number before repeating, and the +x part is the number it starts the count at, going in a loop.

    So if I had 100 image files, name Filename_00 and up, and images 20 to 50 pertained to a run motion. The below code would loop said animation from 20 to 50 repeatedly?

    Filename_((self.Time*30)%50)+20

  • SocksSocks London, UK.Member Posts: 12,822

    @Franto said:
    So if I had 100 image files, name Filename_00 and up, and images 20 to 50 pertained to a run motion. The below code would loop said animation from 20 to 50 repeatedly?

    Filename_((self.Time*30)%50)+20

    It would be:

    "Filename"..floor(self.time*30)%31+20

  • FrantoFranto Member Posts: 779

    @Socks Thanks for the correction, and about floor's removal, reason I thought it wasn't needed was that it was mentioned earlier in the thread that removing floor from the equation still yielded the same result even if there were decimals, perhaps it was discovered later that it was not a good idea?

  • SocksSocks London, UK.Member Posts: 12,822

    @Franto said:
    Socks Thanks for the correction, and about floor's removal, reason I thought it wasn't needed was that it was mentioned earlier in the thread that removing floor from the equation still yielded the same result even if there were decimals, perhaps it was discovered later that it was not a good idea?

    Yep, you need to read the whole thread, the floor function is needed.

  • gamestewgamestew Member Posts: 11

    you just gave me a reason to delete a couple projects. =) youre so smart socks!

  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2015

    @bobarino said:
    Rather than basing the FPS on the velocity of the actor, I'm trying to base it on the velocity of a different actor. Ex: I have the 'background actor' moving to simulate motion and i need the 'main characters' animation FPS to be base off of the background moving speed. (the 'main character' remains centered at all times, and the 'Background actor' is a moving backdrop which wraps continuously) As the background speeds up, the main character animation speeds up.....?

    Constrain image to floor( Insert FPS here )%21

    Constrain image to floor( background linear velocity divided by some suitable number that scales to your animation frame numbering )%21

  • ChimoruChimoru Member, PRO Posts: 137

    This is a great method! Here's a tricky problem I'm trying to solve to no avail:

    play the sequence up to a certain frame, and then play the sequence backwards.

    I can't seem to figure out a solution using this method. Any ideas?

  • SocksSocks London, UK.Member Posts: 12,822
    edited July 2015

    @Chimoru said:
    play the sequence up to a certain frame, and then play the sequence backwards.

    A simple way to do this would be . . .

    Constrain self.image to round(X)

    Rule
    --When X = 0
    ----Interpolate X to 12

    Rule
    --When X = 12
    ----Interpolate X to 0

    . . . . .

    Edit: example attached.

  • ChimoruChimoru Member, PRO Posts: 137

    Perfect! Thank you for the quick response.

  • SocksSocks London, UK.Member Posts: 12,822
    edited July 2015

    @Chimoru said:
    Perfect! Thank you for the quick response.

    You could also dump the two Interpolate rules and do it with a single constrain behaviour, like this, Constrain image to . . .

    . . . . . . . . . .

    round(10 *cos(( game.Time *200)+180)+10)

    . . . . . . . . . .

    200 is the speed.
    The two 10's are the sum of the range of frames.
    The 180 is the starting point within the sequence.
    (180° = starting at the first frame, 0° = starting at the last frame)

    So looping back and forth over a 40 frame sequence called "trapdoor_1" "trapdoor_2" "trapdoor_3" (. . .) would look like this . . .

    "trapdoor_"..round(20 *cos(( game.Time *200)+180)+20)

  • ChimoruChimoru Member, PRO Posts: 137

    Nice! I like the cosine method, but is there any way to make the sequence play linearly using one constrain? Since cosine tapers off the framerate doesn't stay the same and the last frames are shown for longer. Maybe a different function?

  • SocksSocks London, UK.Member Posts: 12,822

    @Chimoru said:
    . . . Since cosine tapers off the framerate doesn't stay the same and the last frames are shown for longer. . . .

    Yep, the only reason I posted that was that when doing the 2 Interpolate rules version I noticed how much nicer it looked with ease in and ease out engaged (especially at higher frame rates) . . . but yes, the cos/sin version will dampen into the end points, I'm sure there's a single constrain calculation that will produce a linear version, I'll give it some thought . . . . .

  • ChimoruChimoru Member, PRO Posts: 137
    edited July 2015

    Here's a linear version!

    "framerate" is a decimal, I found .32 to be around 16 FPS, and it oscillates linearly between 0 to "maxFrame". It's based on a triangle wave function.

  • GameAlchemistGameAlchemist Member Posts: 106

    Thanks! this'll help with optimisation! :)

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2015

    @Chimoru said:
    Here's a linear version!

    "framerate" is a decimal, I found .32 to be around 16 FPS, and it oscillates linearly between 0 to "maxFrame". It's based on a triangle wave function.

    Neat ! And useful !! :smile:

  • RetropixRetropix Member Posts: 10

    Hellow forum, This is my first post and first month of gamesalad.
    Im having a problem using this method to animate a character. He moves at a liner velocity of 80 and I want him and the animation to slow down when he is in contact with a goop actor.

    This is the math Im using "char_run"..floor(self.time*(self.motion.linear velocity.x/10))%4

    The problem is that a white box apears when "char_run2" is supposed to be displayed
    If I add a +1 at the end the white box doesn't appear but it skips the 2nd frame.

    My frames are named char_run1,char_run2,char_run3,char_run4

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    The mod() or % function will return the remainder of a division problem. So x%4 or mod(x,4) will return the remainder when x is divided by 4. Possible values of the second part of the expression are 0, 1, 2, or 3. So what's happening is that you are getting char_run0 when dividing a multiple of 4 by 4. Adding one should result in values of 1, 2, 3, or 4. If it doesn't, then something else is wrong and I'm not sure what that might be. I would recommend using an Every 0 seconds timer with a Log Debugging Statement with that expression and checking the Log Debugger window to see if you ever get char_run2.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • RetropixRetropix Member Posts: 10

    Thank you for the speedy reply!
    I fixed it by adding a - to self.motion.velocityx / (self.time*(-self.motion.linear velocity x/10))
    For some reason the animation was runing in reverse and adding the - fixed both issues.

Sign In or Register to comment.