[los-cocos] r1349 committed - fix Sprite.get_rect , was missing scale_x and scale_y - #208

2 views
Skip to first unread message

los-...@googlecode.com

unread,
Mar 19, 2014, 11:03:46 AM3/19/14
to cocos-...@googlegroups.com
Revision: 1349
Author: ccanepacc
Date: Wed Mar 19 15:03:24 2014 UTC
Log: fix Sprite.get_rect , was missing scale_x and scale_y - #208
http://code.google.com/p/los-cocos/source/detail?r=1349

Modified:
/trunk/cocos/sprite.py
/trunk/test/test_rect.py

=======================================
--- /trunk/cocos/sprite.py Wed Mar 19 14:11:44 2014 UTC
+++ /trunk/cocos/sprite.py Wed Mar 19 15:03:24 2014 UTC
@@ -220,6 +220,26 @@
BatchableNode._set_scale_y(self,s)
self._update_position()

+ def _get_width(self):
+ return int(self._texture.width * self._scale * self._scale_x)
+ width = property(_get_width,
+ doc='''Scaled width of the sprite.
+
+ Read-only. Invariant under rotation.
+
+ :type: int
+ ''')
+
+ def _get_height(self):
+ return int(self._texture.height * self._scale * self._scale_y)
+ height = property(_get_height,
+ doc='''Scaled height of the sprite.
+
+ Read-only. Invariant under rotation.
+
+ :type: int
+ ''')
+
def _set_position( self, p ):
BatchableNode._set_position(self,p)
pyglet.sprite.Sprite.set_position(self, *p)
=======================================
--- /trunk/test/test_rect.py Wed Mar 19 14:11:44 2014 UTC
+++ /trunk/test/test_rect.py Wed Mar 19 15:03:24 2014 UTC
@@ -38,6 +38,7 @@
self.do(
Delay(2) + CallFunc(self.mov) +
Delay(2) + CallFunc(self.zoom) +
+ Delay(2) + CallFunc(self.scalex) +
Delay(2) + CallFunc(self.rot)
)
self.mouse_mark = cocos.layer.ColorLayer(0, 0, 255, 255, 20, 20)
@@ -65,6 +66,10 @@
self.sprite1.scale = 2
self.show_rect()

+ def scalex(self):
+ self.sprite1.scale_x = 0.5
+ self.show_rect()
+
def on_mouse_press(self, x, y, buttons, modifiers):
self.update_mouse_mark(x, y)

@@ -92,9 +97,10 @@

This scripts shows a sprite and a white rectangle depicting
sprite.get_rect(),
It starts at one position
- After 3 seconds sprite moves to another position
- After 3 seconds sprite scales 2x
- After 3 seconds sprite rotates 90 degress
+ After 2 seconds sprite moves to another position
+ After 2 seconds sprite scales 2x in both axis
+ After 2 seconds sprite scales 0.5 in the x axis
+ After 2 seconds sprite rotates 90 degress

get_rect() gives a tight fit when changing position or scale, but not when
a
rotation is applied.
Reply all
Reply to author
Forward
0 new messages