File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -35,13 +35,32 @@ subscripts
3535 v.y == v[1]
3636 v.z == v[2]
3737
38- Multiple coordinates can be set using slices or swizzling
38+ Multiple coordinates can be set and retrieved using slices or swizzling.
3939
4040::
4141
4242 v = pygame.Vector2()
4343 v.xy = 1, 2
4444 v[:] = 1, 2
45+ print(v) # Vector2(1, 2)
46+ print(v.x) # 1.0
47+ print(v.y) # 2.0
48+ print(v.xy) # Vector2(1, 2)
49+ print(v.yx) # Vector2(2, 1)
50+ print(v.xyyx) # (1.0, 2.0, 2.0, 1.0)
51+
52+ Note above, that swizzlling with 2 components will return a Vector2 instance
53+ again, while more than 2 components will result in a tuple. But since vectors
54+ support the iterator protocol, they can be by unpacked, or converted to lists
55+ or tuples.
56+
57+ ::
58+
59+ v = Vector2(1, 2)
60+ print(*v) # 1.0 2.0
61+ print(tuple(v)) # (1.0, 2.0)
62+ print(tuple(v.yx)) # (2.0, 1.0)
63+
4564
4665.. versionaddedold :: 1.9.2pre
4766.. versionchangedold :: 1.9.4 Removed experimental notice.
You can’t perform that action at this time.
0 commit comments