By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,362 Members | 1,285 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,362 IT Pros & Developers. It's quick & easy.

Pygame issue while using scrolling to "zoom in/out".

Jory R Ferrell
P: 62
i am attempting to use the scroll wheel to enlarge or shrink everything on the screen. But after I enlarge the images and try to shrink them, the images disappear completely and I can no longer "scroll in". Obviously I am not updating everything correctly, but I'm not sure what I did wrong.

Also, I can't scroll in more than once...I was under the impression that I could make multiple calls to the function the way it's written, and each call would reassign something to the width and height. This is not happening. I suspect again because I am not updating the images correctly?

Expand|Select|Wrap|Line Numbers
  1.  
  2. background_image_filename = 'C:\Users\office\Documents\Portable Python 2.7.2.1\App\Background.jpg'
  3. sprite_image_filename = 'C:\Users\office\Documents\Portable Python 2.7.2.1\App\Neuron_On_2.png'
  4. sprite_image_filename_2 = 'C:\Users\office\Documents\Portable Python 2.7.2.1\App\Neuron_Off_2.png'
  5.  
  6. import pygame
  7. from pygame.locals import *
  8. from sys import exit
  9.  
  10. pygame.init()
  11.  
  12. screen = pygame.display.set_mode((600, 600), 0, 32)
  13.  
  14. background = pygame.image.load(background_image_filename).convert()
  15.  
  16. sprite = pygame.image.load(sprite_image_filename).convert_alpha()
  17. sprite_2 = pygame.image.load(sprite_image_filename_2).convert_alpha()
  18. display_Sprite = sprite_2
  19. clock = pygame.time.Clock()
  20.  
  21. # The x coordinate of our sprite
  22. x = 290.0
  23. y = 290.0
  24.  
  25. h = 0
  26. w = 0
  27.  
  28.  
  29. while True:
  30.     for event in pygame.event.get():
  31.         if event.type == QUIT:
  32.             pygame.quit()
  33.  
  34.         pressed_mouse = pygame.mouse.get_pressed()
  35.  
  36.         if pressed_mouse[0]:
  37.             newX, newY = pygame.mouse.get_pos()
  38.             x = newX
  39.             y = newY
  40.             display_Sprite = sprite
  41.             pygame.display.update()
  42.  
  43.         if not pressed_mouse[0]:
  44.             display_Sprite = sprite_2
  45.             pygame.display.update()
  46.  
  47.         if event.type == pygame.MOUSEBUTTONDOWN:
  48.             print event.button
  49.             w, h = sprite.get_size()
  50.             if event.button == 4:
  51.                 sprite = pygame.transform.scale(sprite, ((w/100)*150, (h/100)*150))
  52.                 sprite_2 = pygame.transform.scale(sprite_2, ((w/100)*150, (h/100)*150))
  53.             elif event.button == 5:
  54.                 sprite = pygame.transform.scale(sprite, ((w/100)*90, (h/100)*90))
  55.                 sprite_2 = pygame.transform.scale(sprite_2, ((w/100)*90, (h/100)*90))
  56.  
  57.             pygame.display.update()
  58.  
  59.  
  60.     screen.blit(background, (0,0))
  61.     screen.blit(display_Sprite, (x-w/2, y-h/2))
  62.  
  63.     clock.tick(120)
  64.  
  65.  
Mar 7 '12 #1
Share this Question
Share on Google+
1 Reply

Jory R Ferrell
P: 62
Nevermind on the updating each time I scroll. For some reason the image won't scale any longer past just a certain size. I started with larger images and it's scrolling fine...till I hit a threshold. I Still don't know why that is.

Again, I just need to figure out why the image disappears past a certain size (only does it when shrinking).
Mar 7 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.