Python Forum
[PyGame] Particle movement mystery
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Particle movement mystery
#11
Assignment of mutable objects should always set off warning bells. This does not create a copy, it assigns two variables to reference the same vector.
self.vector = vector
And as you now know, you ended up with all your particles referencing the same vector object.

Using assignment with non-mutable values is fine. Being non-mutable means the underlying value cannot be changed elsewhere without your knowledge. However, when you are working with lists or dictionaries, make sure that "=" is doing what you want. If you really just want a local variable that references the same object as another variable, fine, use assignment, but if you want your own unique copy, a copy has to be made.
XavierPlatinum likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Laggy Game Movement game_slayer_99 12 4,406 Oct-05-2022, 11:34 AM
Last Post: metulburr
  [PyGame] Isometric Movement on Tiled Map Josselin 0 2,378 Nov-02-2021, 06:56 AM
Last Post: Josselin
  [PyGame] object's movement to left leave shadow on the screen Zhaleh 3 3,164 Aug-02-2020, 09:59 PM
Last Post: nilamo
  Using classes for room movement (text game) Lawr3y 3 6,603 Aug-20-2019, 12:40 AM
Last Post: Lawr3y
  Problem with coding for movement keys Aresofthesea 3 3,486 Jul-05-2019, 07:05 PM
Last Post: nilamo
  Pygame Movement X/Y coord TheHumbleIdiot 2 3,532 Mar-19-2019, 02:21 PM
Last Post: TheHumbleIdiot
  Movement after KEYUP, only after pause func esteel 2 3,301 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,637 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