我使用的IDE (编写器)有字体错误等等,所以我尝试使用我自己的字体。我很难让这些信出现在我想要的地方。例如,
draw_word('abab',[15,10])
使'abab‘这个词(到目前为止我只做了a和b)达到了预期的效果。然而,如果我要这样做:
draw_word('abab',[50,10])
然后信件就散落了。我想把这个词放在x=50的屏幕上。
draw_word('abab',[5,10])
这会把单词卷起来,而不是把它放到x=5的屏幕上。
我如何解决这个问题,以及是什么原因造成的?
完整的代码是:
draw_word('abab',[15,10])
这就要求:
def draw_word(word,xy):
loc=1 # short for location
for letter in word:
draw_letter(letter,[(xy[0]*loc),xy[1]]) #uses loc to move the letter over
loc+=1 #next letter
这就要求:
def draw_letter(letter,xy):
l=pygame.image.load(('letters/'+letter+'.png')).convert()
l.set_colorkey(WHITE)
screen.blit(l,xy)
发布于 2014-07-08 03:15:08
在print xy[0]*loc
中添加for letter in word
,您就会明白为什么在错误的地方有字母。
x=50
的例子:第一个字母50*1=50,下一个字母50*2=100,下一个字母50*3=150
你需要:
def draw_word(word,xy):
loc=0 # short for location
for letter in word:
draw_letter(letter,[(xy[0]+loc),xy[1]]) #uses loc to move the letter over
loc += 20 #next letter
使用loc += 20
中的其他值来获得字母之间的更好距离。
顺便说一句:你可以这样写:
def draw_word(word,xy, distance=20)
for letter in word:
draw_letter(letter,xy)
xy[0] += distance
现在你可以用它了
draw_word('abab',[15,10]) # distance will be 20
draw_word('abab',[15,10], 30) # distance will be 30
https://stackoverflow.com/questions/24623079
复制相似问题