我想在图像周围绘制红色边框,但不知道如何做。
我尝试填充Hero精灵的图像并将 colorkey 设置为 red self.image.set_colorkey(red),但这会使图像不可见。
在图像上绘制一个红色矩形,将其完全填充:pygame.draw.rect(self.image, red, [0, 0, width, height])。
我只想要一个红色边框,以帮助将来进行碰撞检测。
main.py中的代码:
import pygame
from pygame import *
import sprites
from sprites import *
pygame.init()
width = 640
height = 480
color = (255, 255, 255) #white
x = 0
y = 0
speed = 3
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Mushroom")
icon = pygame.image.load('icon.bmp')
pygame.display.set_icon(icon)
sprites_list = pygame.sprite.Group()
hero = Hero('mushroom.png', 48, 48)
hero.rect.x = 200;
hero.rect.y = 300;
sprites_list.add(hero)
running = …Run Code Online (Sandbox Code Playgroud)