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
35
35
v.y == v[1]
36
36
v.z == v[2]
37
37
38
- Multiple coordinates can be set using slices or swizzling
38
+ Multiple coordinates can be set and retrieved using slices or swizzling.
39
39
40
40
::
41
41
42
42
v = pygame.Vector2()
43
43
v.xy = 1, 2
44
44
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 swizzling 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 unpacked, or converted to lists or
55
+ 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
+
45
64
46
65
.. versionaddedold :: 1.9.2pre
47
66
.. versionchangedold :: 1.9.4 Removed experimental notice.
You can’t perform that action at this time.
0 commit comments