app-inventor

Resetting a sprite to its original dimensions programmatically


Is it possible to reset a sprite's dimensions programmatically, by invoking a built-in procedure / method?

I know that I can do something along the lines (ignoring the aspect ratio in this example, for simplicity's sake):

initialize global myHeight to 0
initialize global myWidth to 0


when Screen1.initialize
do
  set myHeight to get ImageSprite.Height
  set myWidth to get ImageSprite.Width
  set Clock1.TimerInterval to 2500


when Clock1.Timer
do
  set ImageSprite.Height = myHeight * random integer from 50 to 100
  set ImageSprite.Width = myWidth * random integer from 50 to 100


when Button1.Click
do
  set ImageSprite.Height = myHeight
  set ImageSprite.Width = myWidth

But I'm wondering if there's a way to simplify this, preferably natively, without the use of custom procedures, extensions, etc.

I'm aware that I could make a generic resetting procedure, and then use it on Button1.Click, or in a foreach loop, when having more than one sprite. I'm trying to avoid that, by asking for an already existing procedure, if there is one.


Solution

  • your pseudo code shows the way to do it... there is no already existing procedure...