Skip to content

Commit

Permalink
Refactor sprite from _x, _y, _z attributes to _position tuple attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Aug 3, 2023
1 parent 4029cba commit 23aa26e
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions pyglet/experimental/geoshader_sprite.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def __hash__(self):
class Sprite(event.EventDispatcher):
__slots__ = ['_batch', '_animation', '_frame_index', '_paused', '_rotation',
'_rgba', '_scale', '_scale_x', '_scale_y', '_visible',
'_vertex_list', 'group_class', '_x', '_y', '_z', '_img', '_texture',
'_vertex_list', 'group_class', '_position', '_img', '_texture',
'_program', '_user_group', '_group', '_subpixel',
'_position_setter']

Expand Down Expand Up @@ -289,9 +289,7 @@ def __init__(self,
self._vertex_list = None
self.group_class = SpriteGroup

self._x = x
self._y = y
self._z = z
self._position = (x, y, z)
self._img = img

if isinstance(img, image.Animation):
Expand Down Expand Up @@ -322,7 +320,7 @@ def _create_vertex_list(self):
texture = self._texture
self._vertex_list = self.program.vertex_list(
1, GL_POINTS, self._batch, self._group,
position=('f', (self._x, self._y, self._z)),
position=('f', self._position),
size=('f', (texture.width, texture.height, 1, 1)),
color=('Bn', self._rgba),
texture_uv=('f', texture.uv),
Expand Down Expand Up @@ -477,11 +475,11 @@ def position(self):
`z` : int
Z coordinate of the sprite.
"""
return self._x, self._y, self._z
return self._position

@position.setter
def position(self, position):
self._x, self._y, self._z = position
self._position = position
self._vertex_list.position[:] = position

@property
Expand All @@ -490,38 +488,44 @@ def x(self):
:type: int
"""
return self._x
return self._position[0]

@x.setter
def x(self, x):
self._x = x
self._vertex_list.position[:] = x, self._y, self._z
_, y, z = self._position
position = x, y, z
self._position = position
self._vertex_list.position[:] = position

@property
def y(self):
"""Y coordinate of the sprite.
:type: int
"""
return self._y
return self._position[1]

@y.setter
def y(self, y):
self._y = y
self._vertex_list.position[:] = self._x, y, self._z
x, _, z = self._position
position = x, y, z
self._position = position
self._vertex_list.position[:] = position

@property
def z(self):
"""Z coordinate of the sprite.
:type: int
"""
return self._z
return self._position[2]

@z.setter
def z(self, z):
self._z = z
self._vertex_list.position[:] = self._x, self._y, z
x, y, _ = self._position
position = x, y, z
self._position = position
self._vertex_list.position[:] = position

@property
def rotation(self):
Expand Down

0 comments on commit 23aa26e

Please sign in to comment.