What does "it doesnt draw very well" mean? Most of the time laggy operations in pygame result to bottlenecks in your own code. The following is probably not enough to create those issues, but indeed shows that there are bottlenecks in your code. This is not very resource intensive, but things like this sporadically throughout your code can make it laggy.
The following is however resource intensive....
Your screen fill is on every draw method of that object. I can see why you need it, however it is drawing the entire background every frame and every object (regardless of whether its being moved or not). So if you have a 1000 objects on screen, you are separately drawing the background 1000 times per frame, when you only need it when drag and dropping. I would determine if an item is being dragged and only while that is occurring, fill the screen in. Also there are methods for reducing CPU usage including dirty rects and pygame.display.update to only update portions of the screen.
It would be much helpful to view your full code.
It would also be helpful to use pygame rects, instead of handling positioning of drawing. There are magic numbers everywhere.
Quote:The draw methods should only do that....draw things. Not handle logic. For every object that is being drawn you are wasting resources by obtaining the mouse position for every object. This is not needed. You only need to obtain the mouse position once per frame, not per object. The mouse position will not change in the same frame, so you can pass the same mouse position down to all your objects.def draw(self): if self.slot == None: #item's slot number mouse = pygame.mouse.get_pos() pos = [mouse[0] - 25, mouse[1] - 25] #Center the thumbnail on the mouse else: pos = self.CalculatePos() #Get positions from the slot number Screen.blit(PD[self.weapon + 'Thumbnail'], pos)
The following is however resource intensive....
Your screen fill is on every draw method of that object. I can see why you need it, however it is drawing the entire background every frame and every object (regardless of whether its being moved or not). So if you have a 1000 objects on screen, you are separately drawing the background 1000 times per frame, when you only need it when drag and dropping. I would determine if an item is being dragged and only while that is occurring, fill the screen in. Also there are methods for reducing CPU usage including dirty rects and pygame.display.update to only update portions of the screen.
It would be much helpful to view your full code.
It would also be helpful to use pygame rects, instead of handling positioning of drawing. There are magic numbers everywhere.
Recommended Tutorials: