Python Forum
[PyGame] Help with blitting and events
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Help with blitting and events
#2
(Nov-04-2018, 09:04 PM)elxleon42 Wrote: What I am attempting to do is have the Bomb image populate when the mouse clicks.
This can be achieved with a flag. A flag is just a boolean variable that is determined to draw the image or not.

Originally it will be set to False.

the event would change the flag:
    for event in pygame.event.get():
        if event == pygame.MOUSEBUTTONDOWN:       #I've had this event below the quit event
            draw_image = True
then in your render section (next to oceanSprites draw)
if draw_image:
    bombSprites.draw(screen)
oceanSprites.draw(screen)
hplaneSprites.draw(screen) 
Note that only the bomb images are in the if condition. You dont want to ever draw in the event loop as it only sometimes occurs.


(Nov-04-2018, 09:04 PM)elxleon42 Wrote: I had an idea to create a different loop specifically for the mouse click event, but was unsure how to implement that within the game loop.
There should only ever be one game loop. Creating more loops will make your code into spaghetti.

If you want you can check out our pygame tutorials. It does go into these types of explanations. https://python-forum.io/Forum-Game-Tutorials

Quote: self.blit = (self.image, self.rect) #is this correct for blitting?
it would be screen.blit(self.image, self.rect) because you are passing screen to draw the image in the class' render method. Although i must admit i dont really use pygame.sprite.Sprite much to know the proper method they use. I usually make my own.
Recommended Tutorials:
Reply


Messages In This Thread
Help with blitting and events - by elxleon42 - Nov-04-2018, 09:04 PM
RE: Help with blitting and events - by metulburr - Nov-04-2018, 11:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [pygame] Blitting armor and weapons with inventory SheeppOSU 3 2,914 Apr-29-2019, 02:31 AM
Last Post: SheeppOSU
  [PyGame] Beginner in pygame, I don't know how to use events Erepiv1 5 6,464 Jan-26-2018, 08:59 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