![pygame image convert alpha pygame image convert alpha](http://i.stack.imgur.com/Z6orA.png)
One to track whether your player is jumping or not, determined by whether or not your player sprite is standing on solid ground.You must add two new variables to your Player class: Once the player sprite is jumping, then gravity is applied to the player sprite again, pulling it back down to the nearest object.
![pygame image convert alpha pygame image convert alpha](https://img-blog.csdnimg.cn/20190817125054339.gif)
First, you must establish variables for the player sprite so that Python can track whether or not the sprite is jumping. But once you hit the peak of your jump, gravity kicks in again and pulls you back down to earth.
![pygame image convert alpha pygame image convert alpha](https://i.stack.imgur.com/fNO42.jpg)
For a few moments, you jump up instead of falling down, the way gravity is pulling you. In the previous article in this series, you simulated gravity, but now you need to give your player a way to fight against gravity by jumping.Ī jump is a temporary reprieve from gravity. Self.rectangle = pygame.Surface((10, 20), pygame.SRCALPHA) Pygame.K_w, pygame.K_s, pygame.K_a, pygame.K_d) Self.sprite_movement = RotationMovementKeys(self.sprite, Self.sprite = BaseSprite(self.rectangle,, "center") Self.angle = (self.angle + self.rotation_speed * delta) % 360 Self.angle = (self.angle - self.rotation_speed * delta) % 360 Self.center += self.direction * delta * (self.speed / 2) Self.center -= self.direction * delta * self.speed Self.direction = pygame.Vector2(sin(rad), cos(rad)) Self.surface = _mode((width, height))ĭef _init_(self, image, position, anchor="topleft"):ĭef _init_(self, sprite, up, down, left, right): Thank you for reading!ĭef _init_(self, caption, width, height, center=True): Game.main_loop()So if anyone has an idea how I could fix this, I would be really grateful. If (yd-yc) = (self.xdest - 10) and xc = (self.ydest - 10) and yc 1921 : Self.RIGHT, self.LEFT, self.UP, self.DOWN = "right left up down".split() Self.rightMousePressed = rightMousePressed Self.step4 = ("Sprites/Ant-mid.png").convert_alpha() Self.step3 = ("Sprites/Ant-3.png").convert_alpha() Self.step2 = ("Sprites/Ant-mid.png").convert_alpha() Self.step1 = ("Sprites/Ant-1.png").convert_alpha() Self.image = self.perso_rotated_surf = ("Sprites/Ant-rot.png").convert_alpha() Here it is:ĭef _init_(self, x, y,DIRECTION,upKeyPressed,downKeyPressed,leftKeyPressed,rightKeyPressed, leftMousePressed, rightMousePressed, oneKeyPressed, HP, game):
PYGAME IMAGE CONVERT ALPHA HOW TO
I see that most people use "()", however my code is a heavily modified version of a game I previously made with a friend, and I have no idea how to adapt it.
![pygame image convert alpha pygame image convert alpha](https://i.stack.imgur.com/xncfg.png)
I've seen many ways to correct it, however, all of them were really out of reach for me, even more as English is not my first language. Note that I don't mind the hitbox changing of size, but if possible I wouldn't be nitpicky. As a square diagonal is bigger than its side, the image is moving to the bottom right of the screen, the worst being when you're at a 45° angle. The reason for it, I know it very well: the "rect" cannot be circular, so the image is moving, to look like a square on its tip. While the rotation is working fine, the problem is -and as I saw through my internet research, a common one- that the image is actually being displaced. However, I want to add the possibility of my character rotating to the direction where it is going. Until there, no problem at all, everything is working as intended. When selected, if I right-click somewhere else, it will move to that position, and stop once destination reached. When I left-click on it, he is "selectionned"(yes I'm aware of the error). I want to have a character displayed on the screen, being able to move in every direction. Hello everyone! I'm a new pygame/python (wannabe) programmer, and I stepped into a problem.