简体   繁体   English

[Pygame]:将表面移向位置

[英][Pygame]: Move surface towards position

Is there an algorithm to change a set of coordinates to make it move towards another set of coordinates?是否有一种算法可以更改一组坐标以使其向另一组坐标移动? Like, if I have ax,ay=(20,30) a就像,如果我有 ax,ay=(20,30) a

 #fonctions import pygame, sys from pygame.locals import * pygame.init() fpsClock = pygame.time.Clock() windows= pygame.display.set_mode((1200,500), 0, 32) pygame.display.set_caption('testing') size = width, height = (32, 32) PNGImg = pygame.Surface(size) sob_X=575 sob_Y=250 FPS = 15 # frames per second setting RED= (255, 0, 0) #red color while True: windows.fill((54, 141, 197)) pygame.draw.circle(windows, RED, (70, 80), 20, 0) windows.blit(PNGImg, (sob_X,sob_Y)) dis_X=sob_X-600 #cicle X_Cordinate dis_Y=sob_X-870 #cicle Y_Cordinate if dis_X<0: sob_X=sob_X+ dis_X if sob_X==70 and dis_Y<0: sob_Y=sob_X+dis_Y elif sob_X==70 and dis_Y>0: sob_Y=sob_Y-dis_Y elif dis_X>0: sob_X=sob_X -dis_X if sob_X==70 and dis_Y<0: sob_Y=sob_Y+dis_Y elif sob_X==70 and dis_Y>0: sob_Y=sob_Y-dis_Y windows.blit(PNGImg, (sob_X,sob_Y)) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() pygame.display.update() fpsClock.tick(FPS) pygame.quit()

nd bx,by=(40,60) nd bx,by=(40,60)

How can I change ax and ay (coordinate of the image"surface") to equal bx and by?如何将 ax 和 ay(图像“表面”的坐标)更改为等于 bx 和 by? (Preferably an algorithm achievable in python.) i tried to make algorithme but in the end don't work thanks you (最好是可以在 python 中实现的算法。)我试图制作算法,但最终不起作用,谢谢

Replying here as I can't comment yet, but from the question itself, do you mean to do ax, ay = bx, by ?在这里回复,因为我还不能发表评论,但从问题本身来看,你的意思是做ax, ay = bx, by吗? You can simply do that, or even individual ones like ax = by .你可以简单地做到这一点,甚至可以像ax = by这样的个人。

With an example from the terminal:以终端为例:

>>> ax,ay=(20,30)
>>> bx,by=(40,60)
>>> ax, ay = bx, by
>>> ax, ay
(40, 60)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM