В этом коде, когда происходит elif event.button == 4: # Прокрутка вверх, я хочу, чтобы анимация Smoke2foot воспроизводилась вместе с 2footkick, не удаляя эту анимацию и воспроизводя ее отдельно. Как мне это сделать?
import pygame
import glob
import os
# Initialize Pygame
pygame.init()
# Set the screen dimensions
screen_width = 1920
screen_height = 1080
screen = pygame.display.set_mode((screen_width, screen_height))
# Define a function to load frames from a folder
def load_frames(folder):
frame_paths = glob.glob(os.path.join(folder, '*.png'))
frames = [pygame.image.load(frame_path) for frame_path in sorted(frame_paths)]
return frames
# Define a function to initialize animations
def initialize_animations():
animations = {
"idle": (load_frames('C:\\Users\\t\\Desktop\\a\\idle-t'), False),
"kick": (load_frames('C:\\Users\\t\\Desktop\\a\\kick-t'), False),
"uppercut": (load_frames('C:\\Users\\t\\Desktop\\a\\uppercut-t'), False),
"jumpkick": (load_frames('C:\\Users\\t\\Desktop\\a\\jumpkick-t'), False),
"2footkick": (load_frames('C:\\Users\\t\\Desktop\\a\\2footkick-t'), False),
"smoke2foot": (load_frames('C:\\Users\\t\\Desktop\\a\\smoke-t'), False)
}
return animations
# Set the frame rate
clock = pygame.time.Clock()
fps = 24
# Main loop
running = True
current_animation = "idle"
frame_index = 0
animations = initialize_animations()
animation_playing = False # Flag to track if an animation is currently playing
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif not animation_playing: # Process key events only if no animation is playing
if event.type == pygame.MOUSEBUTTONDOWN:
# Reset all animation flags to False
for anim in animations:
animations[anim] = (animations[anim][0], False)
if event.button == 1: # Left mouse button
current_animation = "kick"
elif event.button == 3: # Right mouse button
current_animation = "uppercut"
elif event.button == 2: # Middle mouse button
current_animation = "jumpkick"
elif event.button == 4: # Scroll up
current_animation = "2footkick"
frame_index = 0
# Set the flag of the current animation to True
animations[current_animation] = (animations[current_animation][0], True)
animation_playing = True # Set the flag to indicate an animation is playing
# Fill the screen with a background color
screen.fill((225, 255, 255))
# Display the current frame
screen.blit(animations[current_animation][0][frame_index], (0, 0))
pygame.display.update()
# Increment the frame counter
frame_index = (frame_index + 1) % len(animations[current_animation][0])
# Check if animation has finished
if frame_index == len(animations[current_animation][0]) - 1:
# Reset the flag of the current animation to False
animations[current_animation] = (animations[current_animation][0], False)
# Switch to idle animation
current_animation = "idle"
animation_playing = False # Reset the flag since animation is finished
# Delay to achieve the desired frame rate
clock.tick(fps)
# Quit Pygame
pygame.quit()
Я помню, что мне удалось этого добиться, но это замедлило игру, и у меня больше нет этого кода.
В этом коде, когда происходит elif event.button == 4: # Прокрутка вверх, я хочу, чтобы анимация Smoke2foot воспроизводилась вместе с 2footkick, не удаляя эту анимацию и воспроизводя ее отдельно. Как мне это сделать? [code]import pygame import glob import os
# Initialize Pygame pygame.init()
# Set the screen dimensions screen_width = 1920 screen_height = 1080 screen = pygame.display.set_mode((screen_width, screen_height))
# Define a function to load frames from a folder def load_frames(folder): frame_paths = glob.glob(os.path.join(folder, '*.png')) frames = [pygame.image.load(frame_path) for frame_path in sorted(frame_paths)] return frames
# Set the frame rate clock = pygame.time.Clock() fps = 24
# Main loop running = True current_animation = "idle" frame_index = 0 animations = initialize_animations() animation_playing = False # Flag to track if an animation is currently playing
while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif not animation_playing: # Process key events only if no animation is playing if event.type == pygame.MOUSEBUTTONDOWN: # Reset all animation flags to False for anim in animations: animations[anim] = (animations[anim][0], False) if event.button == 1: # Left mouse button current_animation = "kick" elif event.button == 3: # Right mouse button current_animation = "uppercut" elif event.button == 2: # Middle mouse button current_animation = "jumpkick" elif event.button == 4: # Scroll up current_animation = "2footkick" frame_index = 0 # Set the flag of the current animation to True animations[current_animation] = (animations[current_animation][0], True) animation_playing = True # Set the flag to indicate an animation is playing
# Fill the screen with a background color screen.fill((225, 255, 255))
# Display the current frame screen.blit(animations[current_animation][0][frame_index], (0, 0)) pygame.display.update()
# Check if animation has finished if frame_index == len(animations[current_animation][0]) - 1: # Reset the flag of the current animation to False animations[current_animation] = (animations[current_animation][0], False) # Switch to idle animation current_animation = "idle" animation_playing = False # Reset the flag since animation is finished
# Delay to achieve the desired frame rate clock.tick(fps)
# Quit Pygame pygame.quit() [/code] Я помню, что мне удалось этого добиться, но это замедлило игру, и у меня больше нет этого кода.
У меня есть CSS-анимация, которая повторяется либо бесконечно, либо только определенное время. но я бы хотел воспроизводить это примерно 2 раза каждые 5 секунд.
Вот мой код:
Я работаю над небольшим проектом в pygame (издание сообщества), реализующим 2D-игру о военных кораблях с видом сверху.
Я хочу реализовать дым из трубы, исходящий от каждого корабля, эффективно создавая след позади каждого корабля. Поскольку...
Я работаю над небольшим проектом в pygame (издание сообщества), реализующим 2D-игру о военных кораблях с видом сверху.
Я хочу реализовать дым из трубы, исходящий от каждого корабля, эффективно создавая след позади каждого корабля. Поскольку...
Я хочу создать аналогичный эффект анимации удара кисти в узле JS, как я могу его реализовать? Мне не нужны различные цвета в этом простой простой анимации с цветной кистью.
Я хочу создать аналогичный эффект анимации удара кисти в узле JS, как я могу его реализовать? Мне не нужны различные цвета в этом простой простой анимации с цветной кистью.