Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Javascript problem

  • 05-02-2013 11:33AM
    #1
    Closed Accounts Posts: 1,386 ✭✭✭


    I'm making a very basic javascript game and I'm running inro problems.
    My code so far is
    var Helloworld = cc.Layer.extend({
        isMouseDown:false,
        helloImg:null,
        helloLb:null,
        circle:null,
        sprite:null,
        sprite2:null,
        
    
        init:function () {
            var selfPointer = this;
            //////////////////////////////
            // 1. super init first
            this._super();
            
    
            var size = cc.Director.getInstance().getWinSize();
    
            //this.helloLb = cc.LabelTTF.create("Hello World", "Impact", 40);
            // position the label on the center of the screen
            //this.helloLb.setPosition(cc.p(cc.Director.getInstance().getWinSize().width / 2, 0));
            // add the label as a child to this layer
            //this.addChild(this.helloLb, 5);
    
            // add "HelloWorld" splash screen"
            this.sprite = cc.Sprite.create("res/HelloWorld.png");
            this.sprite.setPosition(cc.p(size.width / 2, size.height / 2));
            this.sprite.setVisible(true);
            this.sprite.setAnchorPoint(cc.p(0.5, 0.5));
            this.sprite.setScale(0.5);
            this.sprite.setRotation(360);
            //this.addChild(this.sprite, 0);
            
            [B]for(var j=0; j<3; j++)
            {
            for(var i=0; i<10; i++)
            {
            this.sprite2 = cc.Sprite.create("res/CloseNormal.png");
            this.sprite2.setPosition(cc.p((i*(size.width/10)),size.height/(2*(j+2)))));
            this.sprite2.setVisible(true);
            this.sprite2.setAnchorPoint(cc.p(1, 0));
            this.addChild(this.sprite2, 1);
            
            }    
            
            
            }[/B]
            
            var actionTo = cc.SkewTo.create(0, 0, 0);
            var actionToBack = cc.SkewTo.create(0, 0, 0);
            var rotateTo = cc.RotateTo.create(0, 0);
            var rotateToBack = cc.RotateTo.create(0, 0);
            var actionScaleTo = cc.ScaleTo.create(0, 0, 0);
            var actionScaleToBack = cc.ScaleTo.create(5, 1.0, 1.0);
            var actionBy = cc.MoveBy.create(5, cc.p(0, 0));
            var actionByBack = actionBy.reverse();
    
            //this.sprite.runAction(cc.Sequence.create(rotateToA, scaleToA));
    
    
            this.sprite.runAction(cc.Sequence.create(actionTo, actionToBack, null));
            this.sprite.runAction(cc.Sequence.create(rotateTo, rotateToBack, null));
            this.sprite.runAction(cc.Sequence.create(actionScaleTo, actionScaleToBack));
            this.sprite.runAction(cc.Sequence.create(actionBy, actionByBack));
    
    
            this.setTouchEnabled(true);
    
    
            var closeItem = cc.MenuItemImage.create(
                "res/CloseNormal.png",
                "res/CloseSelected.png",
                this.menuCloseCallback,
                this
            );
            var text = cc.MenuItemFont.create("A game created with Coco-2D", function () {
            }, this);
            text.setColor({r:0, g:0, b:0});
            text.setPosition(cc.p(cc.canvas.width / 2, cc.canvas.height / 2));
            closeItem.setPosition(cc.p(cc.canvas.width - 0, -0));
            var menu = cc.Menu.create(closeItem, text);
            menu.setPosition(cc.p(9, -180));
            this.sprite.addChild(menu);
            //cc.fullscreen();
    
            cc.DOM.convert(this.sprite, closeItem, text);
            return true;
        },
        // a selector callback
        menuCloseCallback:function (sender) {
            history.go(-5);
        }
    
    });
    var HelloWorldScene = cc.Scene.extend({
        onEnter:function () {
            this._super();
            var layer = new Helloworld();
            layer.init();
            this.addChild(layer);
        }
    });
    
    

    I know it would be easier if I didn't do a for loop but it looks better. Can anyone help me at all? Whenever I try loading it up on a browser it's just a black screen. I'm pretty sure the part in bold is the problem


Comments

  • Registered Users, Registered Users 2 Posts: 525 ✭✭✭mwrf


    What is cc? Your code makes no sense without knowing what cc is.
    I presume it's some library you are trying to use.


Advertisement