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 8145957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:49:56+00:00 2026-06-06T13:49:56+00:00

How do you make this code work? Just have pyglet installed and change fireball.png

  • 0

How do you make this code work? Just have pyglet installed and change "fireball.png" with the name of an image stored in the directory where you saved this code to a file.

import pyglet

class Fireball(pyglet.sprite.Sprite):
    def __init__(self, batch):
        pyglet.sprite.Sprite.__init__(self, pyglet.resource.image("fireball.png"))
        # replace "fireball.png" with your own image stored in dir of fireball.py
        self.x =  10 # Initial x coordinate of the fireball
        self.y =  10 # Initial y coordinate of the fireball

class Game(pyglet.window.Window):
    def __init__(self):
        pyglet.window.Window.__init__(self, width = 315, height = 220)
        self.batch_draw = pyglet.graphics.Batch()
        self.fps_display = pyglet.clock.ClockDisplay()
        self.fireball = []

    def on_draw(self):
        self.clear()
        self.fps_display.draw()
        self.batch_draw.draw()
        if len(self.fireball) != 0:             # Allow drawing of multiple
            for i in range(len(self.fireball)): # fireballs on screen
                self.fireball[i].draw()         # at the same time

    def on_key_press(self, symbol, modifiers):
        if symbol == pyglet.window.key.A:
            self.fireball.append(Fireball(batch = self.batch_draw))
            pyglet.clock.schedule_interval(func = self.update, interval = 1/60.)
            print "The 'A' key was pressed"

    def update(self, interval):
        for i in range(len(self.fireball)):
            self.fireball[i].x += 1 # why do fireballs get faster and faster?

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

This code creates a black background screen, where the fps are displayed and a fireball is shot along the x direction from the position (10, 10) whenever you press the A key.

You will notice that the more fireballs you shoot, the faster all fireballs will start to go.

Questions:

  1. Why do the fireballs go faster and faster each time I press A ?

  2. How should I stop the fireballs from accelerating each time I press A ?

  • 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-06T13:49:58+00:00Added an answer on June 6, 2026 at 1:49 pm

    The fireball goes faster and faster because every time you press the A you add another call of self.update to the scheduler. So self.update is called more and more times each time resulting in more updates of the position. To fix that move the line below to the __init__().

    pyglet.clock.schedule_interval(func = self.update, interval = 1/60.)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code, but i cant make it work: images = Image.find_by_sql('PREPARE stmt
How can I make this code work? class Meta @array = [:a,:b] def self.method_missing(name,
I have this code and I need to make this work: if ($handle =
I have written this code in javascript however I have to make it work
just wondering if someone can help me make this code work properly and be
Is there a way to make this code work? LogonControl.java @Audit(AuditType.LOGON) public void login(String
MyClass c = 10; Is there any way to make this code work? I
Is there a way to make this code work without a Warning? function myFunction($value,
I already know how to make this code work, but my question is more
How to make this css code cross browser compatible using jquery. this code only

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.