Can Someone Turn This Script Into a ‘Node’ Tutorial, Please?
ccc last edited by
I provided a pull request that does not yet move to Nodes but removes xrange(). This allows the cards to be displayed (in the wrong places) in Python 3.
enceladus last edited by enceladus
Not tested well. Seems to work fine. Hopefully gives an idea on how to implement with nodes.
@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.
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.
ccc last edited by ccc
The puzzle is that in Python 2 the cards are all properly aligned but in Python 3 they are staggered.
Phuket2 last edited by
@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
divmodlets 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.