Woo woo, question number 4! Seems simple.... change a node's (shapenode primarily) size after the fact?
I've scoured the scene module trying to find an option other than deleting the node and replacing it with an updated one which seems excessive.
If I want to update a node's position (without animation) I can simply write:
self.node.position = x, y
But if I try using self.node.size in a similar way, nothing happens. The values update (I checked with a print command) but visually nothing changes.
I imagine this has to do with the involvement of a ui.Path object to create the Shapenode in the first place but I'm not sure what to do with that potential fact. What's the most straightforward way to update a Shapenode's dimensions?
Thanks guys, I will also answer if i can
I haven't used the
scenemodule since it was updated from the render-loop version to nodes, so I can't help you with your main problem. But just a small thing about tuples and assignments. In Python, the lines
name = a, band
name = (a, b)do exactly the same. When assigining a tuple, it makes no difference if you use parens or not, because there's no other way that the operator precedence could work out. (Assignment is not an expression in Python, so
(name = a), bis invalid syntax and cannot happen by accident.)
In many other cases you need parens around tuples though, for example when calling a function, or when concatenating tuples with
+. For example
1, 2 + 3, 4will result in the tuple
(1, 5, 4), and
(1, 2) + (3, 4)will result in
(1, 2, 3, 4). Personally I almost always put parens around tuples just to be sure.
Assigning to the
sizeattribute of a
ShapeNodeshould work, with or without parentheses around the (x, y) value. I don't know why it didn't at first, I'd have to see the full code to know if this was due to some bug in the
scenemodule or something else.
As you've seen though, the shape gets distorted when you assign a different size. The reason is basically that a
ShapeNodeis a pretty simple subclass of
SpriteNode. The only difference is that a
texturefrom a vector path instead of an image file. But once the texture is generated, it behaves just like any other bitmap, i.e. you can't scale it without getting a blurry image or distortion.
I would assume user-error for now on my earlier attempts... Lord knows I make enough of them!
I know I'm cross-threading now but interestingly, I've had another error go away: when I asked about the modal_scene issue, and the last comment I made was that I got it to work but it was still throwing the same error into the console at the same time. Well, as I kept working that just randomly stopped eventually. I was adding things (more nodes and tweaking things) to the modal scene so based on your original comment that's likely related I suppose?
EDIT: on the subject of bugs, I'm assuming this is one: I have a codebase that works 100% fine at the moment, but when I try adding a new method to one of my classes it's throwing me an indentation error. I made it as simple as possible so there's nothing I could have screwed up... it's the most basic method I could create, it contains one print comment, I'm not calling it anywhere, I added the colon at the end of the definition... but it gives me the indentation error. Comment out those two lines of code though and it runs like a charm again.
You might be mixing tabs and spaces by accident. In the Pythonista settings, try enabling "Show Mixed Indentation", then the indent type that is not your default will be highlighted. In a single file, you should only use one type of indentation, and always the same number of spaces/tabs for one indentation level.
My indentation has been very consistent (only using tab) but I think I figured it out sort of. I neglected to mention that I actually got my project up and running in X-Code and I'm pretty sure that's what was causing trouble. I messed with the "intelligent indenting" preferences a little bit and the problem hasn't come back so far.
@WTFruit When you're editing Python code in Xcode, I would recommend never to use the regular "Paste" command – always use "Paste and Preserve Formatting". Xcode's automatic re-indentation fails spectacularly with Python code.
@omz Yeah I noticed that - never realised there was an option to paste with preserved formatting! Had to turn on 'show invisibles' and delete all the spaces that had appeared!
https://atom.io is a wonderful editor that I highly recommend. If you add the package
linter-flake8, Atom will catch indentation issues and a multitude of other errors in your Python code in realtime as you type! I find that it consistently saves me several run-and-crash cycles on Mac, Windoze, and Linux. See the video at https://atom.io/packages/linter-flake8