Python Forum
How to make an image move in relation to another in PYGAME - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: How to make an image move in relation to another in PYGAME (/thread-35502.html)



How to make an image move in relation to another in PYGAME - CompleteNewb - Nov-10-2021

I'm trying to make a boat in pygame. I have two image: a boat and a tiller. The tiller can rotate around an axis at the back of the boat using the button left and right and the boat can move around the screen and rotate. My problem is that the two are separate(i load one image and then the other). Is it possible to make an object(oop) of a boat that when I call and rotate the two image act as one? If so how?


RE: How to make an image move in relation to another in PYGAME - metulburr - Nov-10-2021

Set the tiller offset to a fixed point off the boat. Then move the boat around. This can be done by creating a boat class. Which will make it a lot easier to pass data back and forth.

Psuedocode...
boat_rect = boatimage.get_rect()
Tillerrect = boat_rect.center() #modify center to specific locations
Move boat_rect coordinates and the tiller will move too