Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Can Someone Turn This Script Into a ‘Node’ Tutorial, Please?
-
Not tested well. Seems to work fine. Hopefully gives an idea on how to implement with nodes.
https://gist.github.com/168e93ca05f213124f1aec4c329d9c73 -
@ccc I’ve, too, dabbled with swapping xrange(len(images)) for range(0, len(images)) in an attempt to produce an equivalent outcome, However, the output always seems to positions the cards in somewhat of an “ascending staircase” pattern... I have no idea as to why. Hah
-
@enceladus Now that is a great starting point! Thank you for your timly response and contribution! I’ve definitely enjoyed looking through your scripting style and techniques. Do you know why the cards refuse to be in the center of the screen? I attempted making the cards once myself, out of Nodes, and I was unable to get them center as well. I roughly used the same exact logic that rcruz used with his Layers format of the cards, and they always seem to favor a more low-left output... No idea why...
-
Try looking at the anchor_point -- I forget the default, but you can make the X,y refer to a corner, or center.
-
@ccc I reviewed your PR and approved it; thank you for the pro tips and etiquette!
-
@JonB The default is definitely the center of the sprite, that’s why it doesn’t make sense that the same logic to center the layer objects wouldn’t work for the node objects.
-
The andhor point just says what part of the node your are placung with
position
. But the coordinate system of the parent which you place into is always based in the corner. so, if you are trying to create a grid, using corner coordinates probably makes more sense, or else, you need to reference everything to the center, and use vector addition.i.e
center=parent.bbox.size/2.0 #(w/2, h/2) somenode.position = center + Vector2( j*colwidth, i*rowheight)
where i,j are row/col, as measured from the center.
-
The puzzle is that in Python 2 the cards are all properly aligned but in Python 3 they are staggered.
-
@ccc , its the / operator , need the // version in py3.x
for i, front_image in enumerate(self.front_images): x, y = i%5, i//5
-
fwiw, i always forget this, but
divmod
lets you do both in one operation:y,x = divmod(i, 5)
-
@Phuket2 Wow, that definitely solved the alignment issue! But OP is still hoping someone can convert this memory card game into a “Tutorial.” Maybe in the same format as the Alien Game that Ole provided within the examples of Pythonista.