ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am attempting to write a simple program to move a image across a tile background. I got it working by making everything it's own class, but it was too much typing. I read and reread the moveit program and the docs for it and tried to splice it into my own. I get either a background and no player or i get a background with an error:
Traceback (most recent call last):
File "F:\PYGA\backgroundworks.pyw", line 78, in ?
if __name__ == '__main__': main()
File "F:\PYGA\backgroundworks.pyw", line 75, in main
heros.draw(screen)
File "D:\PROGRA~1\PYTHON~1.2\Lib\site-packages\pygame\sprite.py", line 459, in draw
surface_blit(s.image, s.rect)
TypeError: invalid destination position for blit
Here's the program.
import os, sys
import pygame
from pygame.locals import *
global playerpos
playerpos = 2
#Taken from moveit.py, using it because it works
def load_image(name):
path = os.path.join('data', name)
return pygame.image.load(path).convert()
I removed the Player class and everything that dealt with it and was able to get the background. I slowly added the Player class and ran the program with no errors, and then added the heor.update() and heros.draw(screen) after blitting the screen. I get the following error:
Traceback (most recent call last):
File "D:\WINDOWS.000\Desktop\pygame short\background_w_player.py", line 71, in ?
if __name__ == '__main__': main()
File "D:\WINDOWS.000\Desktop\pygame short\background_w_player.py", line 67, in main
hero.update()
File "D:\PROGRA~1\PYTHON~1.2\Lib\site-packages\pygame\sprite.py", line 323, in update
s.update()
File "D:\WINDOWS.000\Desktop\pygame short\background_w_player.py", line 28, in update
self.rect.topleft = 32, 0
TypeError: 'Surface' object has only read-only attributes (assign to .topleft)
Removing the hero.update() gives me the error posted in my first post. One more thing, I am using whitespace it just wasn't posted.
Does anyone have any idea about what is wrong with the above. If it will help I can post the orignal program that works but it is long (about 114 lines). If you know any sites to visit for information it would be appreicated. I read the tutorial sfor pugame and python and am understanding the stuff but I need to use them to grasp them hence this program. It may not be much but it's a start to learning something new and different.
It takes a while to see your post, and for the replies to come in, but the literal experts on the language post there frequently, and there's plenty of help to be found.
I haven't done anything serious with classes yet, or with graphics, so sorry I'm not much help. Hopefully, that link will help, though.
Thanks for the reply. I got the program working but I still have no idea why it doesn't work. I added another def to load images using a short form of the orignal format and used it to load the background.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.