我想让我的精灵像滑冰一样滑动。所以如果他在地面上,那么他可以正常行走,但是当他接触冰块时,他会滑动,直到阻止他。 有谁知道如何做到这一点? 由于滑动精灵
Q
滑动精灵
1
A
回答
1
操纵像“Sprite Movement Towards a Target”示例的摩擦系数(以下修改):
class Sprite(pygame.sprite.Sprite):
ICE = 0.01
LAND = 1.
def __init__(self):
# ...
self.normal_friction = .95 # friction while accelerating
self.slowing_friction = .8 # friction while slowing down
def update(self):
# ...
if self.dir: # if there is a direction to move
if self.in_ice_region():
surface_coefficient = Sprite.ICE
else:
surface_coefficient = Sprite.LAND
if self.distance_check(self.dist): # if we need to slow down
self.speedX += (self.dir[0] * (self.speed/2)) # reduced speed
self.speedY += (self.dir[1] * (self.speed/2))
self.speedX *= surface_coefficient * self.slowing_friction # increased friction
self.speedY *= surface_coefficient * self.slowing_friction
else: # if we need to go normal speed
self.speedX += (self.dir[0] * self.speed) # calculate speed from direction to move and speed constant
self.speedY += (self.dir[1] * self.speed)
self.speedX *= surface_coefficient * self.normal_friction # apply friction
self.speedY *= surface_coefficient * self.normal_friction
self.trueX += self.speedX # store true x decimal values
self.trueY += self.speedY
self.rect.center = (round(self.trueX),round(self.trueY)) # apply values to sprite.center
+0
谢谢 这个工程! – bluesplay106
+0
如果您对答案满意,请随时接受。 –
+0
等待,实际上我希望这个人滑动(更像滑冰),直到它碰到一个物体。这段代码就像一个快速幻灯片。对不起,我没有正确看待它。 – bluesplay106
相关问题
- 1. 精灵的不平滑运动
- 2. 从头开始平滑精灵运动
- 3. 拖动精灵
- 4. 精灵动画
- 5. 动态精灵as3
- 6. Css,精灵动画
- 7. jquery动画精灵
- 8. 精灵动画片
- 9. cocos2d动画精灵
- 10. cocos2d动画精灵?
- 11. 自动移动一个精灵来捕捉另一个精灵
- 12. 的Flash ActionScript 3个的平滑移动大精灵
- 13. 平滑和快速的精灵动画(CSS)
- 14. 如何让精灵从精灵表变成另一个精灵?
- 15. 手写体精灵动画
- 16. 带动画精灵的Isuee
- 17. pygame动画精灵表
- 18. 游戏精灵动画
- 19. Swift如何移动精灵?
- 20. 移动精灵直线
- 21. CSS3 - 动画精灵网格
- 22. 动画pygame的精灵
- 23. 对精灵的CCWave动作
- 24. 定时移动精灵
- 25. 用TouchMoved拖动精灵
- 26. 向点动画精灵
- 27. 触摸后动画精灵?
- 28. 行动中产卵精灵
- 29. 如何动画精灵?
- 30. cocos2d 0.8版精灵动画
确保使用的[摩擦系数]低值(http://en.wikipedia.org/wiki/Friction#Coefficient_of_friction)。或者至少低于“正常行走”的价值。 –
我真的没有冰的摩擦系数 我应该。我的意思是没有一种方法可以让精灵滑下来。我的意思是我没有写任何复杂的东西。如果精灵在地面上,它会走路,当它不在时,它会滑动。我正在做一个期限项目,所以我要去简单大声笑 – bluesplay106