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

  • Home
  • SEARCH
  • 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 7784071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:02:01+00:00 2026-06-01T20:02:01+00:00

I know how to draw them at the same time using batches but I

  • 0

I know how to draw them at the same time using batches but I was wondering if there was a way to move a whole batch at once. Do I need to move all sprites individually?

So far I have been doing it like this:

tile2 =pyglet.sprite.Sprite(tile1,0,0,batch = terrain)
tile3 =pyglet.sprite.Sprite(tile1,10,0,batch = terrain)
tile4 =pyglet.sprite.Sprite(tile1,20,0,batch = terrain)
tile5 =pyglet.sprite.Sprite(tile1,30,0,batch = terrain)
tile6 =pyglet.sprite.Sprite(tile1,40,0,batch = terrain)
tile7 =pyglet.sprite.Sprite(tile1,50,0,batch = terrain)

tile2.x += 10
tile3.x += 10
tile4.x += 10

etc…

But there will be more sprites than this in the finished product (50+ I hope) and moving them all will be pretty tiresome.

Any help will be appreciated 🙂

  • 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-01T20:02:03+00:00Added an answer on June 1, 2026 at 8:02 pm

    You would want to store your objects in an appropriate data structure, such as a list:

    tiles = []
    tiles.append(pyglet.sprite.Sprite(tile1,0,0,batch = terrain))
    tiles.append(pyglet.sprite.Sprite(tile1,10,0,batch = terrain))
    ...
    

    A list contains a series of items, which can be accessed individually (tiles[0], tiles[1]) or looped through (for tile in tiles:). The list can change length and allows you to make the number of tiles you have changeable, without having to hard code lots of variables.

    However, this is a very verbose way of doing it, and the much better method is to use a loop:

    tiles = []
    for x in range(0, 51, 10):
        tiles.append(pyglet.sprite.Sprite(tile1, x, 0, batch = terrain))
    

    Here we loop over a range of numbers (from 0 to 51 in steps of 10 – note the use of 51, not 50 – python stops on the last value, not after it, so range(0, 50, 10) would yield 0 to 40 in steps of 10.), creating a tile and adding it to our list. Note that if you are using a pre-3.x version of Python, xrange() will be faster than range() as it is returns a generator, not a list. In Python 3.x, this is the behaviour of range.

    But Python can be even more elegant, using a list comprehension to create the list easily:

    tiles = [pyglet.sprite.Sprite(tile1, x, 0, batch = terrain) for x in range(0, 51, 10)] 
    

    Then to move them, we loop through the list, moving each one as we go:

    for tile in tiles:
        tile.x += 10
    

    In general, doing x1, x2, x3, … is a sign that something is wrong – using an appropriate data structure will help you do less typing, and make your code more flexible. A good way to think about this is if you are copying and pasting something, then could probably re-factor that code into a reusable function or use a loop to perform the same thing on multiple items.

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

Sidebar

Related Questions

I know how to draw basic objects using JOGL or LWJGL to connect to
So I do know how to draw multiple triangles using glBegin(GL_TRIANGLE_STRIPS) . What I
Note there's a lot of code posted below but its mostly all the same,
I have data from *.obj file. I know how draw with GL_TRIANGLES . How
does someone know how to draw 3D surfaces and hide the invisible lines? I
I know that the CGContext cannot call it to draw directly, and it needs
Does anyone know of existing code that lets you draw fully justified text in
Know this might be rather basic, but I been trying to figure out how
Know if it's possible to access the iPhone compass in Safari using JavaScript? I
I am making a website where users can upload pictures and draw on them,

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.