![](/img/trans.png)
[英]Python:Pygame: How to animate a ball to move in a sin() like pattern?
[英]How to animate arcs in python (pygame zero)
我如何通过使这些弧向上移动来简单地为这些弧设置动画?
import random
import pygame
import math
WIDTH = 700
HEIGHT = 500
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
BROWN = (101, 67, 33)
YELLOW = (255, 255, 0)
PI = math.pi
def draw():
screen.fill(BLUE)
chimney_smoke(400, 90, 50, 100)
我不确定要在更新功能中添加什么:
def update():
def chimney_smoke(x, y, w, h):
pygame.draw.arc(screen.surface, BLACK, [x, y, w ,h], PI/2, PI, 2)
pygame.draw.arc(screen.surface, BLACK, [x, y, w, h], 0, PI/2, 2)
pygame.draw.arc(screen.surface, BLACK, [x, y, w, h], 3*PI/2, 2*PI, 2)
pygame.draw.arc(screen.surface, BLACK, [x, y, w, h], PI, 3*PI/2, 2)
我做了很多尝试,但似乎无法做到。 这是上课的,我被困住了。 任何帮助将不胜感激!
您要做的是用一个变量替换硬编码的90
,您可以在每次PyGame Zero调用update
函数时进行update
。 像这样:
smoke_y = 90
def update():
global smoke_y
smoke_y -= 1
def draw():
screen.fill(BLUE)
chimney_smoke(400, y, 50, 100)
当然,您可能不希望以每帧1像素的精确速度移动,并且可能想为击中屏幕边缘时发生的情况添加一些逻辑,但这足以使您前进。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.