Jump to content
  • Advertisement

Don Polettone

Member
  • Content Count

    9
  • Joined

  • Last visited

Community Reputation

117 Neutral

About Don Polettone

  • Rank
    Newbie
  1. Don Polettone

    pygame - jerky movement in general

    Thanks for the hint mousetail but I've tried that already and it's not really better.   Is there a clock object in python language that is VERY, VERY accurate on windows/mac/unix? What's the best way to program a NES-like game in python 2.x regarding the time step?   Anyone can help?
  2. Don Polettone

    pygame - jerky movement in general

    clock.get_time() returns the number of milliseconds that have passed since the previous call to clock.tick(). So at 60 FPS, this returns a value like 16 or 17 (on my machine).   The pygame docs are sometimes really nuts... alas.   /EDIT:   I have just tried the pyglet clock and limited it to 60 FPS; all the rest is still pygame. And see, it is much better now! Still not a 100% smooth but fine enough to code an NES-like game that runs at 60 FPS with a fixed time step.   Here's the code: import sys import pygame import pyglet pygame.init() display = pygame.display.set_mode((640, 480), pygame.FULLSCREEN) clock = pyglet.clock.Clock() clock.set_fps_limit(60) def motion_test(): rect = pygame.rect.Rect((0, 240), (40, 40)) while 1: # clear display display.fill((0, 0, 0)) # check quit for e in pygame.event.get(): if (e.type == pygame.QUIT or e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE): pygame.quit() sys.exit() # move the rect rect.x += 1 if rect.x >= 640: rect.x = 0 # draw the rect and flip the display pygame.draw.rect(display, (255, 0, 0), rect) pygame.display.flip() # tick the clock clock.tick() if __name__ == "__main__": motion_test()
  3. Don Polettone

    pygame - jerky movement in general

    Just tried again using 30 FPS. The result is quite similar: The rect "hickups" every like 1.0 seconds. I'm desperate...   Can you try and confirm or provide a hint? import sys import pygame pygame.init() display = pygame.display.set_mode((640, 480), pygame.FULLSCREEN) clock = pygame.time.Clock() FPS = 30 def motion_test(): dt = 0 rect_pos = [0.0, 240.0] rect = pygame.rect.Rect(rect_pos, (40, 40)) rect_speed = 60 # pixels per sec while 1: # clear display display.fill((0, 0, 0)) # check quit for e in pygame.event.get(): if (e.type == pygame.QUIT or e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE): pygame.quit() sys.exit() # move the rect dt = clock.get_time() rect_pos[0] += rect_speed * dt / 1000.0 if rect_pos[0] >= 640: rect_pos[0] = 0.0 rect.topleft = rect_pos # draw the rect and flip the display pygame.draw.rect(display, (255, 0, 0), rect) pygame.display.flip() # tick the clock clock.tick(FPS) if __name__ == "__main__": motion_test() Is there any way to get an accurate fixed time step on Win7 somehow? (Preferably @ 60 FPS)
  4. Don Polettone

    pygame - jerky movement in general

    Thanks for the hint! I now move the rect according to delta time (which is usually 16 / 17 ms @ 60 FPS), but still it's the same result: A notable "lag" after every 0.5 seconds or so.   Here's the code again: import sys import pygame pygame.init() display = pygame.display.set_mode((640, 480), pygame.FULLSCREEN) clock = pygame.time.Clock() FPS = 60 def motion_test(): dt = 0 rect_pos = [0.0, 240.0] rect = pygame.rect.Rect(rect_pos, (40, 40)) rect_speed = 60 # pixels per sec while 1: # clear display display.fill((0, 0, 0)) # check quit for e in pygame.event.get(): if (e.type == pygame.QUIT or e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE): pygame.quit() sys.exit() # move the rect dt = clock.get_time() rect_pos[0] += rect_speed * dt / 1000.0 if rect_pos[0] >= 640: rect_pos[0] = 0.0 rect.topleft = rect_pos # draw the rect and flip the display pygame.draw.rect(display, (255, 0, 0), rect) pygame.display.flip() # tick the clock clock.tick(FPS) if __name__ == "__main__": motion_test() I will try again using 30 FPS, just a moment...
  5. I've got a huge issue with pygame. Movement is always a bit jerky, even if the code is as simple as can be. Try running this simple example which moves a rect by 1 pixel at 60 FPS: import sys import pygame pygame.init() display = pygame.display.set_mode((640, 480), pygame.FULLSCREEN) clock = pygame.time.Clock() FPS = 60 def motion_test(): rect = pygame.rect.Rect((0, 240), (40, 40)) while 1: # clear display display.fill((0, 0, 0)) # check quit for e in pygame.event.get(): if (e.type == pygame.QUIT or e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE): pygame.quit() sys.exit() # move the rect by 1 pixel rect.x += 1 if rect.x >= 640: rect.x = 0 # draw the rect and flip the display pygame.draw.rect(display, (255, 0, 0), rect) pygame.display.flip() # tick the clock clock.tick(FPS) if __name__ == "__main__": motion_test() No matter on what hardware I test this, the rect is moving jerky. Every like half a second or so, it "jumps" a bit. It's just not smooth motion. Please, this makes me mad... does anybody know what might cause this? Is it pygame itself, or Python's garbage collection, or the OS, or just what? Any ideas? Do you see the same running the example?   (Win7 64bit, Pygame 1.9.1, Python 2.7.3)  
  6. Don Polettone

    Double Dragon 2 (NES) - Physics and collision

    Thanks, but can you please go a bit more into detail? I still don't get how it actually works and how I should go on.
  7. Hi there,   I've been trying very hard to get smooth movement using Pygame, but no matter how I try, things always look a bit jiggly.   I've read many tutorials about time step and pygame's time module, but it did not help. I would basically like to create pixely, "NES-ish" games and have therefore chosen a fixed time step of about 16 ms (= ca. 60 FPS). I've written a little demo program to test the main loop and see if it runs smooth, but the movement seems to stutter a bit sometimes. The module should run standalone with just Python 2.x and Pygame installed. Press ESC to exit the demo. Here it is:   import sys import pygame pygame.init() from pygame.constants import FULLSCREEN from pygame.rect import Rect RES = (640, 480) BLACK = (0, 0, 0) WHITE = (255, 255, 255) RED = (255, 0, 0) FPS = 60 screen = pygame.display.set_mode(RES, FULLSCREEN) clock = pygame.time.Clock() font = pygame.font.SysFont(pygame.font.get_default_font(), 24) player_pos = [0.0, 240.0] player_rect = Rect((0, 0), (40, 40)) player_speed = 0.8 # pixels per frame def check_quit():     for event in pygame.event.get():         quit_it = (event.type == pygame.QUIT or                    (event.type == pygame.KEYDOWN and                     event.key == pygame.K_ESCAPE))         if quit_it:             pygame.quit()             sys.exit() def draw_player():     pygame.draw.rect(screen, RED, player_rect) def draw_fps(ms):     topleft = (20, 20)     surf = font.render("FPS " + str(ms), True, WHITE)     screen.blit(surf, topleft) def draw_time_left(ms):     topleft = (20, 50)     surf = font.render("time left " + str(ms), True, WHITE)     screen.blit(surf, topleft) def main():     time_left = 0     fps = FPS     player_rect.center = player_pos     draw_player()     pygame.display.flip()     pygame.time.wait(4000)          while 1:         check_quit()         screen.fill(BLACK)         player_pos[0] += player_speed         player_rect.center = player_pos         draw_player()         draw_time_left(time_left)         draw_fps(fps)         pygame.display.flip()         frame_duration = clock.tick(FPS) # 1 frame -> ca. 16 milsecs         time_used = clock.get_rawtime() # cpu time used for 1 frame         fps = clock.get_fps() # fps computed by pygame         time_left = frame_duration - time_used # time left for each frame to compute more stuff          if __name__ == "__main__":     main()   Are there any experienced pygame users who could run the file and see if they experience the same? I really start thinking that pygame is not the proper tool to code my stuff...   Thanks, folks
  8. Hi all,   First post from me in this forum. I'd like to code a game like Double Dragon 2 on the NES, using Python / Pygame. I know the original very well and I'd like to adapt most of its gameplay and physics.   The physics are pretty special though in these games,,, it's tile-based and that is fine, but some areas are like 2.5D, other are 2D sideview.   Here are some screenshots for those who don't know the game:   2.5D Area     2.5D "Steps"     2D Area     So the game has mixed areas, even in the same level. Now I thought about how I could handle the physics. In 3D areas, I thought about storing the ground position of each char and move this position around when walking. For jumping, the char stores an "air" attr. The chars hitrect will go up when jumping according to air, the ground position stays where it is (when jumping straight up). Here are some images for better understanding:       So I would use the groundposition for collision checking (in 2.5D areas). But for 2D areas, the same logic doesn't work anymore (I think?) Does anyone know how they made the collision stuff in this particular game? A tutorial about this, or just a good hint, would be much appreciated!   Thanks in advance and have a crispy day :-)    
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!