Getitng Widget modified values: when the widget modified values are available eg. onLoad, onStart (v.1.7) or other!


#1

@slackmoehrle, hi,
Property value modified by the widget (Align widget) could not be found by onLoad or onStart default method of cocos creator. So what is the best way to get the value modified by widget excluding update method. Cause there will be so many calculation in the update method.

Thanks in advance.


#2

Need to see some code.

Sometimes the scope can be lost depending on how you reference you methods.


#3

Thanks for the reply. I am newbie in cocos creator and have certain questions in mind while porting some of my interactive contents to cocos creator. In a scene onLoad->onStart->update(dt) executes one after another. i set widgets to left and right some percentage values. They works fine for different screen resolutions. Based on left artwork i want to place my monkey as seen in the screen for different resolution. like monkey.x = arwork.x + someOffset but both onLoad() and start() unable to get the value changed by widget attached with left artwork. I tested in update(dt) method and i get the result as i expected which i dont want! widget sample

Is there any super() call or something?


#4

It’s hard to tell without any code.

Are you adding event listeners during load or start? And do you try to read value in those event listeners?


#5

align widget is attached with the Left land.
The minimal code that can describe my problem is …

onLoad () { this.monkey.x = this.land.x },
// Not getting updated values of land

start () { this.monkey.x = this.land.x },
// update values are not here

update (dt) { this.monkey.x = this.land.x },
// here i am getting the updated values.


#6

try unchecking Align Once property of widget in your UI in cocos creator, it should do the trick for you.