I wanted to create an animated toggle button that would actually slide when toggled. This code is attached to a button's actionPerformed event handler. It just toggles a variable and slide over the object by it's own width when clicked:
this = event.source
toggleState = not this.toggleState
this.toggleState = toggleState
if toggleState == False:
target = this.x - this.width
this.text = this.state0Text
elif toggleState == True:
target = this.x + this.width
this.text = this.state1Text
system.gui.transform(
this,
newX=target,
duration=200,
acceleration=system.gui.ACCL_EASE
)
This works perfectly fine when done directly in the editor.
Then I wanted to template it and started getting really weird behavior when resizing the instance. The animation works fine if I keep the original size, but it breaks if I resize.
Even weirder, the breaking behavior is different if the objects are 'loose' or grouped within the template. See screenshots:
As you can see, when templated, the button doesn't slide over the right amount. I added some print statements to check the values of 'this.x', 'this.width' and 'target'. The first time I click the button, the values appear correct, but the object doesn't actually gets moved the right amount, which throws off all subsequent toggles.
I'm even more perplexed at the behavior when the object is grouped within the template. Now not only the position is wrong, it also somehow scales the button, even though I'm not changing the scale in the code.
To reiterate, those are the exact same objects, with the same code, the only difference is being a template instance or not.
This was only a fun little test so I'm not too worried about keeping it non-templated, but I feel like this is either a bug or I'm wrong about the expected behavior.
Either way I appreciate any advice!