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

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.

Related

Scratch walking animation broken

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?

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

How do I fix loop time in unity even though it is enabled?

When i add animation to animator in unity 2020.1.3f and i want it to be in infinite loop it pauses after one cycle knowing Loop Time is enabled
There is a loop function on the animation clip called loop. If you want to loop through your clip over and over, the enable it.
I don't have enough rep to post a picture yet, but here is a image of what it looks like https://www.google.com/search?q=animation+loop+feature+unity&rlz=1C1CHBF_enCA845CA845&sxsrf=ALeKk008pakwg2CfVPkD2wC4hNGmselSxg:1599702152566&tbm=isch&source=iu&ictx=1&fir=QMJ5GQP1EIIrrM%252CGBN5feXfV4TSNM%252C_&vet=1&usg=AI4_-kSEHfRYMQzMoCPlbk1_12JFGtkvAQ&sa=X&ved=2ahUKEwjZ3LL0ut3rAhUSqZ4KHfYlDs4Q9QF6BAgMEAM#imgrc=QMJ5GQP1EIIrrM
The problem might be after Enabling Looptime to not have clicked on apply Button.

Creating a pause menu in Xcode SpriteKit

I have been developing by game for some time now and I am now trying to code in a pause menu. I have been looking through forums and videos but i still do not understand how to implement in a pause menu. I have a little pause button in the top left corner which i want to click to pause. Then it to overlay a menu, such as changing the z position of items so they are now visible. And then there be buttons such as resume and main menu which respectively do what they are called. I am still quite new to coding so any help would be appreciated. I am working with falling objects and a moving player so if i need to freeze them all, then unfreeze once resumed that might be a solution I am not sure. Thanks :D
I've tried various ways to do this, but not found a satisfactory method that works for any app/game. A lot of it will depend on how your game works. As a starting point, you probably need to look at someway of pausing the SKScene - this should halt a lot of the animation (but you may have to do extra work).
You could add some kind of blur effect or overlay and then add an unpause button and then pause the scene. Touches will still be detected when paused, but you won't have any animation or updates happening after the pause. The following code should work to pause the scene.
let pauseAction = SKAction.run {
self.isPaused = true
debugPrint("Paused")
}
self.run(pauseAction)
The reason to pause the scene in an action is that any addChild calls won't be processed if you set isPaused directly. actuallyPaused is just a bool variable to keep track of wether the scene should be paused or not (if the parent view is un-paused, the scene would also be un-paused). Btw, You do not need to use an action to set isPaused to false.
You probably also should look at implementing observers for
NSNotification.Name.UIApplicationWillResignActive
NSNotification.Name.UIApplicationDidEnterBackground
NSNotification.Name.UIApplicationWillEnterForeground
as you will also need to know when your game has been sent to background either via control center or the home button.

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

Resources