File tree Expand file tree Collapse file tree 4 files changed +30
-1
lines changed
Expand file tree Collapse file tree 4 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ class LIBSCRATCHCPP_EXPORT Sprite
4747 double y () const ;
4848 void setY (double newY);
4949
50+ void setPosition (double x, double y);
51+
5052 double size () const ;
5153 void setSize (double newSize);
5254
Original file line number Diff line number Diff line change @@ -184,6 +184,17 @@ void Sprite::setY(double newY)
184184 impl->iface ->onYChanged (impl->y );
185185}
186186
187+ /* Sets the position of the sprite. */
188+ void Sprite::setPosition (double x, double y)
189+ {
190+ setXY (x, y);
191+
192+ if (impl->iface ) {
193+ impl->iface ->onXChanged (impl->x );
194+ impl->iface ->onYChanged (impl->y );
195+ }
196+ }
197+
187198/* ! Returns the size. */
188199double Sprite::size () const
189200{
Original file line number Diff line number Diff line change @@ -233,7 +233,7 @@ TEST(SpriteTest, XY)
233233
234234 EngineMock engine;
235235 sprite.setEngine (&engine);
236- EXPECT_CALL (engine, requestRedraw ()).Times (17 );
236+ EXPECT_CALL (engine, requestRedraw ()).Times (18 );
237237 EXPECT_CALL (engine, spriteFencingEnabled ()).Times (4 ).WillRepeatedly (Return (false ));
238238
239239 sprite.setX (-53.25 );
@@ -340,6 +340,13 @@ TEST(SpriteTest, XY)
340340 EXPECT_CALL (handler, onYChanged);
341341 sprite.setY (-340 );
342342 ASSERT_EQ (sprite.y (), -340 );
343+
344+ EXPECT_CALL (engine, spriteFencingEnabled ()).WillOnce (Return (false ));
345+ EXPECT_CALL (handler, onXChanged);
346+ EXPECT_CALL (handler, onYChanged);
347+ sprite.setPosition (56 , -23 );
348+ ASSERT_EQ (sprite.x (), 56 );
349+ ASSERT_EQ (sprite.y (), -23 );
343350}
344351
345352TEST (SpriteTest, Size)
Original file line number Diff line number Diff line change @@ -93,6 +93,15 @@ TEST_F(ISpriteHandlerTest, Y)
9393 m_sprite.setY (207.08 );
9494}
9595
96+ TEST_F (ISpriteHandlerTest, Position)
97+ {
98+ EXPECT_CALL (m_handler, onXChanged (284.61 ));
99+ EXPECT_CALL (m_handler, onYChanged (207.08 ));
100+ EXPECT_CALL (m_engine, spriteFencingEnabled ()).WillOnce (Return (false ));
101+ EXPECT_CALL (m_engine, requestRedraw ());
102+ m_sprite.setPosition (284.61 , 207.08 );
103+ }
104+
96105TEST_F (ISpriteHandlerTest, Size)
97106{
98107 EXPECT_CALL (m_handler, onSizeChanged (53.8 )).Times (1 );
You can’t perform that action at this time.
0 commit comments