Author Topic: moving animation  (Read 10294 times)

krog9

  • Newbie
  • *
  • Posts: 8
    • View Profile
moving animation
« on: August 14, 2015, 12:35:25 AM »
Hi there! I am newbie in this difficult matter. In general, i animated spritesheet animation in my layout, uses spritesheet.nut, but i want to do it at the same time moving across the screen. Please, prompt novice how to do it?

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: moving animation
« Reply #1 on: August 14, 2015, 07:59:01 AM »
Rather than use spritesheet.nut module, use the animate module. It allows for both spritesheets and animations. Code to do a spritesheet and move it will looks something like this:

Code: [Select]
fe.load_module("animate");

local my_obj = fe.add_image("image.png", 0, 0, 128, 128 );
local sprite_config = {
   when = Transition.ToNewSelection,
   width = 128,
   frame = 0,
   order = [ 0, 1, 2, 3, 4 ],
   time = 3000
}
local move_config = {
   when = Transition.ToNewSelection,
   property = "x",
   start = 0,
   end = 300
}

animation.add( SpriteAnimation( my_obj, sprite_config ) );
animation.add( PropertyAnimation( my_obj, move_config ) );


For the module, get the animate.nut and animate folder here:
https://github.com/liquid8d/attract-extra/tree/master/modules

krog9

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: moving animation
« Reply #2 on: August 14, 2015, 10:10:10 AM »
Thank you, liquid, this animate.nut - handsome stuff :)

krog9

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: moving animation
« Reply #3 on: August 16, 2015, 10:13:54 PM »
Another question, I have an animation, after she played, I need to create an animation in a different plane, for example, the first animation in y = 120, the second animation y = 170, while I can not use a delay, because I want to second the animation loop and it should be played without delay. Is it possible to somehow put a one-time delay?

Previous suggestion helped me will move on, and I hope this time you can help.

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: moving animation
« Reply #4 on: August 16, 2015, 10:35:14 PM »
Not sure exactly what you mean, another animation on the same object? Yes you can and there is a 'delay' option. Set the delay of the 2nd animation to start a little after the length of the first one:

Code: [Select]
local my_obj = fe.add_image("image.png", 0, 0, 128, 128 );
local move1_config = {
   when = Transition.ToNewSelection,
   property = "y",
   start = 0,
   end = 120,
   time = 1000
}
local move2_config = {
   when = Transition.ToNewSelection,
   property = "y",
   start = 120,
   end = 160,
   delay = 1500
}

animation.add( PropertyAnimation( my_obj, move1_config ) );
animation.add( PropertyAnimation( my_obj, move2_config ) );

krog9

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: moving animation
« Reply #5 on: August 16, 2015, 11:50:27 PM »
In more detail, the first animation should "escape" for the screen (I have already taken care of), second (not necessarily the same object, but it is advisable) should run out of the screen is slightly lower, the performance of the first animation I make somewhere 9000, this means that the delay of the second animation is also 9000, and everything would be fine, if a loop occurred without the same delay. Here's the code to play the first animation:

local buster = fe.add_image("busterCarrot.png", 180, 140, 52, 130 );
local buster_config = {
   when = Transition.StartLayout,
   width = 42,
   height = 56,
   loop = false,
   frame = 0,
   order =[0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],
   time = 9000
}
local busterm_config = {
   when = Transition.StartLayout,
   property = "position",
   loop = false,
   end = {x = 180, y = 140},
   time = 9000
}
local busterrun_config = {
   when = Transition.StartLayout,
   width = 42,
   height = 56,
   loop = false,
   delay = 9000,
   frame = 0,
   order = [3,4,5,6,7,8,3,4,5,6,7,8],
   time = 578
}
local busterrunm_config = {
   when = Transition.StartLayout,
   property = "x",
   delay = 9000,
   loop = false,
   start = 180,
   end = -70,
   time = 578
}

