Aaand it's done. The patch is attached.
It was pretty quick and easy to do. You guys did a good job.
Also, I'm sorry to ask, but can you test it for me? It seems to be working
well for sprites as well as scenes and layers, but I didn't do much testing
as I wouldn't know what to test.
Thanks!
--
You received this message because you are subscribed to the Google Groups
"cocos2d discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cocos-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Index: cocosnode.py
===================================================================
--- cocosnode.py (revision 1225)
+++ cocosnode.py (working copy)
@@ -94,6 +94,14 @@
#: Default: 1.0
self._scale = 1.0
+ #: a float, alters the horizontal scale of this node and its children.
+ #: Default: 1.0
+ self._scale_x = 1.0
+
+ #: a float, alters the vertical scale of this node and its children.
+ #: Default: 1.0
+ self._scale_y = 1.0
+
#: a float, in degrees, alters the rotation of this node and its children.
#: Default: 0.0
self._rotation = 0.0
@@ -382,6 +390,26 @@
scale = property( _get_scale, lambda self, scale: self._set_scale(scale))
+ def _get_scale_x( self ):
+ return self._scale_x
+
+ def _set_scale_x( self, s ):
+ self._scale_x = s
+ self.is_transform_dirty = True
+ self.is_inverse_transform_dirty = True
+
+ scale_x = property( _get_scale_x, lambda self, scale: self._set_scale_x(scale))
+
+ def _get_scale_y( self ):
+ return self._scale_y
+
+ def _set_scale_y( self, s ):
+ self._scale_y = s
+ self.is_transform_dirty = True
+ self.is_inverse_transform_dirty = True
+
+ scale_y = property( _get_scale_y, lambda self, scale: self._set_scale_y(scale))
+
def _get_rotation( self ):
return self._rotation
@@ -564,8 +592,8 @@
if self.rotation != 0.0:
glRotatef( -self._rotation, 0, 0, 1)
- if self.scale != 1.0:
- glScalef( self._scale, self._scale, 1)
+ if self.scale != 1.0 or self.scale_x != 1.0 or self.scale_y != 1.0:
+ glScalef( self._scale * self._scale_x, self._scale * self._scale_y, 1)
if self.transform_anchor != (0,0):
glTranslatef(
@@ -802,7 +830,7 @@
matrix.translate(self._x, self._y)
matrix.translate( self.transform_anchor_x, self.transform_anchor_y )
matrix.rotate( math.radians(-self.rotation) )
- matrix.scale(self._scale, self._scale)
+ matrix.scale(self._scale * self._scale_x, self._scale * self._scale_y)
matrix.translate( -self.transform_anchor_x, -self.transform_anchor_y )
Index: sprite.py
===================================================================
--- sprite.py (revision 1225)
+++ sprite.py (working copy)
@@ -102,6 +102,10 @@
the rotation (degrees). Defaults to 0.
`scale` : float
the zoom factor. Defaults to 1.
+ `scale_x` : float
+ additional horizontal-only zoom factor. Defaults to 1.
+ `scale_y` : float
+ additional vertical-only zoom factor. Defaults to 1.
`opacity` : int
the opacity (0=transparent, 255=opaque). Defaults to 255.
`color` : tuple
@@ -118,6 +122,10 @@
self._image_anchor_x = 0
self._image_anchor_y = 0
+ # These need to be forward-defined here because pyglet sprites don't have them.
+ self._scale_x = 1
+ self._scale_y = 1
+
pyglet.sprite.Sprite.__init__(self, image)
BatchableNode.__init__(self)
@@ -150,6 +158,12 @@
#: scale of the sprite where 1.0 the default value
self.scale = scale
+ #: additional horizontal-only scale of the sprite where 1.0 the default value
+ self.scale_x = 1
+
+ #: additional vertical-only scale of the sprite where 1.0 the default value
+ self.scale_y = 1
+
#: opacity of the sprite where 0 is transparent and 255 is solid
self.opacity = opacity
@@ -268,8 +282,8 @@
if self.transform_anchor_x == self.transform_anchor_y == 0:
if self._rotation:
- x1 = -self._image_anchor_x * self._scale
- y1 = -self._image_anchor_y * self._scale
+ x1 = -self._image_anchor_x * self._scale * self._scale_x
+ y1 = -self._image_anchor_y * self._scale * self._scale_y
x2 = x1 + img.width * self._scale
y2 = y1 + img.height * self._scale
x = self._x
@@ -288,11 +302,11 @@
dy = int(x1 * sr + y2 * cr + y)
self._vertex_list.vertices[:] = [ax, ay, bx, by, cx, cy, dx, dy]
- elif self._scale != 1.0:
- x1 = int(self._x - self._image_anchor_x * self._scale)
- y1 = int(self._y - self._image_anchor_y * self._scale)
- x2 = int(x1 + img.width * self._scale)
- y2 = int(y1 + img.height * self._scale)
+ elif self._scale != 1.0 or self._scale_x != 1.0 or self._scale_y != 1.0:
+ x1 = int(self._x - self._image_anchor_x * self._scale * self._scale_x)
+ y1 = int(self._y - self._image_anchor_y * self._scale * self._scale_y)
+ x2 = int(x1 + img.width * self._scale * self._scale_x)
+ y2 = int(y1 + img.height * self._scale * self._scale_y)
self._vertex_list.vertices[:] = [x1, y1, x2, y1, x2, y2, x1, y2]
else:
x1 = int(self._x - self._image_anchor_x)