上次说了窗口的创建和框架创建的区别、on_draw方法、on_update方法和鼠标按下松开时调用的on_mouse_release,on_mouse_press。
本篇文章就再次讲解arcade库Window类里的方法。
对了,有一个事情上篇文章忘说了,在把窗口实例化的时候,可以填3个属性,分别是此窗口的宽度(x值)、长度(y值)和标题,窗口默认大小是800*600,默认的标题是‘arcade window’,这个上篇文章仔细的小伙伴应该看出来了。
还是一样编写一个程序来看一下
#导入库中大部分功能
from arcade import *
#子类继承父类Window
class MyWindow(Window):
pass
#类的实例化,窗口长度400宽度1000,标题为‘随便一个标题’
w = MyWindow(1000,400,'随便一个标题')
#运行
run()
运行之后出现的窗口明显比之前的窗口更加扁一些,在此窗口中看到的图片大小肯定不是1000*400,但是把图片保存下来之后就可以看到它的大小了,仍然不是1000*400,因为要算上边框。
好了话题有点偏了,我们进入今天的内容
接着上篇的,我们先讲鼠标的方法。
on_mouse_motion(self,x,y,dx,dy)
这个方法相信大家都能看出来,是在鼠标移动时自动按当前程序帧率执行。和其它的鼠标方法一样,前面的x,y是指当前鼠标的坐标,后面的是这个函数的“专属”参数
这个函数的“专属”参数dx和dy分别指鼠标在上一帧在x方向和y方向移动的值
dx>0,鼠标向右运动,dx<0,鼠标向左运动,dy<0,鼠标向下,反之则向上。
编写一个程序来具体的看一下。
#导入库中大部分功能
from arcade import *
#子类继承父类Window
class MyWindow(Window):
#鼠标移动时自动执行
def on_mo