PyDew-Valley icon indicating copy to clipboard operation
PyDew-Valley copied to clipboard

find a bug from code s12

Open JanXuan opened this issue 1 year ago • 9 comments

Hi, 😄 it's obvious that you have created a very interesting project. I have learned a lot about pygame and game development from it. When I followed your tutorial S12: Particles, I found a bug. When I first ran the code, chopping the tree resulted in apple and tree particle effects, which was not a problem. However, when I started this code again, no apple appeared on the tree, and chopping the tree did not result in tree particle effects, This is really bothering me T^T

JanXuan avatar Jul 30 '23 14:07 JanXuan

Oh!!, It looks like a problem with Particle objects, because when I add more particles to my code, the Particle effect may occur when obtaining apples or crops. It may be that the particles have not yet been initialized, causing exit. It may be a problem with the computer's running speed, but the bug of not having any apples on the tree has not been resolved yet

JanXuan avatar Jul 31 '23 10:07 JanXuan

I also randomly get apples being drawn below the tree sprite and I know that they're there because of print statement but it seems to be fixed now so yeah there are some weird side affects.

DaVagrant avatar Aug 14 '23 20:08 DaVagrant

I have the same bug with apples being drawn behind trees, and no particle effect being shown. The weird thing is it only happens randomly when running the game. Has anyone found out whats causing this and how to fix it?

semustache avatar Nov 26 '23 16:11 semustache

Found a fix in the YouTube comments, credits to @kinuseo1616:

I think the issue comes from using the groups() method. Try passing the self.all_sprites group into the Tree instance in the level so that you can access it in the Tree class. Instead of calling the group() method, use the all_sprites group. For some reason pygame doesn't keep the groups in the same order every time you start the game. This ensures that the apples are in the all_sprites group every time and should fix your issue

semustache avatar Nov 26 '23 16:11 semustache

Thanks!

DaVagrant avatar Nov 26 '23 22:11 DaVagrant

@semustache How do i pass the self.all_sprites to the tree class? I have trouble to do it

SaphiraSkulblaka avatar Nov 28 '23 10:11 SaphiraSkulblaka

I also am trying to figure out how to pass the self.all_sprites to trees

Thanatoscorax avatar Apr 06 '24 22:04 Thanatoscorax

Correction got it added to trees but still down have it added to particles.

Thanatoscorax avatar Apr 07 '24 00:04 Thanatoscorax

I have solved the issue by setting a variable in the tree __init__ method

self.all_sprites = groups[0]

and then the particle spawn looks like this:

Particle(
                pos=random_apple.rect.topleft,
                surf=random_apple.image,
                groups=self.all_sprites,
                z=LAYERS['fruit']
            )

Entrio avatar Apr 26 '24 17:04 Entrio