System

Vector2

class sfml.system.Vector2

Utility class for manipulating 2-dimensional vectors.

Vector2 is a simple class that defines a mathematical vector with two coordinates (x and y).

It can be used to represent anything that has two dimensions: a size, a point, a velocity, etc.

Vector2 supports arithmetic operations (+, -, /, *), unary operations and comparisons (==, !=).

It contains no mathematical function like dot product, cross product, length, etc.

Usage example:

v1 = sf.Vector2(16.5, 24)
v1.x = 18.2
y = v1.y

v2 = v1 * 5

v3 = v1 + v2

different = v2 != v3

Note: for 3-dimensional vectors, see Vector3

Vector2(x=0, y=0)

Construct an sfml.system.Vector2

x

X coordinate of the vector.

y

Y coordinate of the vector.

Vector3

class sfml.system.Vector3

Utility class for manipulating 3-dimensional vectors.

Vector3 is a simple class that defines a mathematical vector with three coordinates (x, y and z).

It can be used to represent anything that has three dimensions: a size, a point, a velocity, etc.

Vector3 supports arithmetic operations (+, -, /, *), unary operations and comparisons (==, !=).

It contains no mathematical function like dot product, cross product, length, etc.

Usage example:

v1 = sf.Vector3(16.5, 24, -8.2)
v1.x = 18.2
y = v1.y
z = v1.z

v2 = v1 * 5

v3 = v1 + v2

different = v2 != v3

Note: for 2-dimensional vectors, see Vector2

Vector3(x=0, y=0, z=0)

Construct an sfml.system.Vector3

x

X coordinate of the vector.

y

Y coordinate of the vector.

z

Z coordinate of the vector.

seconds

sfml.system.seconds(amount)

Construct a time value from a number of seconds.

Parameters:amount (float) – Number of seconds
Returns:Time value constructed from the amount of seconds
Return type:sfml.system.Time

milliseconds

sfml.system.milliseconds(amount)

Construct a time value from a number of milliseconds.

Parameters:amount (int) – Number of milliseconds
Returns:Time value constructed from the amount of milliseconds
Return type:sfml.system.Time

microseconds

sfml.system.microseconds(amount)

Construct a time value from a number of microseconds.

Parameters:amount (int) – Number of microseconds
Returns:Time value constructed from the amount of microseconds
Return type:sfml.system.Time

Time

class sfml.system.Time

Represents a time value.

Time encapsulates a time value in a flexible way.

It allows to define a time value either as a number of seconds, milliseconds or microseconds. It also works the other way round: you can read a time value as either a number of seconds, milliseconds or microseconds.

By using such a flexible interface, the API doesn’t impose any fixed type or resolution for time values, and let the user choose its own favorite representation.

Time values support the usual mathematical operations: you can add or subtract two times, multiply or divide a time by a number, compare two times, etc.

Since they represent a time span and not an absolute time value, times can also be negative.

Usage example:

t1 = sf.seconds(0.1)
milli = t1.milliseconds

t2 = sf.milliseconds(30)
micro = t2.microseconds

t3 = sf.microseconds(-800000)
sec = t3.seconds
def update(elapsed):
   position += speed * elapsed.seconds

update(sf.milliseconds(100))

See also: Clock

Time()

Construct a Time equivalent to ZERO

ZERO

Predefined “zero” time value. Copy this value with the copy module.

seconds

Return the time value as a number of seconds.

milliseconds

Return the time value as a number of milliseconds.

microseconds

Return the time value as a number of microseconds.

Clock

class sfml.system.Clock

Utility class that measures the elapsed time.

Clock is a lightweight class for measuring time.

It provides the most precise time that the underlying OS can achieve (generally microseconds or nanoseconds). It also ensures monotonicity, which means that the returned time can never go backward, even if the system time is changed.

Usage example:

clock = sf.Clock()
# ...
time1 = clock.elapsed_time
# ...
time2 = clock.restart()

The Time value returned by the clock can then be converted to a number of seconds, milliseconds or even microseconds.

See also: Time

Clock()

Construct a Clock

The clock starts automatically after being constructed.

elapsed_time

Get the elapsed time.

This attribute returns the time elapsed since the last call to restart() (or the construction of the instance if restart() has not been called).

Returns:Time elapsed
Return type:sfml.system.Time
restart()

Restart the clock.

This function puts the time counter back to zero. It also returns the time elapsed since the clock was started.

Returns:Time elapsed
Return type:sfml.system.Time

sleep

sfml.system.sleep(duration)

Make the current thread sleep for a given duration.

sleep() is the best way to block a program or one of its threads, as it doesn’t consume any CPU power.

Parameters:duration (sfml.system.Time) – Time to sleep