After many research I didn't find the answer, when I'm trying to display object in pygame with pytmx, the result is fully broken, because x, y change with rotation. I've tried to use matrix rotation but for this, I need to know the original center. I don't know how to find it, because Tiled sends me, x, y after rotation...
So my goal is simply to display object tile in pygame with pytmx.
import numpy
import math
angle = math.radians(-117.57) #rotation get with tiled, set - for cancel rotation
center_x = 148 #how to get this ?
center_y = 747 #and this
x = 126.82 #get with tiled
y = 679.54 #get with tiled
id_rotation = [ [math.cos(angle), -math.sin(angle)],
[math.sin(angle), math.cos(angle)] ]
R = numpy.matrix(id_rotation)
id_position = [ [x - center_x],
[y - center_y] ]
B = numpy.matrix(id_position)
id_center = [ [center_x],
[center_y] ]
C = numpy.matrix(id_center)
print(numpy.dot(R, B) + C) #return original position before rotation
If I only use pygame.transform.rotate:
if isinstance(layer, pytmx.TiledObjectGroup):
for object in layer:
if (object.image):
assets_surface = pygame.Surface((object.width, object.height), pygame.SRCALPHA)
assets_surface.blit(object.image, (0, 0))
assets_surface_rotate = pygame.transform.rotate(assets_surface, -object.rotation)
rdc.blit(assets_surface_rotate, (object.x, object.y))
I get this the wrong position x,y for tile object:
Ok I have found the solution if someone needs :