As you can see, on the first click of the button when buttonState is 0, the animation works fine but on the second click when buttonState is 1, the StencilAttrib doesnāt update although all the functions are executed.
I know the code might be a bit messy, but what can I do to get the result I expect? and any suggestions for cleaner code would be much appreciated
Looking at your code, when you create a new āviewingSquareā, I donāt see anything removing the previous āviewingSquareāācould it simply be that your old squares are obstructing your new ones?
[edit]
Also, if Iām reading this correctly, you only ever create āanimā once, since the code that does it doesnāt appear to be in a function or method. Thus you presumably just restart the same anim, created with a ābuttonStateā of 0, over and over.
If Iām correct, I would suggest perhaps moving that code into the ābuttonCommandā function.
[edit 2]
As to cleaner code⦠I think that much of this comes down to what works for you.
For myself, I prefer to keep just about everything in a class. That seems to me to keep things much neater and clearer than having code all over the place.
However, if a more function-and-global-based approach works for you, then I say stick with it!
I changed the second click to make the stencil grow bigger instead of smaller to test your observation and you were right! The old stencil was blocking out the new. Only thing is now is how do I remove āself.viewingSquareā?
ps: sorry for the rookie questions, Iām developing my first app so itās a slow process
Simply call the āremoveNodeā methodāsomething like this: āself.viewingSquare.removeNode()ā.
There are two caveats that occur to me:
First, donāt attempt to use a NodePath that youāve removed; it will presumably no longer be valid.
However, in this case I imagine that youāll be immediately creating a new NodePath and storing it in the variable that held the old NodePath, so this might not be a problem!
Second, if you havenāt yet created a variable called āviewingSquareā, you will presumably hit a Python error.
To prevent this, it might be worth creating the āself.viewingSquareā variable at some point before your first call to ācreateViewā (perhaps in the āStencilā classās constructor?). Since at this point you havenāt yet created the actual square, you might give it a value of āNoneā, and then check for that before attempting to remove the NodePath.
Donāt worry about it! It seems only reasonable to me that someone new to an activity might have questions regarding the basics.
By the way, may I suggest my Panda tutorial? It should take you through the process of creating a very simple gameāwith source codeāfrom a discussion of the basics of using Panda to building a distributable application. If youāre interested, you should find it here:
Yess that works perfectly, thank you once again
Iām defining self.viewingSquare straight after I remove it so that works fine, and also Iām checking if it exists before trying to remove with
if hasattr(self,'viewingSquare'):
Oh wow Iāll definitely go through that before continuing! Wish I had found that when I first started learning. It would be great if there was a link to that tutorial at the end of https://www.panda3d.org/manual/?title=Tutorial_End. I personally wouldāve found it very helpful
That would be nice, perhaps, but I suppose that, since itās a community tutorial (as Iām not one of the Panda devs), itās not an āofficialā part of Panda, and hence not in the official manual.