Jump to content

question regarding setting Sprite.scale...


Recommended Posts

is it acceptable to set Sprite.scale to a non-unit (1/-1) value during gameplay? as it currently stands if you change a sprite's scale during gameplay to a non-unitary value (for instance to cause the sprite to grow over time), the sprite's position in the world/screen is compromised.


you can experience this using the starstruck demo by adding a line to update() that changes player.scale.y each frame. (e.g. 'player.scale.y += 0.01;'). then try moving the sprite about normally - you'll see that it jumps to the left as it is scaled.


I debugged into it a bit, but figured I ought to find out if this was intended to work before I spent too much time on it.


if changing scale during gameplay is not allowed, is there a way to change the size of sprites while the game is running?





Link to comment
Share on other sites

Yes you can scale a sprite at run-time (I do it quite a lot). I expect what's happening in Starstruck is the scale is causing the sprite to embed into the tiles below, so when it separates it's clearing the whole tile width in one jump, accelerating off to the left (or right) of the world as soon as it gets a delta value again. A change in just scale isn't currently considered as having any motion, so it's not separating as it thinks the sprite is stationary.


I guess it's not really a bug in that it's doing what it's supposed to do, but it's just not smart enough to cope with separating after a shift in scale, which it ought to do.

Link to comment
Share on other sites

thanks Rich, you pegged it. changing the sprite's position to ensure the scale change doesn't cause an overlap with anything 'solid' gets me the behavior I was looking for.


I was seeing this in my game when I changed the 'y' scale, but not 'x', because my sprite was standing on a long flat row of 'solid' tiles - the sprite would fly off the screen to the left when I tried to change it's 'y' scale. quite amusing (esp. since the sprite is a cat, which emits a loud 'meow' simultaneously), but not quite what I was looking for.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...