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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jory R Ferrell
    New Member
    • Jul 2011
    • 62

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

    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?

    Code:
    background_image_filename = 'C:\Users\office\Documents\Portable Python 2.7.2.1\App\Background.jpg'
    sprite_image_filename = 'C:\Users\office\Documents\Portable Python 2.7.2.1\App\Neuron_On_2.png'
    sprite_image_filename_2 = 'C:\Users\office\Documents\Portable Python 2.7.2.1\App\Neuron_Off_2.png'
    
    import pygame
    from pygame.locals import *
    from sys import exit
    
    pygame.init()
    
    screen = pygame.display.set_mode((600, 600), 0, 32)
    
    background = pygame.image.load(background_image_filename).convert()
    
    sprite = pygame.image.load(sprite_image_filename).convert_alpha()
    sprite_2 = pygame.image.load(sprite_image_filename_2).convert_alpha()
    display_Sprite = sprite_2
    clock = pygame.time.Clock()
    
    # The x coordinate of our sprite
    x = 290.0
    y = 290.0
    
    h = 0
    w = 0
    
    
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
    
            pressed_mouse = pygame.mouse.get_pressed()
    
            if pressed_mouse[0]:
                newX, newY = pygame.mouse.get_pos()
                x = newX
                y = newY
                display_Sprite = sprite
                pygame.display.update()
    
            if not pressed_mouse[0]:
                display_Sprite = sprite_2
                pygame.display.update()
    
            if event.type == pygame.MOUSEBUTTONDOWN:
                print event.button
                w, h = sprite.get_size()
                if event.button == 4:
                    sprite = pygame.transform.scale(sprite, ((w/100)*150, (h/100)*150))
                    sprite_2 = pygame.transform.scale(sprite_2, ((w/100)*150, (h/100)*150))
                elif event.button == 5:
                    sprite = pygame.transform.scale(sprite, ((w/100)*90, (h/100)*90))
                    sprite_2 = pygame.transform.scale(sprite_2, ((w/100)*90, (h/100)*90))
               
                pygame.display.update()
    
        
        screen.blit(background, (0,0))
        screen.blit(display_Sprite, (x-w/2, y-h/2))
    
        clock.tick(120)
  • Jory R Ferrell
    New Member
    • Jul 2011
    • 62

    #2
    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).

    Comment

    Working...