简体   繁体   中英

Pyglet not drawing sprites in correct positions

Hey I've been stuck on this issue for quite a while and was hoping someone could help me out:

I'm using pyglet and have got all of the code working in my project (even what I was having the issue with) then I restarted my computer and suddenly it didn't work...

This is the loop that is instantiating my 'Letter' objects:

main_st = ut.makeString("EXNXYXAXDAADUXMDXLGEQTAQXDDQSVXUTSXKHXHRXYFUXLXJUTHXYVADSUXKHUQUIXSJHXHDPKXFQUXILNXORMXRPL")
letter_list = []
for i in range(len(main_st)):
    letter_list.append(l.Letter(pyglet.resource.image("Letters/" + main_st[i] + ".png"),main_st[i],10,10))

And this is the Letter class constructor Letter is a subclass of pyglet.sprite.Sprite:

def __init__(self,im,iden,xx,yy):

        super(Letter,self).__init__(img=im,x=xx,y=yy)

At no point in the program do I modify the x and y coordinates of sprite but when I go to draw them, no matter what I put in for xx and yy they're always drawn in the same place on the window UNLESS I do a very large number for yy, and in those cases it simply disappears (I assume it's outside of the window).

I'm having each letter flash on the screen for 1 second and in order to do that here's my on_draw method

def on_draw():
    background.draw()

    if not key_manager.cur_letter == None:
        key_manager.cur_letter.draw()

(only key_manager.cur_letter gets drawn and that switches every second).

The problem might be related to older versions.
But after calling super(Letter, self)... you could do:

def __init__(self,im,iden,xx,yy):
    super(Letter,self).__init__(img=im,x=xx,y=yy)
    self.x = xx
    self.y = yy

And that should do the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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