Not able to extend SpriteObject:setSequence()

Hello, 

Could someone of the Corona team verify that SpriteObject methods are not able to be extended/overridden? And if so, why is that? and will it ever be possible in the near future?

The problem is shown in the code below. I’m just testing setSequence here, but testing play/pause or setFrame won’t work either.

local testSheet = graphics.newImageSheet(INSERT\_OWN\_SHEET\_CONFIG\_HERE}) local testSprite = display.newSprite(testSheet, INSERT\_OWN\_SPRITE\_CONFIG\_HERE) print(testSprite.setSequence) -- Printing before override function testSprite:setSequence() -- Override print("extendedSetSequence") end print(testSprite.setSequence) -- Printing after override testSprite:setSequence("test") -- Calling the new function

After running this code, you will get 2 print messages mentioning the same function (eg. “function: 0x7ABC”, “function: 0xABC”). Also the “extendedSetSequence” print message is not shown.

Ps. extending DisplayObject function DOES work

Hi @pouwelsjochem8,

Can you explain what your needs/purposes are for overriding a core function like this?

Best regards,

Brent

I sure can. As you might know, when applying a filter effect or do setFillColor() on a sprite, you need to apply that effect again when changing to a new sequence.

I was making an utility function which does this for you. In my case: spriteHelper:setOnSequenceInit(_sprite, _function). This would apply given function one time per sequence.

Hi @pouwelsjochem8,

In my testing, the :setSequence() function does appear to be “blocked” from typical override practice.

One alternative which might work for you is to apply a sprite listener to the object, detect the “began” phase, and then re-apply your filter/fill at that time… but that will only work if you immediately play() the new sequence after you change to it.

Sadly this won’t work in the situation I needed it for, since the sprite is being controlled by using setSequence/setFrame.

I don’t know what reason there is to block the overriding of these functions, is there any possibility you might reconsider/unblock this?

Hi @pouwelsjochem8,

Can you explain what your needs/purposes are for overriding a core function like this?

Best regards,

Brent

I sure can. As you might know, when applying a filter effect or do setFillColor() on a sprite, you need to apply that effect again when changing to a new sequence.

I was making an utility function which does this for you. In my case: spriteHelper:setOnSequenceInit(_sprite, _function). This would apply given function one time per sequence.

Hi @pouwelsjochem8,

In my testing, the :setSequence() function does appear to be “blocked” from typical override practice.

One alternative which might work for you is to apply a sprite listener to the object, detect the “began” phase, and then re-apply your filter/fill at that time… but that will only work if you immediately play() the new sequence after you change to it.

Sadly this won’t work in the situation I needed it for, since the sprite is being controlled by using setSequence/setFrame.

I don’t know what reason there is to block the overriding of these functions, is there any possibility you might reconsider/unblock this?