python arcade库教程(2)

本文继续探讨Python的arcade库,详细解析Window类中的方法,包括鼠标移动、拖动、滚动以及键盘按键的事件处理。通过示例程序展示了如何监听并响应这些事件,同时介绍了ASCII码在事件处理中的作用。
摘要由CSDN通过智能技术生成

上次说了窗口的创建和框架创建的区别、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
Learn and use Python and PyGame to design and build cool arcade games. In Program Arcade Games: With Python and PyGame, Second Edition, Dr. Paul Vincent Craven teaches you how to create fun and simple quiz games; integrate and start using graphics; animate graphics; integrate and use game controllers; add sound and bit-mapped graphics; and build grid-based games. After reading and using this book, you'll be able to learn to program and build simple arcade game applications using one of today's most popular programming languages, Python. You can even deploy onto Steam and other Linux-based game systems as well as Android, one of today's most popular mobile and tablet platforms. You'll learn: How to create quiz games How to integrate and start using graphics How to animate graphics How to integrate and use game controllers How to add sound and bit-mapped graphics How to build grid-based games Audience This book assumes no prior programming knowledge. Table of Contents Chapter 1: Before Getting Started… Chapter 2: Create a Custom Calculator Chapter 3: What Is a Computer Language? Chapter 4: Quiz Games and If Statements Chapter 5: Guessing Games with Random Numbers and Loops Chapter 6: Introduction to Graphics Chapter 7: Back to Looping Chapter 8: Introduction to Lists Chapter 9: Introduction to Animation Chapter 10: Functions Chapter 11: Controllers and Graphics Chapter 12: Bitmapped Graphics and Sound Chapter 13: Introduction to Classes Chapter 14: Introduction to Sprites Chapter 15: Libraries and Modules Chapter 16: Searching Chapter 17: Array-Backed Grids Chapter 18: Sorting Chapter 19: Exceptions Chapter 20: Recursion Chapter 21: Formatting Chapter 22: Exercises
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值