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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:42:30+00:00 2026-06-13T21:42:30+00:00

We are using the cocos2d framework to create a game. We’re completely new to

  • 0

We are using the cocos2d framework to create a game. We’re completely new to this framework, so we cannot get the director object to work as we are expecting. Here is our code skeleton:

from cocos.director import director
from cocos.layer import base_layers


import sys
import math
import os

import pyglet
import cocos


world_width = 1000
world_height = 1000
class NetworkMap(cocos.layer.ScrollableLayer):
    def __init__(self, world_width, world_height):
        self.world_width = world_width
        self.world_height = world_height
        super(NetworkMap, self).__init__()
        bg = ColorLayer(170,170,0,255,width=500,height=500)
        self.px_width = world_width
        self.px_height = world_height
        self.add(bg,z=0)

class TestScene(cocos.scene.Scene):
    def __init__(self):
        super(TestScene,self).__init__()

    def on_enter():
        director.push_handlers(self.on_cocos_resize)
        super(TestScene, self).on_enter()

    def on_cocos_resize(self, usable_width, usable_height):
        self.f_refresh_marks()

def main():
    scene = TestScene()
    director.init(world_width, world_height, do_not_scale=True)
    world_map = NetworkMap(world_width, world_height)
    scroller = cocos.layer.ScrollingManager()
    scroller.add(world_map)
    scene.add(scroller)
    director.run(scene)

So for some reason the director doesn’t have all the attributes we want.
Our stack trace is:

Traceback (most recent call last):
File "map.py", line 49, in <module>
main()
File "map.py", line 39, in main
scene = TestScene()
File "map.py", line 29, in __init__
super(TestScene,self).__init__()
File "/usr/local/lib/python2.7/dist-packages/cocos2d-0.5.5-py2.7.egg/cocos/scene.py",     line 95, in __init__
super(Scene,self).__init__()
File "/usr/local/lib/python2.7/dist-packages/cocos2d-0.5.5-py2.7.egg/cocos/cocosnode.py", line 114, in __init__
self.camera = Camera()
File "/usr/local/lib/python2.7/dist-packages/cocos2d-0.5.5-py2.7.egg/cocos/camera.py", line 56, in __init__
 self.restore()
 File "/usr/local/lib/python2.7/dist-packages/cocos2d-0.5.5-py2.7.egg/cocos/camera.py", line 76, in restore
 width, height = director.get_window_size()
 File "/usr/local/lib/python2.7/dist-packages/cocos2d-0.5.5-py2.7.egg/cocos/director.py", line 522, in get_window_size
 return ( self._window_virtual_width, self._window_virtual_height)
AttributeError: 'Director' object has no attribute '_window_virtual_width'
  • 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-13T21:42:32+00:00Added an answer on June 13, 2026 at 9:42 pm

    You need to initialise the director before you instantiate your first scene. The director is the global object that initialises your screen, sets up the Cocos2D framework, etc.

    I found a few other errors:

    • You need to change ColorLayer to be fully qualified, e.g. cocos.layer.ColorLayer.
    • on_enter needs to have self as the first argument.
    • You need to define f_refresh_marks in your TestScene class.

    Here’s a working copy of the code. (Working, in the sense that it does not throw errors, not that it does any sort of scrolling.)

    from cocos.director import director
    from cocos.layer import base_layers
    
    
    import sys
    import math
    import os
    
    import pyglet
    import cocos
    
    
    world_width = 1000
    world_height = 1000
    class NetworkMap(cocos.layer.ScrollableLayer):
        def __init__(self, world_width, world_height):
            self.world_width = world_width
            self.world_height = world_height
            super(NetworkMap, self).__init__()
            bg = cocos.layer.ColorLayer(170,170,0,255,width=500,height=500)
            self.px_width = world_width
            self.px_height = world_height
            self.add(bg,z=0)
    
    class TestScene(cocos.scene.Scene):
        def __init__(self):
            super(TestScene,self).__init__()
    
        def on_enter(self):
            director.push_handlers(self.on_cocos_resize)
            super(TestScene, self).on_enter()
    
        def on_cocos_resize(self, usable_width, usable_height):
            self.f_refresh_marks()
    
        def f_refresh_marks(self):
            pass
    
    def main():
        director.init(world_width, world_height, do_not_scale=True)
        scene = TestScene()
        world_map = NetworkMap(world_width, world_height)
        scroller = cocos.layer.ScrollingManager()
        scroller.add(world_map)
        scene.add(scroller)
        director.run(scene)
    
    if __name__ == '__main__': main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing one 2d game using cocos2d framework, in this game i am
I am using cocos2d to create a simple arrow shooting game.On reset button I
I am developing a game using Cocos2d FrameWork in Android. I encountered a problem
I'm using cocos2d to make a game and I'm trying to create a shot
I am using Cocos2d game development framework for iPhone. Let's focus on the battle
I'm having really hard time with my pixelated 2D game. I'm using Cocos2D framework
I'm using Cocos2D in my project and I'm quite new to this library. And
I am doing iOS game development using the cocos2d framework, and I tremendously envy
I am working on an iPhone game using the cocos2d framework, and recently encountered
I am developing an interactive 2-book for children using cocos2D framework. It would be

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.