TypeError: cc.Director.getInstance is not a function. (In 'cc.Director.getInstance( )', 'cc.Director.getInstance' is undefined)

  • Marcel
    Likes 0

    Problem Description

    Hello,

    at first, sorry for my bad english..

    Everytime i want to run my project, i get this error code.
    I already copy & paste the code from the tutorial: Cocos2d-x Multi Device Design 2.0
    But i always get the same issue.

    Thanks for your help!

    Best regards

    Marcel

     


  • Sonar Systems admin
    Likes 0

    Could you show us the code you are using and what version of Cocos2d-x are you using?

  • Marcel
    Likes 0

    Wow, thank you so much for your fast reply!

    I use cocos2d-x 3.10.


    var HelloWorldLayer = cc.Layer.extend({
        ctor:function () {
            //////////////////////////////
            // 1. super init first
            this._super();
           
            var director = cc.Director.getInstance( );
            var winSize = director.getVisibleSize( );
            var origin = director.getVisibleOrigin( );

            var background = new cc.Sprite( res.Background_png );
            background.setAnchorPoint( 0.5, 0.5 );
            background.setPosition( winSize.width / 2 + origin.x, winSize.height / 2 + origin.y );
            this.addChild( background );
                                          
            var playButton = new cc.Sprite( res.PlayButton_png );
            playButton.setAnchorPoint( 0.5, 0.5 );
            playButton.setPosition( winSize.width / 2 + origin.x, winSize.height / 2 + origin.y );
            this.addChild( playButton );
                                          
            var soundButton = new cc.Sprite( res.SoundButton_png );
            soundButton.setAnchorPoint( 0.5, 0.5 );
            soundButton.setPosition( winSize.width / 2 + origin.x, soundButton.height / 2 + origin.y );
            this.addChild( soundButton );
                                          
            var facebookButton = new cc.Sprite( res.Facebook_png );
            facebookButton.setAnchorPoint( 0.5, 0.5 );
            facebookButton.setPosition( facebookButton.width / 2 + origin.x, winSize.height - ( facebookButton.height / 2 ) + origin.y );
            this.addChild( facebookButton );

            var twitterButton = new cc.Sprite( res.Twitter_png );
            twitterButton.setAnchorPoint( 0.5, 0.5 );
            twitterButton.setPosition( winSize.width - ( twitterButton.width / 2 ) + origin.x, winSize.height - ( twitterButton.height / 2 ) + origin.y );
            this.addChild( twitterButton );

            return true;
        }
    });

    var HelloWorldScene = cc.Scene.extend({
        onEnter:function () {
            this._super();
            var layer = new HelloWorldLayer();
            this.addChild(layer);
        }
    });

     

     

    Thank you!

  • Marcel
    Likes 0

    Ok, now im confused..

    Now it works in Xcode but not in the browser…
     

     

  • Sonar Systems admin
    Likes 0

    Try removing the cache form your browser.

  • Marcel
    Likes 0

    Yes i already did that..

    Cache, restart Terminal :(

  • Sonar Systems admin
    Likes 0

    Does a fresh project work fine through a browser and xcode.

  • Marcel
    Likes 0

    Same problem :(

  • Marcel
    Likes 0

    lol…
    It works after a reboot :D

    Thanks for your help!

    
     
  • Sonar Systems admin
    Likes 0

    LOL, reboot of your computer?

  • Marcel
    Likes 0

    I was wrong…:(

    Same issue… 
    Im desperate, spent the whole day to fix the problem

  • Sonar Systems admin
    Likes 0

    The issue is still occurring?

  • Marcel
    Likes 0

    Yes..
     

    Best Regards

    Marcel


Login to reply