Animate using "change attribute?"

chaleychaley Member, PRO Posts: 226
edited January 2012 in Working with GS (Mac)
A while ago, it was suggested to use "change attribute" instead of the "animate" behavior & i can't find a good example of how exactly to do that. Does anyone have an idea of how to get that done?

My game has a fair amount of animated elements, so I want to make sure things are as optimized as possible.

Comments

  • AsymptoteellAsymptoteell Member Posts: 1,362
    You could name each image in the animation sequence, starting with the first one, 1, 2, 3, 4, 5, 6, etc.
    Then make a timer: every x seconds (probably around .1) change self.image to self.attribute.image+1.

    If that doesn't work, you may have to have an in between step. Have the timer change another self attribute, name it self.animation# for instance, to that+1, then constrain self.image to that attribute.

    If that doesn't work, or doesn't make sense for some reason, just let me know, and I'll try to clarify.

    Asymptoteell
  • CloudsClouds Member Posts: 1,599
    I use this kind of thing

    When actor is touched . . . .

    Timer rule after 0.02 seconds change image to image 1.
    Timer rule after 0.04 seconds change image to image 2.
    Timer rule after 0.06 seconds change image to image 3.
    Timer rule after 0.08 seconds change image to image 4.

    Etc . . . works well for me and avoids the glitches you can get with 'animate' in certain scenarios.
  • 921creative921creative Member, PRO Posts: 140
    Tynan: So you prefer Change Image to Change Attribute? Is either one more efficient than the other? Does your method prevent an animation from briefly freezing or is that simply a memory issue?
  • CloudsClouds Member Posts: 1,599
    edited January 2012
    @ 921creative

    To be honest it's just a way to get around the animation briefly freezing / glitching when used in conjunction with certain other behaviours / rules, the change image method seems much more robust (far more robust than 'animate) - stabbing my finger/mouse wildly at the actor (when using 'touch, to trigger the animation) as fast as I can causes no problems whatsoever for the change image method, whereas doing this with animate can throw up all kinds of odd little glitches.

    I've not tried Asymptoteell's method, but it sounds like it would work just fine too.
  • chaleychaley Member, PRO Posts: 226
    So... the "change image" behavior is OK to use? I thought that the "change image" behavior was also a "no-no."
  • MotherHooseMotherHoose Member Posts: 2,456
    IMO ChangeAttribute self.image is more efficient!
    at the change of scene the computer √ all calls for display of images; locates them in the Resources files; and loads them into memory …
    this includes images displayed in Actors and their behaviors and the changeImage behavior displays an image;
    while the changeAttribute self.image is a string … change occurs/image is drawn in runtime.
    Rule: All when
    Attribute self.Image is 4 (the last images in your sequence )
    --Timer: After 0.1 √Run to Completion
    ----changeAttribute self.Image To: 1 (this gets the sequence to restart)
    Otherwise:
    Timer: Every 0.1 seconds √Run to Completion
    changeAttribute self.Image To: self.Image+1
    aha! sometimes you have to start with the end condition to get to the beginning! … and computers are supposed to be logical! ;D


    you do not need to type in .png … any image in GS is a .png

    (0.1 = 6 images/second—FPS; and, 0.15 = 4 FPS)

    because the images names are #s and not text … you can manipulate them with the mathematical operants (+/-)

    MH
  • mynameisacemynameisace Hull, UKMember Posts: 2,484
    edited January 2012
    @MotherHoose +1 - I never use the change image rule, change attribute is the way to go and as MH pointed out, you have more control. You cannot to +/- with change image, just bogs down the code with more rules/bahaviours.

    Ace
  • mynameisacemynameisace Hull, UKMember Posts: 2,484
    Yeah, I use animate now, whereas I didn't used to before pre-load art. I was saying about when a change image is necessary. If I have some images for instructions or something, I set a change attribute self.image to self.image+1 or if I have something set to a numbered attribute, I have my images named as those numbers.

    For animation now, I use animate :)

    Ace
  • MotherHooseMotherHoose Member Posts: 2,456
    edited January 2012
    @tshirtbooth … I stand corrected; and as usual in awe of TSB … please bear in mind that my mindset is still old-style …

    though I still prefer the changeAttribute to changeImage; as believe the images that are on display in a scene, while not preloaded at gameStart, are loaded in memory at sceneStart; and think mayhap images in changeAttribute are not retained in memory (the same appears to be so in animationBehavior.)

    also, I use many transparent.png(s) for images outside the cameraSize area with a scene.loadImages boolean controlActor running a timer after 0.5 seconds to change to true; and, on those transparentActors the Rule when that boolean is true changeAttribute self.Image ... seems run faster for large scenes.

    MH
  • CloudsClouds Member Posts: 1,599
    edited January 2012
    @ tshirtbooth

    "wait, I'm lost. why don't you want to use animate?"

    I simply couldn't get certain things to work with animate, for instance when animating something (with 'animate') and also moving the actor (using change attribute) - I didn't seem to have control over which piece of code happened first (the move or the frames completing) so I ended up with all sorts of weird happenings.

    I am fully willing to accept that I haven't got a clue what I am doing as I am still learning and still have a ton of stuff to even begin to understand, but after a few hours of wrestling with animate I gave up defeated, but after a couple of minutes with ChangeImage I had what I was after, and it seemed unbreakable (compared to animate) no matter how many crazy clicks and drags and randomness I threw at it it refused to glitch in any way.

    And to be honest I've not thought of using Change Attribute . . . . . do you think it would be a better option . . . ?

  • CloudsClouds Member Posts: 1,599
    edited January 2012
    ...
  • chaleychaley Member, PRO Posts: 226
    edited January 2012
    OK... I just disabled the "preload art" on the animated actors & it seems to be running a lot better. It'd be nice to keep the "animate" behaviors as they are nice & easy to set up. Thanks for the suggestions everyone!
  • firemaplegamesfiremaplegames Member Posts: 3,211
    I made an animation controller demo a few years ago:
    http://arcade.gamesalad.com/game/3158

    I cannot seem to play it anymore as it isn't html5? And I cannot locate it in the Creator any more either. Perhaps they removed all of my demos for some reason?

    Anyway, if you can find a way to open it, feel free to dig around in it.

    The advantage of using a custom built Animate behavior is the ability to dynamically change the playback speed of the animation at Runtime. You also have the ability of dynamically playing the animation both forwards and reversed, also instantly changeable during Runtime.

    If you fiddled with the math a bit, you could also have it play forwards then backwards then forwards, etc. creating a pulsing or rocking effect.

    It also used to have the advantage of not preloading the images for iOS causing shorter load times. This appears to have been addressed with the preload art checkbox.

    However, not preloading the art is now an issue though with html5, as the remaining frames of animation appear blank until they are loaded in.

    If you cannot find the demo I made ( as I am unable to!) just email me and I will send you the file.

    Joe
  • chaleychaley Member, PRO Posts: 226
    Hey Joe... Thanks for the "heads up" on that. I was hoping to get a rig going to dynamically change the fps of the animation to match the game speed, and I found your controller a while ago, but I wasn't sure which attributes I needed vs. the ones that were specific for your rig. My GS knowledge is improving, but it's still easy for me to get my wires crossed unless the examples are pretty exact. My scene has a character with a run cycle that basically stays at the same speed all the time. It's weird... I thought it would look odd that as the game got faster, he was still animating at the same speed, but it doesn't actually look that bad.

    It'd be great though, if the fps was controllable right in the "animate" behavior. That'd be a HUGE improvement.
  • ClockClock Member Posts: 308
    what are you guys talking about? Preload art? is that an attribute in GS? can someone summarize this? i am still new...
  • SharkawyDevSharkawyDev Member Posts: 225
    @kinwaing , Preload is an option inside each of your actors , it allows you to choose whether you want all the art in the game to be loaded on launch or when it's only needed.
  • ClockClock Member Posts: 308
    which one is better?
  • CloudsClouds Member Posts: 1,599
    edited January 2012
    kinwaing

    Depends on what you need, fast load times or a tonne of actors right from the start . . . . I don't know too much about it either, I am still picking up clues from other people's conversations.

    Double click an actor in the (top) left panel to get it's attributes window up, you will se the Preload Art option.
Sign In or Register to comment.