1
\$\begingroup\$

Im trying to simulate shadows in a 2d RPG, So far I can make the shadows but i cant blit them properly, Im trying to rotate them according to where the "sun" is (just a position)

I have looked at other questions, they say to move the center of the image to the point rotate it then move it back so that what I'm trying to do

here is my code to rotate it:

def rotate(self, shadow, rect):
    copy = rect.copy() #get copy of rect
    angle = degrees(atan2(self.center[0]-self.sun[0], self.center[1]-self.sun[1]))-180 #get angle from "sun" to center of screen

    if angle < -180:
        angle += 360

    angle /= -5

    rect.center = copy.midbottom #move rect to rotation point
    shadow = rotate(shadow, -15) #rotate -15 as a test
    rect.center = copy.center # move it back

    return shadow, rect #return the image and rect to blit them

when the angle is negative it seem like its working and I get this result (which isnt really what I want):

Negative angle

but when I rotate it positively:

positive angle

so I think I'm doing this totally wrong! I've been trying to figure it out for awhile now, I think I'm blitting it wrong, or not at the right state

\$\endgroup\$
1

1 Answer 1

1
\$\begingroup\$

I don't know pygame and how blitting works there but it seems that you translate rect but rotate shadow. Are you sure that's right?

Also, for this kind of effect I'd use a shear transformation rather than a rotation.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .