Scratch walking animation broken - animation

What it's supposed to do:
I'm making a game on Scratch in which the character has a walking animation. The walking animation is supposed to switch their costume to a walking stance, wait 0.5 seconds then go to an idle stance, wait 0.5 seconds then go to a walking stance, and repeat that until they let go of the button.
The image below is an image of the animation blocks put together that play the animation when walking left.
What it does do and suspected reason for the bug:
It worked perfectly until I added a block function for the same character, when suddenly the animations broke for that character and the other one (who also has a walking animation with the same code). The second image below is an image of the blocking code.
After adding the block function, instead of waiting 0.5 seconds in between costume switches, it seems to switch to the walking stance and then immediately switch to the idle stance instead of waiting.
The image below is showing the blocking blocks and the movement it controls. While they are blocking it isn't supposed to be able to move. That part works fine but I included it in case it has something else to do with my problem.
What I have tried:
I tried running the peice of code shown individually (seperate from the other animation parts) but the bug still occurs and the animation doesn't wait 0.5 seconds. I also tried changing the other character's animation so that it wouldn't activate when the animation broadcast was sent but it still bugged, which means:
The problem isn't because it runs with another sprite too. (Because if it was it would have fixed when I deactivated the other animation).
The problem also isn't because it's connected with the right side walking and idle animations (Because if it was it would have fixed when I ran it alone).
Link to shared game:
https://scratch.mit.edu/projects/690164519/

I think the issue is with this part of your code. The forever loop is always trying to set the costume to the idle state when BlockStatus is NonBlocking.
This is then fighting with the loop that is trying to manage the swap between the idle and the walking costumes.
You may need to set a flag when the key is pressed and move the walking animation into this loop?

Related

How to get a death animation for my character in ActionScript 3 (Adobe Animate)

So basically I have two questions. I am also copying off this video from 2014: https://www.youtube.com/watch?v=w8JgpEjm8i8&t=2792s
Question 1
At the end of the video above the guys computer completely crashed and he wasnt able to show the end of how to setup a death animation for my player (link). So currently I have setup a movie clip of the death animation - just the playing spinning around - and put it in another movie clip called 'All Sprites' in which I have my other movie clips such as the different walking directions. So I have placed it in there, labelled it with "Link Death Frame". I then went back to the main script and added code so that once my player dies, the animation will play. Such as:
~
if(linkHealthBarMC.scaleX <= 0.01)
{
linkAlive = false;
}
trace(linkAlive);
if(linkAlive == false)
{
linkMC.gotoAndStop("Link Death Frame");
}
~
However, the issue comes in which the animation doesnt actually play, it just goes straight to the first frame and doesnt play. I have tested it and I know for sure that it gets stuck on the first frame and that something must be wrong with the animation as I tested it with another animation and it worked fine (once I met the requirements for the animation to play). So does anyone have any idea how I can fix this issue so that my character can play a death animation?
Question 2
How do I stop time? Like just completely freeze everything after my character is dead? Because at the moment I am just going to the first frame of the death animation and can still move and attack.
I'd assume this is on an EnterFrame loop. Then you would have two possible causes for this:
1.) You're loop is constantly checking if the 'linkAlive' if statement is false (which it is) and setting your Animation to the first frame. You can check this method by putting a Trace statement in your if statement and if the output window overflows, then that's your culprit.
2.) What you want is gotoAndPlay(-insert label here-)
Tho it is outside the scope of the question you have, I create a variable~Switch State machine to control states for me:
1.) Current State as a number (int, number, or uint)
2.) function with a switch statement (Switch is kind of a fancy if Statement)
3.) inside the cases are instructions
switch(current_state){
case 1:
linkMC.gotoAndPlay('death animation');
break;
}
if (current_state != 1){
-put movement code here-
}
This is close to what I use for my game. Just checking states or you can have a variable like the one above that explicitly checks for the death state and remove the ability to move. If you use a mouse (and I assume event listener) then you can remove the event listener for the mouse. If you use a solution like keyboard inputs then an if statement would be more what you are looking for.

In godot, I want to run an animation tied to an animated sprite one time only

I can't do this at the moment because the system I'm using to detect input runs once every frame, meaning that the animation will continue looping every frame. I tried making it so that the animation would only run when the spacebar is being held down, but it just made it start and then pause when the spacebar is unheld, which is not what I'm going for. Is there any way to make it such that when a certain key is pressed, an animated sprite runs its animation once and then stops? Thanks for your help.
Telling the animation that currently playing to play is fine. I believe the issue is with stopping it. For that I suggest having an "idle" animation. So that instead of stopping the current animation, you can tell it to play the "idle" animation (which could be as simple as one frame).
Now, if you don't want to tell the animation to play every frame, use Input.is_action_just_pressed and Input.is_action_just_released, and that will tell you when to start and stop the animation.
And if you prefer to only run code if there is some input event, you can use _input. See also _process vs. _physics_process vs. *_input and Using InputEvent.
Addendum: I paid little attention to "only one time". In the SpriteFrames editor, where you define the animations, there is a toggle in the bottom where you can tell Godot if you want the animation to loop or not.
In the odd case where you might want to change that from code, it would be something like this $AnimatedSprite.frames.set_animation_loop("animation_name", false) to make the animation not loop (you still need to tell Godot to play it, this changes how it plays from there on). Or you can replace false with true to make it loop again.

Controlling different types of sprite animation in Scratch

I'm building a platformer in Scratch 3.0 where a player can run, jump, crouch, and has a few basic attacks. Right now I have animation set up under a custom block like this example for the idle:
switch to costume (1+((floor of (timer*10)) mod 6)
This loops the costume around with the game timer as long as the animation conditions are met; and works fine for idle, run, and jump—however I'm not sure how to implement something like a crouch (three costumes/frames), which always needs to start on a specific costume, play through two additional costumes, then stop until the down key is released. Similarly, I need attack animations to always start on a specific costume, and play the entire animation through sequentially.
I hope that makes sense. Any advice for a good way to implement this, or additional parameters I need to include to make that work?
So let's say that you want to start walking. you can set the costume to the first frame of that, and then go to the next costume a few times (maybe also add in a wait block depending on the fps of your animation) and then if the costume goes past your animation frames, just set the costume back. Here is an image, but you can just ignore the custom block, and pretend that the if else is in the forever. i just like using custom blocks because of the run without screen refresh. (The mage of the code needed)
sorry if this is confusing, i'm just bad at writing
How about using a state variable that is a number?
Example, lets create a block called crouch and apply a counter so that if the down arrow key is pressed, you set counter to 1 and then to 2 for the crouching sprites. Then you use a wait until <=> block to wait until crouching is gone.
Now you do the same for the others

Animation is not looping

Im using Unity 5.3.4 and made some animation clips in the native animation panel of Unity, using keyframes.
In the Animator, I related those clips with transitions. I set "idle" as my entry clip and y checked "Loop Time" on it's properties. Nevertheless, when I hit play, the animation is not looping. It just play once and goes to the "jump" clip. Then it keeps rotation between "jump" and "hit".
Here's how things are done:
You should control the animation behaviour with conditions for example if you want it to loop till something happened you should first add a parameter to use it for checking if something happened then use it in conditions tab for example you can make an bool parameter then use it in condition so when it was checked you will move to the next state till then it will just loop in the current state , if you put no condition so there is nothing stopping the state machine from going to the next state
animation transitions
Another tutorial

SFML - Frame independent movement + dragging window

I am trying to implement frame independent movement in SFML, but am having trouble getting it to work. When I had this problem earlier with SDL, I found somewhere that Windows pauses the main thread of an application whenever it is moved (by dragging the title-bar). The problem comes because when the window is being dragged, the clock updates but the movement is not drawn until I let go of the window. When I move the window, the window is no longer being drawn to, but the time is still increasing. Thus, when I let go of the window, the units immediately jump to where they would be if the window had not been dragged.
I tried thinking of a solution, and since Windows only pauses the main thread, I considered just running the entire game in a separate thread, and launching it in main() but that does not appear to work as the same result occurs. I also thought about the extremely low FPS's I get as a result, but I would have no way of being able to differentiate between someone dragging the window and if their game is just naturally running slowly... There has to be a way to either prevent windows from pausing the main thread, or doing something that prevents this issue, but I haven't found any sort of solution on the internet...
Here is a link to a zip file which demonstrates the problem. Both Demo0 and Demo1 are the same, except Demo1 uses a second thread to run the program, yet the same effect occurs. Just run both and watch as the delta value is output to command line. Then drag the window and move it to some other part of the screen. When you let go, you should see a very large delta value and the circle should jump ahead depending on how long you had the window suspended. The source code is all there (in the "src" folder), so I hope people can understand the exact problem: http://www.sendspace.com/file/4er8f4
I see two solutions to the problem:
You can try to see if the sf::Events LostFocus or Resized picks up a window drag, and if they do, simply pause the clock on the game. More information can be found here: http://www.sfml-dev.org/tutorials/2.0/window-events.php
However, if that doesn't work, I would simply add an upper-cap on your delta. Meaning, if the game goes above a certain threshold of delta (1/60 or 1/30), you set delta to a lower value. In your situation though, this cap could probably be really big, like 1/15.
if(delta > 1/15.0f)
delta = 1/15.0f;
Chances are you don't expect your game to be playable at 15fps anyways, and if the user drags the window while moving, the worst you'll have to deal with is a 15fps delta on resume.

Resources