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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:17:35+00:00 2026-06-18T01:17:35+00:00

I’m working on a custom tiled map loader. Seems to work fine, I don’t

  • 0

I’m working on a custom tiled map loader. Seems to work fine, I don’t get any errors, but the screen only shows up 1 tile of each type.

this is the file structure:

/main.py 
/other/render2.py 
/other/render.py

here’s the render2.py file:

import pyglet, json
from pyglet.window import key
from pyglet.gl import *
from ConfigParser import SafeConfigParser
from cocos.layer import *
from cocos.batch import *
from cocos.sprite import Sprite

class renderer( Layer ):
    #init function
    def __init__(self):
        super( renderer, self ).__init__()

    #call function, returns the map as a list of sprites, and coordinates
    def __call__(self, mapname):

        #runs the map file parser
        parser = SafeConfigParser()

        #reads the map file
        try:
            world = parser.read('maps/'+mapname+'.txt')
            print world
        except IOError:
            return

        #These variables the config from the map file
        tileSize = int(parser.get('config', 'tilesize'))
        layers = int(parser.get('config', 'layers'))

        mapList = []

        #the super mega advanced operation to render the mapList
        for i in range(0,layers):
            layer = json.loads(parser.get('layer'+str(i), 'map'))
            tileType = parser.get('layer'+str(i), 'tiletype')
            nTiles = int(parser.get('layer'+str(i), 'tiles'))
            tileSet  = []

            #this over here loads all 16 tiles of one type into tileSet
            for n in range(0, nTiles):
                tileSet.append(Sprite("image/tiles/"+tileType+"/"+str(n)+".png", scale = 1, anchor = (0,0)))

            for x in range(0, len(layer)):
                for y in range(0, len(layer[x])):
                    X = (x*tileSize)
                    Y = (y*tileSize)
                    total = [tileSet[layer[x][y]], i, X, Y]
                    print layer[x][y], tileSet[layer[x][y]]
                    mapList.append(total)
        return mapList

This is an example of what this returns :

 [<cocos.sprite.Sprite object at 0x060910B0>, 0, 0,0 ]
 [<cocos.sprite.Sprite object at 0x060910B0> , 0, 64,64 ]

It returns a huge list with a lot of sublists like these in it.

when I call it from the main.py file, it only draws the last tile of each kind.
here’s the main.py file:

import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

import pyglet
import threading,time
from pyglet import clock
from pyglet.gl import *
from cocos.director import *
from cocos.menu import *
from cocos.scene import *
from cocos.layer import *
from cocos.actions import *
from cocos.batch import *
from cocos.sprite import Sprite
from other.render2 import renderer
import random; rr = random.randrange
class Background(ScrollableLayer):
    def __init__(self):
        super(Background, self).__init__()
        world = renderer()
        bg = world('sampleidea')


        batch = BatchNode()
        for i in range(0, len(bg)):
            l= bg[i][1]
            x= bg[i][2]
            y= bg[i][3]

            spr = bg[i][0]
            spr.position =(x,y)
            batch.add(spr, z = l)

        self.add(batch)
class Menu(Layer):
    def __init__(self):
        super(Menu, self).__init__()
        title = Sprite('image/title.png' )
        title.position = (400,520)
        self.add( title )


def start():
    director.set_depth_test()
    background = Background()
    menu = Menu()
    scene = Scene(background, menu)
    return scene

def init():
    director.init( do_not_scale=True, resizable=True, width=1280, height=720)
def run(scene):
    director.run( scene )

if __name__ == "__main__":
    init()
    s = start()
    run(s)

What am I doing wrong? I have an older render.py, which does work, but I remade it since it loaded each sprite file for each tile. That took way to long to load on big maps.

This is the old render.py I’ve been using before.
It’s quite different since it used different map files too.

import pyglet, json
from pyglet.window import key
from pyglet.gl import *
from ConfigParser import SafeConfigParser
from cocos.layer import *
from cocos.batch import *
from cocos.sprite import Sprite

class renderer( Layer ):
    def __init__(self):
        super( renderer, self ).__init__()
    def __call__(self, mapname):
        parser = SafeConfigParser()
        try:
            world = parser.read('maps/'+mapname+'.txt')
            print world
        except IOError:
            print("No world file!")
            return

        tilesize = json.loads(parser.get('data', 'tilesize'))
        world = json.loads(parser.get('data', 'world'))

        maplist = []
        for l in range(len(world)):

            for x in range(len(world[l])):

                for y in range(len(world[l][x])):
                    if world[l][x][y] != None:
                        foldername = str(world[l][x][y][0])
                        imagename = str(world[l][x][y][1])


                        spr = Sprite("image/tiles/"+foldername+"/"+imagename+".png", scale = 1, anchor = (0,0))

                        X = (x*tilesize)
                        Y = (y*tilesize)

                        total = [spr, l, X, Y]

                        maplist.append(total)

        return maplist

Is it possible to make the new “render” to work?

  • 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-18T01:17:36+00:00Added an answer on June 18, 2026 at 1:17 am

    The problem is that my new optimized “renderer” creates a bunch of
    cocos.sprite.Sprite objects, instead of just loading Image files as i thought it would. The code in my question only repositioned the same sprite object over and over again this way. To solve this, the way to do it is by opening the image with pyglet.image.load(), and creating sprite objects with that.
    example:

    f = pyglet.image.load('sprite.png')
    batch = CocosNode()
    batch.position = 50, 100
    add(batch)
    for i in range(0, 200):
        test = Sprite(f)        
        test.position = i*10,i*10
        batch.add( test )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I want to construct a data frame in an Rcpp function, but when I
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I need to clean up various Word 'smart' characters in user input, including but

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.