Python Forum
[PyGame] Particle movement mystery
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Particle movement mystery
#3
(Jul-05-2022, 01:29 AM)Windspar Wrote: First I would not use a keyword to store variables. _dir over dir.
Second print self.pos, self.dir out during update. Make sure data is right.

Other improvements.

pygame.Vector2 where made for this. Understanding the basic we take care of a lot math. They are always floats.
vector = pygame.Vector2()
vector.from_polar((1, angle))
To give more control over random. Create different list. Then use random choice.
explosion_data = [list(range(1, 30)), list(range(32, 60))]
# in explosion
for particle in explosion_data:
    angle = random.choice(particle)
    vector = pygame.Vector2()
    vector.from_polar((1, angle))
pygame.sprite.Spirte and pygame.sprite.Group can handle your particles. They are a built in framework. They also work faster. I give example later.

For some reason, I thought pygame groups were more resource intensive, I'll certainly change that. The .pos I use is already a pygame vector2, as is vec(), I just imported it as vec for brevity. I also really like the idea of storing the random data as a list rather than calculating it a million times.

I'll implement your suggestions later today and see what I find. Thank you.
Reply


Messages In This Thread
Particle movement mystery - by XavierPlatinum - Jul-04-2022, 05:37 PM
RE: Particle movement mystery - by Windspar - Jul-05-2022, 01:29 AM
RE: Particle movement mystery - by XavierPlatinum - Jul-05-2022, 03:46 PM
RE: Particle movement mystery - by Windspar - Jul-05-2022, 10:47 PM
RE: Particle movement mystery - by XavierPlatinum - Jul-06-2022, 05:04 PM
RE: Particle movement mystery - by Windspar - Jul-06-2022, 08:11 PM
RE: Particle movement mystery - by XavierPlatinum - Jul-06-2022, 09:28 PM
RE: Particle movement mystery - by Windspar - Jul-06-2022, 09:34 PM
RE: Particle movement mystery - by Windspar - Jul-07-2022, 12:56 AM
RE: Particle movement mystery - by XavierPlatinum - Jul-07-2022, 06:01 PM
RE: Particle movement mystery - by deanhystad - Jul-09-2022, 04:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Laggy Game Movement game_slayer_99 12 4,916 Oct-05-2022, 11:34 AM
Last Post: metulburr
  [PyGame] Isometric Movement on Tiled Map Josselin 0 2,513 Nov-02-2021, 06:56 AM
Last Post: Josselin
  [PyGame] object's movement to left leave shadow on the screen Zhaleh 3 3,333 Aug-02-2020, 09:59 PM
Last Post: nilamo
  Using classes for room movement (text game) Lawr3y 3 6,751 Aug-20-2019, 12:40 AM
Last Post: Lawr3y
  Problem with coding for movement keys Aresofthesea 3 3,598 Jul-05-2019, 07:05 PM
Last Post: nilamo
  Pygame Movement X/Y coord TheHumbleIdiot 2 3,690 Mar-19-2019, 02:21 PM
Last Post: TheHumbleIdiot
  Movement after KEYUP, only after pause func esteel 2 3,399 Aug-22-2018, 03:03 PM
Last Post: Windspar
  [PyGame] How to stop the sprite's movement when it touches the edges of the screen? mrmn 5 11,993 May-13-2018, 06:33 PM
Last Post: mrmn

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020