Pyglet 游戏制作跟随鼠标移动和旋转的精灵

30 篇文章 7 订阅
23 篇文章 1 订阅
import pyglet
from datetime import datetime

WIDTH = 960
HEIGHT = 720
window = pyglet.window.Window(WIDTH,HEIGHT)

background_pattern= pyglet.image.SolidColorImagePattern(color=(255,255,255,255))
background_image = background_pattern.create_image(WIDTH,HEIGHT)

pattern = pyglet.image.SolidColorImagePattern(color=(200,200,130,150))
image = pattern.create_image(150,150)
image.anchor_x = image.width//2
image.anchor_y = image.height//2
ball = pyglet.sprite.Sprite(image, x=100, y=200)
ball.opacity= 200

@window.event
def on_draw():
    window.clear()
    background_image.blit(0,0)
    image.blit(0,0)
    ball.draw()

@window.event
def on_mouse_release(x,y,button,modifier):
    print(x,y,button,modifier)

@window.event
def on_mouse_motion(x,y,dx,dy):
    ball.x=x
    ball.y=y

def callback(dt):
    #print(f"{dt} seconds since last callback")
    s = datetime.now().second
    ball.rotation += 1

pyglet.clock.schedule_interval(callback,1/60)

pyglet.app.run()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值