Misc¶
Blend modes¶

sfml.
BLEND_ADD
¶ Pixel = Source + Dest.

sfml.
BLEND_ALPHA
¶ Pixel = Source * Source.a + Dest * (1  Source.a).

sfml.
BLEND_MULTIPLY
¶ Pixel = Source * Dest.

sfml.
BLEND_NONE
¶ Pixel = Source.
Primitive types¶

sfml.
POINTS
¶ List of individual points.

sfml.
LINES
¶ List of individual lines.

sfml.
LINES_STRIP
¶ List of connected lines, a point uses the previous point to form a line.

sfml.
TRIANGLES
¶ List of individual triangles.

sfml.
TRIANGLES_FAN
¶ List of connected triangles, a point uses the common center and the previous point to form a triangle.

sfml.
TRIANGLES_STIP
¶ List of connected triangles, a point uses the two previous points to form a triangle.

sfml.
QUADS
¶ List of individual quads.
Basic classes¶

class
sfml.
Color
(int r, int g, int b[, int a=255])¶ Represents a color of 4 components:
 red,
 green,
 blue,
 alpha (opacity).
Each component is a public member, an unsigned integer in the range [0, 255]. Thus, colors can be constructed and manipulated very easily:
color = sfml.Color(255, 0, 0) # red; you can also use Color.RED color.r = 0 # make it black color.b = 128 # make it dark blue
The fourth component of colors, named “alpha”, represents the opacity of the color. A color with an alpha value of 255 will be fully opaque, while an alpha value of 0 will make a color fully transparent, whatever the value of the other components is.
This class provides the following special methods:
 Comparison operators:
==
and!=
.  Arithmetic operators:
+
and*
.
The following colors are available as static attibutes, e.g. you can use
Color.WHITE
to obtain a reference to the white color:
BLACK
¶

BLUE
¶

CYAN
¶

GREEN
¶

MAGENTA
¶

RED
¶

TRANSPARENT
¶ Transparent black color, i.e. this is equal to
Color(0, 0, 0, 0)
.

WHITE
¶

YELLOW
¶

r
¶ Red component.

g
¶ Green component.

b
¶ Blue component.

a
¶ Alpha (opacity) component.

copy
()¶ Return a new Color with the same value as self.

class
sfml.
Vector2f
(float x=0.0; float y=0.0)¶ You don’t have to use this class; everywhere you can pass a
Vector2f
, you should be able to pass a tuple as well. However, it can be more practical to use it, as it overrides arithmetic and comparison operators, is mutable and requires that you use thex
andy
members instead of indexing.This class provides the following special methods:
 Comparison operators:
==
and!=
.

x
¶ x coordinate for this vector.

y
¶ y coordinate for this vector.
 Comparison operators:

class
sfml.
IntRect
(int left=0, int top=0, int width=0, int height=0)¶ A rectangle is defined by its topleft corner and its size.
To keep things simple,
IntRect
doesn’t define functions to emulate the properties that are not directly members (such as right, bottom, center, etc.), instead it only provides intersection functions.IntRect
uses the usual rules for its boundaries: The left and top edges are included in the rectangle’s area.
 The right (left + width) and bottom (top + height) edges are excluded from the rectangle’s area.
This means that
sfml.IntRect(0, 0, 1, 1)
andsfml.IntRect(1, 1, 1, 1)
don’t intersect.Usage example:
# Define a rectangle, located at (0, 0) with a size of 20x5 r1 = sfml.IntRect(0, 0, 20, 5) # Define another rectangle, located at (4, 2) with a size of 18x10 r2 = sfml.IntRect(4, 2, 18, 10) # Test intersections with the point (3, 1) b1 = r1.contains(3, 1) # True b2 = r2.contains(3, 1) # False # Test the intersection between r1 and r2 result = sfml.IntRect() b3 = r1.intersects(r2, result) # True # result == (4, 2, 16, 3)
Note
You don’t have to use this class; everywhere you can pass a
IntRect
, you should be able to pass a tuple as well. However, it can be more practical to use it, as it provides useful methods and is mutable.This class provides the following special methods:
 Comparison operators:
==
and!=
.

left
¶ Left coordinate of the rectangle.

top
¶ Top coordinate of the rectangle.

width
¶ Width of the rectangle.

height
¶ Height of the rectangle.

contains
(int x, int y)¶ Return whether or not the rectangle contains the point (x, y).

copy
()¶ Return a new IntRect object with the same value as self.

intersects
(IntRect rect[, IntRect intersection])¶ Return whether or not the two rectangles intersect. If intersection is provided, it will be set to the intersection area.

class
sfml.
FloatRect
(float left=0, float top=0, float width=0, float height=0)¶ A rectangle is defined by its topleft corner and its size.
To keep things simple,
FloatRect
doesn’t define functions to emulate the properties that are not directly members (such as right, bottom, center, etc.), instead it only provides intersection functions.FloatRect
uses the usual rules for its boundaries: The left and top edges are included in the rectangle’s area.
 The right (left + width) and bottom (top + height) edges are excluded from the rectangle’s area.
This means that
sfml.FloatRect(0, 0, 1, 1)
andsfml.FloatRect(1, 1, 1, 1)
don’t intersect.See
IntRect
for an example.Note
You don’t have to use this class; everywhere you can pass a
FloatRect
, you should be able to pass a tuple as well. However, it can be more practical to use it, as it provides useful methods and is mutable.This class provides the following special methods:
 Comparison operators:
==
and!=
.

left
¶ The left coordinate of the rectangle.

top
¶ The top coordinate of the rectangle.

width
¶ The width of the rectangle.

height
¶ The height of the rectangle.

contains
(int x, int y)¶ Return whether or not the rectangle contains the point (x, y).

copy
()¶ Return a new FloatRect object with the same value as self.

intersects
(FloatRect rect[, FloatRect intersection])¶ Return whether or not the two rectangles intersect. If intersection is provided, it will be set to the intersection area.