Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Not able to extend SpriteObject:setSequence()
Started by pouwelsjochem8 Mar 09 2017 08:50 AM

- - - - -
4 replies to this topic
api corona extends displayobject sprite object
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

pouwelsjochem8

[GLOBAL: userInfoPane.html]
pouwelsjochem8
  • Enthusiast

  • 96 posts
  • Corona SDK

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



[TOPIC: post.html]
#2

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

Hi @pouwelsjochem8,

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

 

Best regards,

Brent



[TOPIC: post.html]
#3

pouwelsjochem8

[GLOBAL: userInfoPane.html]
pouwelsjochem8
  • Enthusiast

  • 96 posts
  • Corona SDK

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.

[TOPIC: post.html]
#4

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

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.



[TOPIC: post.html]
#5

pouwelsjochem8

[GLOBAL: userInfoPane.html]
pouwelsjochem8
  • Enthusiast

  • 96 posts
  • Corona SDK

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?




[topic_controls]
[/topic_controls]