[course]08 游戏模块02-1
这部分游戏主要跟图像和滚动相关,是对图像的一个衍生
使用自定义类来创建
和之前的不同,这次使用自定义类来进行创建,通过继承APP来创建。
from game_graphics import *
from tkinter import *
class MyApp(App):
def appStarted(self):
self.counter = 0
def keyPressed(self, event):
self.counter += 1
def redrawAll(self, canvas):
canvas.create_text(self.width/2, self.height/2,
text=f'{self.counter} keypresses', font='Arial 30 bold')
MyApp(width=400, height=400)使用定义的快捷键
绑定模块中自定义的快捷键来进行操作 在game_graphics中的_keyPressedWrapper定义了相应的内容
记录数遍跟踪信息
相关键盘和鼠标的事件 keyPressed、keyReleased 键盘的相应操作 mousePressed、mouseReleased 鼠标的点击和释放 mouseMoved 鼠标移动 mouseDragged 鼠标拖动 sizeChanged 窗口大小变换
控制输入事件
控制输入事件,绑定输入内容
图片控制
输入图片的几种方式
输入图片的几种方式: 1. 直接通过本地图片 2. 通过线上的图片链接 3. 通过跳转图片链接
使用loadImage 来读入图片 使用scaleImage来改变图片的大小
输出图片的大小
图片转换
transpose : Transpose image (flip or rotate in 90 degree steps)
截屏和保存图片
Spritesheets 雪碧图
雪碧图用于游戏中的角色运动。
下载文件 blackbird.jpg
作业: 制作自己的雪碧图人物,可以在网上随便的搜索相应的图片模板
Last updated
Was this helpful?