Animating Characters
Author |
Message |
Tasty Pastry
|
Posted: Fri Jun 09, 2017 4:35 pm Post subject: Animating Characters |
|
|
I'm trying to animate some characters in turing, but I don't know how to animate then only when a key is pressed. For example goes up when the up arrow key is pressed, down when the down arrow key is pressed, etc. I also can't figure out how to stop the character from moving after the key has been depressed. I've got the animation part down, but the rest I can't seem to figure out.
\ |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Sat Jun 10, 2017 6:50 am Post subject: RE:Animating Characters |
|
|
Let me see if I understand what you're going for here.
if a key is pressed, then move the character.
Does that sound about right? |
|
|
|
|
|
Tasty Pastry
|
Posted: Sat Jun 10, 2017 11:33 am Post subject: Re: RE:Animating Characters |
|
|
Insectoid @ Sat Jun 10, 2017 6:50 am wrote: Let me see if I understand what you're going for here.
if a key is pressed, then move the character.
Does that sound about right?
Yeah, I did try if statements, but if I put them inside the for loop, the for loop just executes and finishes without key input, and if I put it before the loop, it does work, but it goes through the whole animation sequence instead of stopping after the key is depressed.
Turing: |
% If statement after for
var chars : array char of boolean
var numFrames := Pic.Frames ("Guy Walking-Fight-Dead (3).gif")
% Load the picture
var delayTime : int
var pics : array 1 .. numFrames of int
Pic.FileNewFrames ("Guy Walking-Fight-Dead (3).gif", pics, delayTime )
var sprite: int
sprite: = Sprite.New (pics (1))
Sprite.SetPosition (sprite, 0, 100, false)
Sprite.Show (sprite )
for x : 2 .. maxx by 2
Input.KeyDown (chars )
if chars (KEY_UP_ARROW) then
Sprite.Animate (sprite, pics ((x div 2) mod numFrames + 1), 100, x, false)
delay (60) % Stop sprite from moving too quickly
end if
end for
Sprite.Free (sprite )
% If statement before for
var chars : array char of boolean
var numFrames := Pic.Frames ("Guy Walking-Fight-Dead (3).gif")
% Load the picture
var delayTime : int
var pics : array 1 .. numFrames of int
Pic.FileNewFrames ("Guy Walking-Fight-Dead (3).gif", pics, delayTime )
var sprite: int
sprite: = Sprite.New (pics (1))
Sprite.SetPosition (sprite, 0, 100, false)
Sprite.Show (sprite )
loop
Input.KeyDown (chars )
if chars (KEY_UP_ARROW) then
for x : 2 .. maxx by 2
Sprite.Animate (sprite, pics ((x div 2) mod numFrames + 1), 100, x, false)
delay (60) % Stop sprite from moving too quickly
end for
end if
end loop
Sprite.Free (sprite )
|
|
|
|
|
|
|
Insectoid
|
Posted: Sat Jun 10, 2017 2:18 pm Post subject: RE:Animating Characters |
|
|
Why do you think you need a for loop? |
|
|
|
|
|
Tasty Pastry
|
Posted: Sat Jun 10, 2017 2:54 pm Post subject: Re: RE:Animating Characters |
|
|
Insectoid @ Sat Jun 10, 2017 2:18 pm wrote: Why do you think you need a for loop?
Because in the animation sequence there are different sprites to use, so I needed that so it can go through all the sprites in the walking animation. |
|
|
|
|
|
Insectoid
|
Posted: Sat Jun 10, 2017 5:56 pm Post subject: RE:Animating Characters |
|
|
Are you sure you can't think of another way to do that without a for loop? |
|
|
|
|
|
Tasty Pastry
|
Posted: Sat Jun 10, 2017 6:52 pm Post subject: Re: RE:Animating Characters |
|
|
Insectoid @ Sat Jun 10, 2017 5:56 pm wrote: Are you sure you can't think of another way to do that without a for loop?
I don't think I can do that without a for loop. |
|
|
|
|
|
Insectoid
|
Posted: Sat Jun 10, 2017 7:05 pm Post subject: RE:Animating Characters |
|
|
You only need the for loop so there's a counter for the gif frames, right? Can you think of another way to make a counter? I mean, it is just a number that increments every loop after all. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|