我正在使用Pygame製作2D遊戲。
我想在我正在處理的遊戲中添加粒子效果。我想做一些事情,如產卵煙,火,血等。我很好奇,有沒有一種簡單的方法來做到這一點?我甚至不知道從哪裏開始。
我只需要一個基礎案例,我可以擴展..
請幫助。pygame - 粒子效果
3
A
回答
3
您可能想要創建一個由上升的rects組成的類,並且每次更新煙霧時都會隨機地向右或向左移動。然後每當你想要的時候就製作一大堆。我會盡量在下面做一個示例代碼,但我不能保證它會起作用。您可以爲其他粒子效果製作類似的類。
class classsmoke(pygame.Rect):
'classsmoke(location)'
def __init__(self, location):
self.width=1
self.height=1
self.center=location
def update(self):
self.centery-=3#You might want to increase or decrease this
self.centerx+=random.randint(-2, 2)#You might want to raise or lower this as well
#use this to create smoke
smoke=[]
for i in range(20):
smoke.append(classsmoke(insert location here))
#put this somewhere within your game loop
for i in smoke:
i.update()
if i.centery<0:
smoke.remove(i)
else:
pygame.draw.rect(screen, GREY, i)
另一種辦法是使課堂只是一個元組,像這樣:
class classsmoke():
'classsmoke(location)'
def __init__(self, location):
self.center=location
def update(self):
self.center[1]-=3
self.center[0]+=random.randint(-2, 2)
#to create smoke
smoke=[]
for i in range(20):
smoke.append(classsmoke(insert location here))
#put inside game loop
for i in smoke:
i.update()
if i.centery<0:
smoke.remove(i)
else:
pygame.draw.rect(screen, GREY, (i.center[0], i.center[1], 1, 1))
或者,爲了避免類完全地:
#to create smoke:
smoke=[]
for i in range(20):
smoke.append(insert location here)
#put within your game loop
for i in smoke:
i[1]-=3
i[0]+=random.randint(-2, 2)
if i[1]<0:
smoke.remove(i)
else:
pygame.draw.rect(screen, GREY, (i[0], i[1], 1, 1))
挑選您的喜好,並做一些事情類似於其他粒子效應。
0
檢查你所說的插入位置在這裏你是什麼意思圖書館的粒子效果PyIgnition
相關問題
- 1. Pygame粒子效應
- 2. 粒子效果libgdx
- 3. HTML5粒子效果
- 4. 使用粒子效果
- 5. 在libgdx中更改粒子效果的粒子圖像java
- 6. 粒子效應?
- 7. Android可編程粒子效果
- 8. 粒子效果在運行時
- 9. 使用粒子的降雪效果
- 10. Android Min3d不支持粒子效果?
- 11. Starling粒子效應
- 12. 粒子效果像chillingo的碰撞效果
- 13. UI中的粒子效應
- 14. 停止粒子效應libgdx
- 15. 爆炸粒子效應
- 16. 顯示相同粒子的粒子效應 - 不隨機化,Monogame
- 17. OpenGL ES - 使用添加劑混合渲染粒子效果(FBO)
- 18. libGDX - 導入到android studio的粒子效果工具
- 19. 如何使用提到的粒子效果?
- 20. 使用粒子引擎的推進器效果
- 21. 如何在Android上創建Raining效果(粒子)?
- 22. 粒子效果[不CCParticleSystemQuad改變其父的位置WRT]
- 23. iOS的 - 如何實現粒子動畫般的效果在iOS
- 24. 爲什麼不在iPhone上使用粒子效果?
- 25. 實時更改XML以更改粒子效果
- 26. 在反應本機中創建粒子效果
- 27. 如何在android cocos2d中使用plist顯示粒子效果?
- 28. 如何在白色背景上顯示Libgdx粒子效果?
- 29. 帶圖標的HTML5帆布粒子效果
- 30. 在CCTouchesMoved中使用Cocos2D粒子效果時FPS降低問題
? – user1758231 2013-02-13 02:18:38
@ user1758231放置在兩個位置的列表中,x和y是這樣的:'[132,45]'帶有x first和y second('[x,y]') – PygameNerd 2013-02-13 19:51:39