How can i get objects to update their positional data after their instantiation.

edited April 2017 in How To...

Hi folks! I have created a simple button class which changes colour when the mouse is over it and when it clicks. i have implemented the surface.setResizable(true); function and am having difficulty updating the buttons position when the window changes size. i instantiate the class and give it the x and y positional coordinates. all goes well until i resize the window and the button doesn't react despite the coordinates being in reference to the width and height of the window. So it seems that the coordinate data is given to the object upon instantiation but is not updated which makes it unable to update its coordinates according to the newly resized window. I can get around this by adding a function in the class which references the specific coordinates of the object and updates within draw continuously but this of course makes the reusable nature of the class pointless because i am required to put the individual objects locations in it. so my question is: How can i get objects to update their positional data after their instantiation. I hope this makes sense and any help would be much appreciated. Thanks! Danny.

Answers

  • edited April 2017

    Hi i fixed it by referencing the object from the draw loop as in button.x = width/2. Is there a way to achieve this from inside the class so that it automatically updates itself? as i mentioned before the position with reference to the width is given in instantiation but this is not constantly updated.i tried making an internal function of x = x (referring to the x value i initially gave) but this did not work...thanks

  • I haven't done this, but it seems like it should be possible as libraries can do it
    https://github.com/processing/processing/wiki/Library-Basics#library-methods

Sign In or Register to comment.