473,378 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

Jory R Ferrell
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
1 6305
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

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

Similar topics

0
by: Chumley the Walrus | last post by:
UPon a user succesfully logging in, i'm having trouble creating a "log out" link on a protected page so that users can end their session (i'm more used to classic asp with this). Below is my...
5
by: Daishi Harada | last post by:
Hi, I'd like to get the 'get2' function below to perform like the 'get1' function (I've included timeit.py results). I'm not sure how to write 'mkget' to do achieve this, however, except to...
1
by: jmev7 | last post by:
Greetings Data Gurus! I've been asked to help find and delete junk records from a database table that comes from online data request forms: you know, those annoying forms you have to fill out to...
0
by: Alex | last post by:
Dear colleagues I don't know what the LDAP attribute in active directory (windows 2000) is called which showes if an user account is locked out or not. Could you help me? My code looks like...
2
by: Usama Zulfiqar | last post by:
Hello guyz, One of my colleagues has made an upload website. We upload big data over the server via asp. Whenever I wanted to upload 5Mb file or more i receive ASP 0113 error. Is there any way...
16
by: saurabhnsit2001 | last post by:
The following program doesn't "seem" to print "hello-out". (Try executing it) #include <stdio.h> #include <unistd.h> int main() { while(1) { fprintf(stdout,"hello-out");
3
by: Bob Milutinovic | last post by:
Greetings, folks. Wondering if someone might be able to shed some light on this without my having to load up 'n test it for myself. I have a page calling another with Server.Execute, but...
1
scubak1w1
by: scubak1w1 | last post by:
OK, I have been banging my head against this all day... so any suggestions gratefully received... I am working on an employee logon section, https://, that I want to add a button to the header to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.