animation.add( SpriteAnimation( buster, buster_config ) );
animation.add( PropertyAnimation( buster, busterm_config ) );
animation.add( SpriteAnimation( buster, busterrun_config ) );
animation.add( PropertyAnimation( buster, busterrunm_config ) );

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: moving animation
« Reply #6 on: August 21, 2015, 09:30:51 AM »
I think I see what you mean with delay, as it applies each time the animation restarts. There are still bugs in the animation module that I need to work out. It might be possible right now, but you might have to use some "work arounds" to get it the way you want.

Ideally, something like this would work - but that seems to be a bit broken as well:
Code: [Select]
local buster = fe.add_image("busterCarrot.png", 180, 140, 52, 130 );
local busterm_config = {
   when = Transition.StartLayout,
   property = "position",
   loop = false,
   end = {x = 180, y = 140},
   time = 9000,
   onStop = function( anim )
   {
        local busterrunm_config = {
           when = When.Always,
           property = "position",
           pulse = true,
           start = { x = 180, y = 140 },
           end = { x = 0, y = 140 },
           time = 500
        }
        animation.add( PropertyAnimation( buster, busterrunm_config ) );
   }
}

Let me know if you are able to get it working properly. If just adding a way to only delay at start of animation will fix it for you, I'll look into getting that implemented.

krog9

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: moving animation
« Reply #7 on: August 24, 2015, 02:39:04 AM »
While I can not understand what the appointment line at onStop, probably it is necessary to consider once again animate.nut))
Check my code can you find something important:
Code: [Select]
local buster = fe.add_image("busterCarrot.png", 180, 140, 52, 130 );
local buster_config = {
   when = Transition.StartLayout,
   width = 42,
   height = 56,
   loop = false,
   frame = 0,
   order =[0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],
   time = 9000
}
local busterm_config = {
   when = Transition.StartLayout,
   property = "position",
   loop = false,
   end = {x = 180, y = 140},
   time = 9000
}
local busterrun_config = {
   when = Transition.StartLayout,
   width = 42,
   height = 56,
   loop = false,
   delay = 9000,
   frame = 0,
   order = [3,4,5,6,7,8,3,4,5,6,7,8],
   time = 578
}
local busterrunm_config = {
   when = Transition.StartLayout,
   property = "x",
   delay = 9000,
   loop = false,
   start = 180,
   end = -70,
   time = 578
}

animation.add( SpriteAnimation( buster, buster_config ) );
animation.add( PropertyAnimation( buster, busterm_config ) );
animation.add( SpriteAnimation( buster, busterrun_config ) );
animation.add( PropertyAnimation( buster, busterrunm_config ) );
//Anything above this is the first two animations, that is, the character stands still 9000 milliseconds (or whatever), at the end of 9000 milliseconds, it runs off the screen.


local buster2 = fe.add_image("busterCarrot.png", -70, 167, 52, 130 );

local buster2_config = {
   when = Transition.StartLayout,
   width = 42,
   height = 56,
   loop = true,
   frame = 0,
   order = [9,10,11,12,9,10,11,12,9,10,11,12],
   time = 490
}
local busterm2_config = {
   when = Transition.StartLayout,
   property = "x",
   loop = true,
   delay = 9350,
   start = -70,
   end = 860,
   time = 4890
}

animation.add( SpriteAnimation( buster2, buster2_config ) );
animation.add( PropertyAnimation( buster2, busterm2_config ) );
//Here runs the third animation, it has to go in loop, but because of the delay animation appears through 9350 milliseconds instead of 450 milliseconds.

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: moving animation
« Reply #8 on: August 27, 2015, 09:20:27 AM »
Can you provide the spritesheet? I've tried to duplicate it but it just makes it a bit confusing to understand what you are trying to accomplish..

empardopo

  • Full Member
  • ***
  • Posts: 49
    • View Profile
Re: moving animation
« Reply #9 on: March 18, 2016, 09:11:01 AM »
Sorry, for recovering this old post but I don't understand how can I use a spritesheet? I think it's not possible to use animated gif and the only option is to use a spritesheet.

Please, anyone can explain to me how can I use it?

Thanks very much in advance.