[SOLVED] sprites and zorder

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

[SOLVED] sprites and zorder

#1 Post by Milkymalk »

When I tried to make a minigame, I came into contact with the sprite manager for the first time. So far it's nice, everything works except for one thing: This darned sprite.zorder !!!

Code: Select all

                if ballclicked >= 0 and y >=100 and y < 100+ball_h:
                    ball_kill(ballclicked)
                    bcolor = renpy.random.randint(0,ballcolors-1)
                    balls_color.append(bcolor)
                    balls_sprites.append(balls.create(ballpic[bcolor]))
                    balls_sprites[number_balls-2].zorder = 1
                    balls_sprites[number_balls-1].zorder = 0
                    balls_sprites[number_balls-1].y = 100
                    balls_sprites[number_balls-1].x = ball_xoffset+(number_balls-1)*ball_w
Ok, what happens here:
ballclicked is a theoretical ball that was clicked, calculated using mouse coordinates. The game then checks whether there is actually a ball to be clicked at that position.
If there is one, delete it (first line of the block) and then create another ball at the end of the line.
When there is a vacancy, all balls to the right of it are moved left so to make room for a new ball on the right. This happens in the update function.
Now I want the new ball to appear BEHIND the old rightmost ball so I manipulate the zorder of the rightmost ball and the one left to it, but it does nothing. The new ball seemingly randomly appears in front or behind the old ball and I don't get why.
Last edited by Milkymalk on Mon Jul 21, 2014 8:19 am, edited 2 times in total.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: sprites and zorder

#2 Post by Asceai »

you don't appear to be updating number_balls in that code. Does it have the right value after balls_sprites.append?

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: sprites and zorder

#3 Post by Milkymalk »

number_balls is fixed. It's just the length of the balls sprite list, so I can change it in one place when I want to use more balls. It's only "incorrect" between deleting a ball and appending the next one, which is a few lines shown here.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: sprites and zorder

#4 Post by Milkymalk »

Here is the complete thing, with images.

You can do:

Click a ball: the ball disappears, the remaining balls slide left, a new ball is created on the right.

Click in the lower portion of the screen: Generate a new line of balls
Attachments
game.rar
(133.29 KiB) Downloaded 35 times
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: sprites and zorder

#5 Post by Asceai »

Testing this, the new ball always appears behind the rightmost ball. Isn't this what you want?

Perhaps try updating your version of Ren'Py.

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: sprites and zorder

#6 Post by Milkymalk »

Asceai wrote:Perhaps try updating your version of Ren'Py.
Yes, that did the trick :D Thank you!

The funny thing is, I usually use the newest release, but I did this on an old machine that still had the old version on it.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

Post Reply

Who is online

Users browsing this forum: Ocelot, piinkpuddiin, snotwurm