Page 1 of 1

[SOLVED] Why doesn't "drag_raise" work when using a loop?

Posted: Tue Oct 25, 2022 3:51 am
by span4ev
I draw objects through a loop.
"circles" is a list with the objects of the class. Each object has 2 attributes: picture and position, so in "i.img pos i.pos" I just specify which picture to take and where to place it.

Code: Select all

for i in circles:
    draggroup:
        drag:
            image i.img pos i.pos
            drag_name   i
            drag_raise  True
but "drag_raise" is not active because the images do not overlap each other, unlike the situation where I explicitly specify each object:

Code: Select all

draggroup:
    drag:
        image img
    drag:
        image img
    drag:
        image img
As I understand it, I don't even need to explicitly specify drag_raise = True, because this is already assigned when creating the instance: class Drag(drag_raise=True)
So it should work by default until I set drag_raise = False

I'm wondering what's going on here?

Code: Select all

drag:
	img # ?
Am I creating an instance of a class (displayed object) that is linked to img?

If I use:

Code: Select all

draggroup:
	drag:
		img 
Then instances of the Drag class become instances of the DragGroup class, as if:
class Drag(DragGroup) ?

But I don't understand how I can refer to Drag and DragGroup instances. I don't know the names of these instances.
Perhaps can somehow explicitly specify the attribute "top = True" or call the method "raise_children" for each active object?

Code: Select all

init python:

    circles             = []


    class Circle:

        def __init__(self, img, pos):

            self.img            = img
            self.pos            = pos


    def create_circles(c, x, y, z):

        for i in range(3):
            for k in range(4):
                circles.append(Circle(c, (x, y)))
                x += field_block * 2
            y += field_block
            x = start_pos if i != z else offset_x

    def draw_obj():
        
        b = Transform('images/black.png', size=(img_sizes)
        w = Transform('images/white.png', size=(img_sizes)

        circles.clear()
        create_circles(b, start_pos, start_pos, 0)
        create_circles(w, offset_x, start_white_pos_y, 1)

screen:

    $ draw_obj()

    frame:

        for i in circles:
            fixed:
                drag:
                    child i.img pos i.pos
                    drag_name   i
                    drag_raise  True
The objects overlap each other only in order of creation, that is, the most recently created object will overlap all others, and the first one created in the loop cannot overlap anyone.
I also call the function for creating objects 2 times (white and black figures). It turns out that all objects that were created in the second function (white shapes) overlap those created in the first function (black shapes).

But that shouldn't matter, because in the function I just create instances of the class and give them parameters: an image and a position. Then I put them in one common list.
Then I draw pictures in the loop and take the picture of the desired color and position from the common list. But I don't understand why the objects created in the second function (white) are dominant... as if they get into 2 different DragGroups. Maybe different pictures are in different groups?

Re: Why doesn't "drag_raise" work when using a loop?

Posted: Tue Oct 25, 2022 4:11 am
by Ocelot
In your firs piece of code you are creating a unique draggroup for each drag. drag_raise only works for entities in the same draggroup.

Re: Why doesn't "drag_raise" work when using a loop?

Posted: Tue Oct 25, 2022 4:25 am
by span4ev
Ocelot wrote:
Tue Oct 25, 2022 4:11 am
In your firs piece of code you are creating a unique draggroup for each drag. drag_raise only works for entities in the same draggroup.
My goodness... You're right... I missed that. I had already started trying to find a list of instances of the class (whose names I don't know), and it turned out to be so simple.

Thank you very much.