Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8172817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:54:10+00:00 2026-06-06T21:54:10+00:00

This code displays the image assassin1.png on a black background. The idea is that

  • 0

This code displays the image assassin1.png on a black background. The idea is that as soon as I press the <right-direction> key the character should move and display an animation using assassin2.png and assassin3.png. I have been able to move the character and display the animation succesfully, just not the two at the same time.

The following code runs as long as I don’t press the <right direction> key:

import pyglet

def sprite_type(type_ = "standing"):
    if type_ == "moving-forward":
        moving_forward_image_list = [pyglet.image.load('assassin2.png'), pyglet.image.load('assassin3.png')]
        moving_forward_animation = pyglet.image.Animation.from_image_sequence(moving_forward_image_list, 0.3) 
        return moving_forward_animation
    if type_ == "standing":
        standing_animation = pyglet.image.load("assassin1.png")
        return standing_animation

class Assassin(pyglet.sprite.Sprite):
    def __init__(self, batch, img):
        pyglet.sprite.Sprite.__init__(self, img, x = 50, y = 30)

    def stand(self, batch, img):
        self.batch = batch
        self.img = img

    def move(self, batch, img):
        self.batch = batch
        self.img = img      

class Game(pyglet.window.Window):
    def __init__(self):
        pyglet.window.Window.__init__(self, width = 315, height = 220)
        self.batch_draw = pyglet.graphics.Batch()
        self.player = Assassin(batch = self.batch_draw, img = sprite_type())
        self.fps_display = pyglet.clock.ClockDisplay()
        self.keys_held = []      
        self.schedule = pyglet.clock.schedule_interval(func = self.update, interval = 1/60.) 

    def on_draw(self): 
        self.clear()         
        self.fps_display.draw()
        self.batch_draw.draw()
        self.player.draw()  

    def on_key_press(self, symbol, modifiers):
        self.keys_held.append(symbol)
        if symbol == pyglet.window.key.RIGHT:
            self.player = self.player.move(batch = self.batch_draw, img = sprite_type("moving-forward"))
            print "The 'RIGHT' key was pressed"

    def on_key_release(self, symbol, modifiers):
        self.keys_held.pop(self.keys_held.index(symbol))
        self.player = self.player.stand(batch = self.batch_draw, img = sprite_type("standing"))

    def update(self, interval):
        if pyglet.window.key.RIGHT in self.keys_held:
            self.player.x += 50 * interval

if __name__ == "__main__":
    window = Game()
    pyglet.app.run()

As soon as I press the <right-direction> key the following error occurs:

Traceback (most recent call last):
  File "ircex.py", line 55, in <module>
    pyglet.app.run()
  File "/usr/local/lib/python2.7/dist-packages/pyglet/app/__init__.py", line 264, in run
    EventLoop().run()
  File "/usr/local/lib/python2.7/dist-packages/pyglet/app/xlib.py", line 93, in run
    sleep_time = self.idle()
  File "/usr/local/lib/python2.7/dist-packages/pyglet/app/__init__.py", line 193, in idle
    window.dispatch_event('on_draw')
  File "/usr/local/lib/python2.7/dist-packages/pyglet/window/__init__.py", line 1219, in dispatch_event
    EventDispatcher.dispatch_event(self, *args)
  File "/usr/local/lib/python2.7/dist-packages/pyglet/event.py", line 349, in dispatch_event
    return getattr(self, event_type)(*args)
  File "pyglet-walk.py", line 37, in on_draw
    self.player.draw()  
AttributeError: 'NoneType' object has no attribute 'draw'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:54:12+00:00Added an answer on June 6, 2026 at 9:54 pm

    In your code the move() method returns None:

    class Assassin(pyglet.sprite.Sprite):
        (...)
    
    
        def move(self, batch, img):
            self.batch = batch
            self.img = img      
    

    Then in the line below you set self.player to return value of player.move(), which is None:

    self.player = self.player.move(batch = self.batch_draw, img = sprite_type("moving-forward"))
    

    Which leads to AttributeError: 'NoneType' object has no attribute 'draw', because self.player is None and you try to call draw() on it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code displays the image assassin1.png on a black screen standing still at position
I have this code that pulls an image from an url and displays it
How can I alter this code so that It only displays one image at
I have found this line of MatLab code on the internet that displays a
I have following code that displays an Image with letters, public class MainActivity extends
the image that is being displayed in this code is leaking but I cant
Currently my code displays a single image from a file path (in SDCard). This
I have this bit of code that get the image i have picked from
i have this li list which displays an image with the username right next
I'm hoping this has a simple solution. I have a JavaScript code that displays

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.