- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<分区>
我想知道如何在 pygame 中滚动我的背景图片
我有一个移动的物体 我希望它在该物体移动时滚动这是背景图片的视频video现在我只是 blit 背景图片
def redrawwindow():
window.blit(bg,(0,0))
这是我的完整代码
import pygame
import random
pygame.init()
#this is screem height
window = pygame.display.set_mode((500,500))
#know we put screem name
pygame.display.set_caption("Noobs Flappy Bird Game")
#player class
class bird:
def __init__(self,x,y,height,width,color):
self.x = x
self.y =y
self.bright = [
pygame.image.load("killers50.png"),
pygame.image.load("killers51.png"),
pygame.image.load("killers52.png"),
pygame.image.load("killers53.png"),
]
self.bleft = [
pygame.image.load("ms1.png"),
pygame.image.load("ms2.png"),
pygame.image.load("ms3.png"),
pygame.image.load("ms4.png"),
]
self.bright = [pygame.transform.scale(image,(image.get_width()//15,image.get_height()//15)) for image in self.bright]
self.bleft = [pygame.transform.scale(image,(image.get_width()//15,image.get_height()//15)) for image in self.bleft]
self.height = height
self.width = width
self.isJump = False
self.JumpCount = 10
self.fall = 0
self.speed = 5
self.Walking = 0
self.vel = 5
self.color = color
self.rect = pygame.Rect(x,y,height,width)
self.direction = "down"
# this makes the enemy move right and left
def draw(self):
self.rect.topleft = (self.x,self.y)
if self.Walking + 1 >= 33:
self.Walking = 0
if self.vel > 0: # left
window.blit(self.bright[self.Walking % 3], (self.x,self.y))
self.Walking += 1
else: # right
window.blit(self.bleft[self.Walking % 3], (self.x,self.y))
self.Walking += 1
class platform:
def __init__(self,x,y,height,width,color):
self.x = x
self.y = y
self.height = height
self.width = width
self.color = color
self.pipis = pygame.image.load("pip.png")
self.pipis = pygame.transform.scale(self.pipis,(self.pipis.get_width()//3,self.pipis.get_height()//3))
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
self.rect.topleft=(self.x,self.y)
window.blit(self.pipis,self.rect)
class pip:
def __init__(self,x,y,height,width,color):
self.x = x
self.y = y
self.height = height
self.width = width
self.color = color
self.pipis = pygame.image.load("pipo.png")
self.pipis = pygame.transform.scale(self.pipis,(self.pipis.get_width()//3,self.pipis.get_height()//3))
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
self.rect.topleft=(self.x,self.y)
window.blit(self.pipis,self.rect)
#player and enemy
white = (255,255,255)
bird1 = bird(0,400,50,50,white)
red = (255,48,48)
platform1 = platform(600,300,150,50,white)
platform2 = platform(800,200,150,50,white)
platform3 = platform(1100,300,150,50,white)
platform4 = platform(1300,400,150,50,white)
platform5 = platform(1500,300,150,50,white)
platform6 = platform(1800,200,150,50,white)
# ROUND 2
platform7 = platform(2200,300,150,50,white)
platform8 = platform(2400,200,150,50,white)
platform9 = platform(2600,300,150,50,white)
platform10 = platform(2700,400,150,50,white)
platform11 = platform(2900,300,150,50,white)
platform12 = platform(3200,200,150,50,white)
# rOUND 3
platform13 = platform(3400,300,150,50,white)
platform14 = platform(3600,200,150,50,white)
platform15 = platform(3800,300,150,50,white)
platform16 = platform(4000,400,150,50,white)
platform17 = platform(4200,300,150,50,white)
platform18 = platform(4400,200,150,50,white)
# ROUND 4
platform19 = platform(600,300,150,50,white)
platform20 = platform(800,200,150,50,white)
platform21 = platform(1100,300,150,50,white)
platform22 = platform(1300,400,150,50,white)
platform23 = platform(1500,300,150,50,white)
platform24 = platform(1800,200,150,50,white)
platforms = [platform1,platform2,platform3,platform4,platform5,platform6,platform7,platform8,platform9,platform10,platform11,platform12,platform13,platform14,platform15,platform16,platform17,platform18,platform19,platform20,platform21,platform22,platform23,platform24]
# sceond pip
pip1 = pip(600,-160,150,50,white)
pip2 = pip(800,-270,150,50,white)
pip3 = pip(1100,-170,150,50,white)
pip4 = pip(1300,-170,150,50,white)
pip5 = pip(1500,-170,150,50,white)
pip6 = pip(1800,-270,150,50,white)
# ROUND 2
pip7 = pip(2200,-160,150,50,white)
pip8 = pip(2400,-270,150,50,white)
pip9 = pip(2600,-170,150,50,white)
pip10 = pip(2700,-170,150,50,white)
pip11 = pip(2900,-170,150,50,white)
pip12 = pip(3200,-270,150,50,white)
# ROUND 3
# rOUND 3
pip13 = pip(3400,-160,150,50,white)
pip14 = pip(3600,-270,150,50,white)
pip15 = pip(3800,-170,150,50,white)
pip16 = pip(4000,-170,150,50,white)
pip17 = pip(4200,-170,150,50,white)
pip18 = pip(4400,-270,150,50,white)
# ROUND 4
pip19 = pip(600,-160,150,50,white)
pip20 = pip(800,-270,150,50,white)
pip21 = pip(1100,-170,150,50,white)
pip22 = pip(1300,-170,150,50,white)
pip23 = pip(1500,-170,150,50,white)
pip24 = pip(1800,-270,150,50,white)
pips = [pip1,pip2,pip3,pip4,pip5,pip6,pip7,pip8,pip9,pip10,pip11,pip12,pip13,pip14,pip15,pip16,pip17,pip18,pip19,pip20,pip21,pip22,pip23,pip24]#window
class orb:
def __init__(self,x,y,height,width,color):
self.x = x
self.y = y
self.height = height
self.width = width
self.color = color
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
self.rect.topleft = (self.x,self.y)
class particleAndPoint:
def __init__(self,x,y,height,width,color):
self.x = x
self.y =y
self.height = height
self.width = width
self.color = color
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
self.rect.topleft = (self.x,self.y)
particleAndPoints = []
# this is the orbs
orb1 = orb(1500,100,50,550,white)
orb2 = orb(2600,100,50,550,white)
orbes = [orb1,orb2]
platformGroup = pygame.sprite.Group
platformList = []
level = [" ",
" ",
" ",
" ",
" p p p p p p p p p p p p p p p p p p",
" ",
" ",
" ",
" ",
" ",
" ",]
for iy, row in enumerate(level):
for ix, col in enumerate(row):
if col == "p":
new_platforms = particleAndPoint(ix*10, iy*0, 10,1010,(255,255,255))
particleAndPoints.append(new_platforms)
# the score text
font = pygame.font.Font('Candarai.ttf',60)
score = 0
loltext = font.render("" + str(score), True, (255,255,255))
lolrect = loltext.get_rect()
lolrect.center = ((130,60))
# wow sound anime
wowsound = pygame.mixer.Sound("wows.wav")
explodesound = pygame.mixer.Sound("partexplode.wav")
class particle:
def __init__(self,x,y):
self.x = x
self.y = y
self.x_vel = random.randrange(-10,13)*1
self.y_vel = random.randrange(-10,-1)*1
self.lifetime = 0
def draw(self,window):
self.lifetime += 1
if self.lifetime <30:
self.x -= self.x_vel
self.y -= self.y_vel
pygame.draw.rect(window,(232,255,24),(self.x,self.y, 16,16))
# draw the screen things
def redrawwindow():
bg = pygame.image.load("bgs.png")
window.blit(bg,(0,0))
#player draw
bird1.draw()
for platform in platforms:
platform.draw()
for pip in pips:
pip.draw()
for particleAndPoint in particleAndPoints:
particleAndPoint.draw()
window.blit(loltext,lolrect)
for orb in orbes:
orb.draw()
for particle in particles:
particle.draw(window)
fps = (30)
clock = pygame.time.Clock()
particles = []
run = True
while run:
clock.tick(fps)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
# if player collides with the obsticles add 1 to the player and delete the obstacle
for one in range(len(particleAndPoints)-1,-1,-1):
if bird1.rect.colliderect(particleAndPoints[one].rect):
score += 1
bird1.speed += 0.2
del particleAndPoints[one]
explodesound.play()
loltext = font.render("" + str(score), True, (255,255,255))
lolrect.center = ((130,60))
for x in range(60):
x, y = bird1.rect.center
particles.append( particle( x, y ) )
# if ball collides with player1 show the particles
# if ball collides with player1 show the particles
if bird1.rect.colliderect( orb1.rect ):
for x in range(60):
wowsound.play()
explodesound.play()
x, y = bird1.rect.center
particles.append( particle( x, y ) )
if bird1.rect.colliderect( orb2.rect ):
for x in range(60):
wowsound.play()
explodesound.play()
x, y = bird1.rect.center
particles.append( particle( x, y ) )
keys = pygame.key.get_pressed()
# bird moving
bird1.x += bird1.speed
if not bird1.isJump:
bird1.y += bird1.speed
bird1.isJump = False
if keys[pygame.K_SPACE]:
bird1.isJump = True
# this part lets you jump on platform
collide = False
for platform in platforms:
if bird1.rect.colliderect(platform.rect):
collide = False
# this makes the player fall down up to
if bird1.rect.bottom >= 500:
collide = True
bird1.isJump = False
bird1.JumpCount = 10
bird1.y = 500 - bird1.height
if collide:
if keys[pygame.K_SPACE]:
bird1.isJump = True
bird1.fall = 0
else:
if bird1.JumpCount > 0:
bird1.y -= (bird1.JumpCount*abs(bird1.JumpCount)) * 0.2
bird1.JumpCount -= 1
else:
bird1.JumpCount = 10
bird1.isJump = False
# this scrolls my screen right
if bird1.x > 300:
bird1.x -= bird1.speed
for platform in platforms:
platform.x -= bird1.speed
for pip in pips:
pip.x -=bird1.speed
for particleAndPoint in particleAndPoints:
particleAndPoint.x -= bird1.speed
for orb in orbes:
orb.x -= bird1.speed
redrawwindow()
pygame.display.update()
pygame.quit()
我希望背景一直向右滚动,因为我的播放器总是向右移动谢谢!
如果附加了 'not-scroll' 类,我希望我的 body 不滚动,否则它应该正常工作。 我已经搜索这个问题两天了,但找不到任何适合我的解决方案。 我想要的是向 body 添加一个 class,并
我发现似乎是 iOS Safari 中的错误(我正在 iOS 8 上进行测试)。当绝对定位的 iFrame 漂浮在一段可滚动内容上方时,滚动 iFrame 也会滚动下面的内容。以下 HTML (ava
我有以下代码来显示一系列投资组合图片,这些图片以 SVG 格式存储在滚动 div 中: 在 Safari 中滚动使用两根手指或鼠标滚轮当光标位于 SVG 之一上时不起作用。 该页
我想用 javascript 做的是: 一旦你向下滚动页面,将#sidebar-box-fixed 的位置从 position: relative; 更改为定位:固定;。改回position:rela
我对 Elasticsearch 的滚动功能有点困惑。在 elasticsearch 中,每当用户在结果集上滚动时,是否可以每次调用搜索 API?来自文档 "search_type" => "scan
我试图做到这一点,以便当我向上或向下滚动页面时,它会运行不同的相应功能。我发现了一个类似的问题here但我已经尝试了他们的答案并且没有运气。 注意:此页面没有正常显示的滚动条。没有地方可以滚动。 bo
(C语言,GTK库) 在我的表单上,我有一个 GtkDrawingArea 小部件,我在上面使用 Cairo 绘制 GdkPixbufs(从文件加载)。我想要完成的是能够在窗口大小保持固定的情况下使用
最近我一直在尝试创建一个拉到(刷新,加载更多)swiftUI ScrollView !!,灵感来自 https://cocoapods.org/pods/SwiftPullToRefresh 我正在努
我正在开发一个应用程序,其中有两个带有可放置区域的列表和一个带有可拖动项目的侧面菜单。 当我滚动屏幕时,项目的位置困惑。 我试图在谷歌上寻找一些东西,最后得到了这个问题:jQuery draggabl
我在 UIWebView 中加载了一个 HTML 表单,而我的 UIWebView 恰好从 View 的中间开始并扩展。我必须锁定此 webView 不滚动并将其放在 ScrollView 之上以允许
如何在每个元素而不是整个元素上应用淡入淡出(与其高度相比)? HTML: CSS: * { padding: 0; margin: 0; box-sizing: border
我想使用带有垂直轴的 PageView 并使用鼠标滚动在页面之间移动,但是当我使用鼠标滚动时页面不滚动...仅页面单击并向上/向下滑动时滚动。 有什么办法吗? 我想保留属性 pageSnapping:
我制作这个程序是为了好玩,但我被卡住了,因为程序在屏幕外运行。如何在不完全更改代码的情况下实现滚动条。 public static void main(String args[]) throws IO
我想使用带有垂直轴的 PageView 并使用鼠标滚动在页面之间移动,但是当我使用鼠标滚动时页面不滚动...仅页面单击并向上/向下滑动时滚动。 有什么办法吗? 我想保留属性 pageSnapping:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
使用 jquery 技术从 css-tricks.com 获得滚动/跟随侧边栏,如果您不知道我在说什么,这里是代码: $(function() { var $sidebar = $
我是 jQuery Mobile 新手。我需要向我的应用程序添加 Facebook 滑动面板功能。 我经历了 sliding menu panel ,它工作正常,但我在菜单面板中的内容超出了窗口大小,
有没有办法在 js 或 jQuery 或任何其他工具中检测 ctrl + 滚动。我正在尝试执行一些动态布局代码,我需要检测不同分辨率下的屏幕宽度,我通过使用 setTimeout() 的计时器实现了这
我有一部分html代码:
我想控制 RichTextBox 滚动,但在控件中找不到任何方法来执行此操作。 这样做的原因是我希望当鼠标光标位于 RichTextBox 控件上时鼠标滚轮滚动有效(它没有事件焦点:鼠标滚轮事件由表单
我是一名优秀的程序员,十分优秀!