clear-code-projects / PyDew-Valley

Proejct files for a Stardew Valley inspired game in Python
461 stars 171 forks source link

find a bug from code s12 #8

Open JanXuan opened 1 year ago

JanXuan commented 1 year ago

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 commented 1 year ago

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

DaVagrant commented 1 year ago

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.

semustache commented 9 months ago

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 commented 9 months ago

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

DaVagrant commented 9 months ago

Thanks!

SaphiraSkulblaka commented 9 months ago

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

Thanatoscorax commented 5 months ago

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

Thanatoscorax commented 5 months ago

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

Entrio commented 4 months ago

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']
            )