Python Forum
[PyGame] I found a way to generate sprites without .blit. Is it effecient?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] I found a way to generate sprites without .blit. Is it effecient?
#12
There's a lot going on in that code lol. If it works, that's cool, but I'd like to offer some notes for the next project:
1) try to stick to a single event loop. The snake game has 6. https://gameprogrammingpatterns.com/game-loop.html
2) I'd recommend looking into State Machines to help control what the game should be doing at any given point in time. A Menu-State, Game-State, PauseScreen-State, etc. That will help with having just one event loop, and will also help with keeping the call stack down (what I mean by that is, you don't currently use while loops for repeating events... if you PlayAgain 20 times, you've added 20 things to the callstack when really that should have been 0). I don't think this would actually help with performance, but it'd help make the code much cleaner to look at, which then makes it significantly easier to add features or fix bugs. https://gameprogrammingpatterns.com/state.html
3) Personally, I hate the fact that there's a quit() function available in python. The program ends just fine when it reaches the end of the file, and things are easier to understand without sudden exits like that. You could just as easily replace all the quit() calls with a return statement, which has the added benefit of syntax highlighting in editors, so it sticks out a bit more. Plus, it helps with debugging when you can unwind what's happening, instead of the program just killing itself lol.
4) I also personally hate global variables. But a lot of that might just clean itself up if you switch the control flow to use a state machine.
Reply


Messages In This Thread
RE: I found a way to generate sprites without .blit. Is it effecient? - by nilamo - Dec-06-2019, 02:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pygame, sprites, and rects menator01 12 7,364 Dec-07-2023, 02:37 AM
Last Post: Benixon
  [PyGame] Sprites just randomly appear and dissapear in my pygame.sprite.GoupeSingle trueShadoWrr 2 3,434 Feb-13-2023, 09:34 AM
Last Post: Vadanane
  [PyGame] pygame blit() method syafiq14 1 6,806 Oct-30-2020, 04:46 PM
Last Post: Russ_CW
  index error when using lists to blit rotated images codefun45 7 5,348 Sep-03-2020, 11:11 PM
Last Post: codefun45
  moving image with blit rwahdan 2 4,074 Jul-10-2019, 06:24 PM
Last Post: nilamo
  [PyGame] Having 4 players(Sprites) all being able to jump ElijahCastle 5 5,320 May-07-2019, 05:04 PM
Last Post: SheeppOSU
  Sprites and Actor error ajlconsulting 6 12,539 Jan-30-2019, 12:50 AM
Last Post: metulburr
  draw not showing all sprites ethanstrominger 0 3,216 Jan-25-2019, 10:10 PM
Last Post: ethanstrominger
  error with survace.blit joemcsk1 3 5,939 Aug-06-2018, 12:23 AM
Last Post: metulburr
  [PyGame] move randomly sprites reutB 4 9,858 Mar-29-2017, 01:12 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

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