Posts: 544
Threads: 15
Joined: Oct 2016
Most of the time it because you didn't use delta or/and floats . Both these will effect movement. Without code it be hard to tell.
99 percent of computer problems exists between chair and keyboard.
Posts: 544
Threads: 15
Joined: Oct 2016
Jul-19-2022, 06:34 PM
(This post was last modified: Jul-19-2022, 06:40 PM by Windspar.)
Another reason for poor performance . Your not letting computer idle. If you let it max out cpu. It will cause lag.
1 2 3 |
clock = pygame.time.Clock()
delta = clock.tick( 60 )
|
99 percent of computer problems exists between chair and keyboard.
Posts: 544
Threads: 15
Joined: Oct 2016
Jul-19-2022, 11:14 PM
(This post was last modified: Jul-19-2022, 11:14 PM by Windspar.)
First rule of game programming. Never use the sleep command.
Delta is use for smooth movement.
metulburr likes this post
99 percent of computer problems exists between chair and keyboard.
Posts: 544
Threads: 15
Joined: Oct 2016
By using pygame.time.get_ticks.
This is how I normal handle it. This handle three different ways. one shot timer, repeat timer, and trip counter timer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
class Ticker:
def __init__( self , ticks, interval):
self .tick = ticks + interval
self .interval = interval
self .count = 0
def elapsed( self , ticks):
return ticks > = self .tick
def reset( self , ticks, interval = None ):
if interval:
self .interval = interval
self .tick = ticks + self .interval
def tick( self , ticks):
if ticks > = self .tick:
self .tick = ticks + self .interval
return True
return False
def tick_count( self , ticks):
self .count = 0
while ticks > = self .tick:
self .tick + = self .interval
self .count + = 1
return bool ( self .count)
|
In main loop. You can do something like this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
ticks = pygame.get_ticks()
ticker = Ticker(ticks, 2000 )
ticks = pygame.get_ticks()
if ticker.elasped(ticks):
ticker.count + = 1
if ticker.count < 2 :
ticker.reset(ticks, 3000 )
if ticker.count = = 0 :
elif ticker.count = = 1 :
|
99 percent of computer problems exists between chair and keyboard.
Posts: 544
Threads: 15
Joined: Oct 2016
Jul-20-2022, 02:54 AM
(This post was last modified: Jul-20-2022, 03:00 AM by Windspar.)
Delta is the time between pygame.display.flip. Since fps can and will vary. This is why you use pygame.time.Clock.
The clock.tick will always return in millisecond. You can simple * 0.001 to return in seconds. Then you take delta * object speed. This will give you the correct amount of movement. No matter what the fps is. Don't forget to store floats. Since Rects are only integers.
1 2 3 4 |
clock = pygame.time.Clock()
delta = 0
delta = clock.tick(fps)
|
99 percent of computer problems exists between chair and keyboard.