#πŸ”’ How do I play this series of images on pygame as an animation?

27 messages Β· Page 1 of 1 (latest)

bright hull
#
if self.value >= len(self.blast_images):
                        self.value = 0

                    cur_image = self.blast_images[self.value]
                    self.screen.blit(cur_image, self.pos)
                    self.value += 1

I have a list called blast_images with all the 11 animation images i want loaded, but when i call this, the animation doesnt seem to work properly(i have set value to be 0 on the global function)

Thanks in advance

fading cargoBOT
#

@bright hull

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

lapis plinth
#

Can you give the entire code? Your code seems to be right, maybe there is something that doesn't make it right. Also what do you mean by animation not working?

bright hull
#

Okay

#

The animation plays one frame every time I click the mouse

#

Oh I should have mentuoned this, i am calling the MOUSE event function and playing this animation under that

#

!paste

fading cargoBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

bright hull
lapis plinth
#

Ah I see, maybe there is something wrong with how you update your character. The mouse event only runs when you have a mouse event, so when the mouse moves, it updates it. I suppose you want your character to run even if the mouse is not moving?

bright hull
#

my charater runs based on wasd controls, i am trying to have an attack based on mouse clicks, not movements, so far everything but the animation seems to work properly

#

the attack is a blast attack and plays this blast animation at the point of clicking, which this does do properly, however the animation comes only for a single frame? I think thats whats happening, everytime i click, only one frame comes, but in the order "right" order

lapis plinth
#

Ah ok I get it now

#

So my method to do it is to have an update method to handle all of the character interactions

#

then I would have another method in the keyboard/mouse events function to run the function, the function just changes the state of my character.

#

So when it updates the character, the frames it is going to use has already been changed because of the function that changes its state

#

The problem with your approach is that when you attack, it is waiting for your keyboard/mouse event

#

So it will not run the frames simultaneously

bright hull
#

Oh

#

Okay. Let me try that and get back to you

lapis plinth
bright hull
#

Okay. Thank you so much!

lapis plinth
#

@bright hull close this forum

#

do !close

bright hull
#

!close

fading cargoBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.