Jump to content

this.current.body undefined


ThatGuy
 Share

Recommended Posts

Hi there!

First of all sorry for my poor English, i'm italian so... you know...

Beside, here i'm biting more then i can actually chew , so i do need your help. I've been assigned to a project consisting in creating a panda js videogame with little to no knowledge of the metter, so now i'm stuck with a nasty "TypeError: this.current is undefined" on Core.js

Could someone give me a clue? My best guest is that somewhere in the createClass of mine game.objects i had refereed .body badly. If it need i'll add the code.

Thanks again in advance for your help! 

Link to comment
Share on other sites

Hi, naturally!

 

Down there we have the page who handle the main player and the movements (for now):

game.module(
    'game.proto_player'
)

.require()

.body(function() {
    
    throw '.body(function) ' + this;    
    
game.createClass('giocatore', { 
    
    collideAgainst: [1,2],
    collisionGroup: 0,
    
    init: function() {
        
        throw '.body ' + this;
        var corpo = new game.body({
            position:       {   x: game.system.width / 20,
                                y: game.system.height / 20 },
            velocityLimit:  {   x: 150,
                                y: 150 },
            velocity:       {   x: -100,
                                y: -100 },
            mass: 0             
        });
        throw '.corpo ' + this;
        
/*      this.body = new game.body({
            position:       {   x: game.system.width / 20,
                                y: game.system.height / 20 },
            velocityLimit:  {   x: 150,
                                y: 150 },
            velocity:       {   x: -100,
                                y: -100 },
            mass: 0 });
  */
        this.body.addShape(new game.Rectangle(20, 20));
             game.scene.addObject(this);
             game.scene.world.addBody(this.body);
             game.scene.stage.addChild(this);
        throw 'addShape ' + this;
    },
     
    initSprite: function() {
        
//      var x = game.system.width / 20;
//      var y = game.system.height / 20;
        
        var sprite = new game.Sprite('proto_player.png');
            sprite.position.set(this.corpo.position.x, this.corpo.position.y);
            sprite.addTo(this.stage); 
            throw 'stage ' + this;},
    
    ready: function() { this.corpo.collide = this.kill.bind(this); },

    update: function() {
        
        this.position.x = this.corpo.position.x;
        this.position.y = this.corpo.position.y;
        throw 'posizione x/y ' + this;    
    
    
        if (game.keyboard.down('UP')) {
                this.corpo.position.y += this.position.y; }
                  
        if (game.keyboard.down('DOWN')) {
                this.corpo.position.y -= this.position.y; }
                
        if (game.keyboard.down('LEFT')) {
                this.corpo.position.x -= this.position.x; }
                
        if (game.keyboard.down('RIGHT')) {
                this.corpo.position.x += this.position.x; } },
    
    remove: function() {

  
        game.scene.removeObject(this);
        game.scene.world.removeObject(this.body);
        game.scene.stage.removeChild(this);
        throw 'remove ' + this;
  
//      game.removeAll();
        game.scene.addTimer(1500, function() { game.scene.setScene('main'); }); },
    
});


}); 

Then the scenes.js

 

game.module(
    'game.scenes'
)

.require(
//  'game.main',
    'game.assets',
//  'game.objects',
    'game.proto_player' 
/*  'game.prova',
    'engine.system',
    'engine.core',
    'engine.pool',
    'engine.scene',
    'engine.physics'*/
)

.body(function() {

    
    if(typeof game.System !== 'undefined') {
        var absY     = game.System.height;
        var absX     = game.System.width;
    
        var absPX = 1004;
        var absPY = 748; }
    
game.createScene('Livello_prova', {

    init: function() {
//      this.subContainer = new game.Container().addTo(this.stage);
        var nomeScena = game.system.currentSceneName;
  		var bg        = new game.Sprite('Background2.png').addTo(this.stage);
//		var bg        = new game.Sprite('Background2.png').addTo(this.subContainer);  
        var muro      = new game.Sprite('muro.png');
        
/*      this.addObject(bg);
        this.mainContainer.addTo(this.stage);
        this.addObject(nomeScena);
        this.addObject(muro)
        this.mainContainer.addTo(this.stage);

        alert(this.mainContainer(nomeScena)); */
        
//aggiungo perimetro
        var i;
        var x1 = 0;
        var x2 = 20;
        var y1 = 0;
        var y2 = 460;

        for (i = 0; i < absY; i ++) {
            var muro_superiore = new game.Sprite('muro.png');
                muro_superiore.position.set(x1,y1,x2,y2);
                muro_superiore.addTo(this.stage);
            x1 = x2;
            x2 = x2 + 20;
        }
        
        x1 = 0;
        x2 = 0;
        y1 = 0;
        y2 = 0;
        
        for (i = 0; i < absX; i++) {
            var muro_sinistro = new game.Sprite('muro.png');
                muro_sinistro.position.set(x1, y1, x2, y2);
                muro_sinistro.addTo(this.stage);
            y1 = y2;
            y2 = y2 + 20;
        }
        
        x1 = 20;
        x2 = 20;
        y1 = 760;
        y2 = 20;
        
        for (i = 0; i < absX; i++) {
            var muro_inferiore = new game.Sprite('muro.png');
                muro_inferiore.position.set(x1, y1, x2, y2);
                muro_inferiore.addTo(this.stage);
            
            x1 = x2
            x2 = x2 + 20;
        }
        
        x1 = 1005;
        x2 = 20;
        y1 = 20;
        y2 = 20;
    
        for(i = 0; i < absY; i++) {
            var muro_muro = new game.Sprite('muro.png');
                muro_muro.position.set(x1, y1, x2, y2);
                muro_muro.addTo(this.stage);
        
            y1 = y2;
            y2 = y2 + 20;    
        }
        
//inizio - ANGOLI & BORDI N#1
        
        var formulaArea = new Object({
            area: 0,
            base: absX - 20,
            altezza: absY - 20 });
        
            formulaArea.area = formulaArea.base * formulaArea.altezza;
        var risultatoArea = formulaArea.area;
//          alert('Area rettangolo da disegnare: ' + risultatoArea);
        var risultatoAltezza = (risultatoArea / formulaArea.base);
//          alert('Altezza rettangolo da disegnare: ' + risultatoAltezza);
//          alert('Base rettangolo da disegnare: ' + formulaArea.base);
        var risultatoPerimetro = ((formulaArea.base + formulaArea.altezza)* 2);
//          alert('Perimetro rettangolo da disegnare: ' + risultatoPerimetro);

        
        var angoloA1 = new game.Sprite('proto_acqua.png');
                angoloA1.position.set(200,200,220,200);
                angoloA1.addTo(this.stage);
        var angoloA2 = new game.Sprite('proto_acqua.png');
                angoloA2.position.set(20, 200, 200, 20);
                angoloA2.addTo(this.stage);
        var angoloA3 = new game.Sprite('proto_acqua.png');
                angoloA3.position.set(20,600,20,600);
                angoloA3.addTo(this.stage);
        var angoloA4 = new game.Sprite('proto_acqua.png');
                angoloA4.position.set(200,600,200,600);
                angoloA4.addTo(this.stage);

        var punti1 = new Object({
            A: 200,
            B: 200,
            C: 200,
            D: 200  });
        
        
        for(i = 0; i < 21; i++) {
            var acqua0 = new game.Sprite('proto_acqua.png');
                acqua0.position.set(punti1.A, punti1.B, punti1.C, punti1.D);
                acqua0.addTo(this.stage); 

                punti1.B = punti1.D;
                punti1.D = punti1.D + 20;
//              alert('Coordinate attuali: ' + punti1.A + ',' + punti1.B + ',' + punti1.C + ',' + punti1.D);
        }            
        
         for(i = 0; i < 11; i++) {
            var acqua1 = new game.Sprite('proto_acqua.png');
                acqua1.position.set(punti1.A, punti1.B, punti1.C, punti1.D);
                acqua1.addTo(this.stage); 

                punti1.A = punti1.C;
                punti1.C = punti1.A - 20;
//              alert('Coordinate attuali: ' + punti1.A + ',' + punti1.B + ',' + punti1.C + ',' + punti1.D);
        } 

        var punti2 = new Object({
            A: 20,
            B: 200,
            C: 20,
            D: 420  });
        
         for(i = 0; i < 11; i++) {
            var acqua2 = new game.Sprite('proto_acqua.png');
                acqua2.position.set(punti2.A, punti2.B, punti2.C, punti2.D);
                acqua2.addTo(this.stage); 

                punti2.A = punti2.C;
                punti2.C = punti2.A + 20;
//              alert('Coordinate attuali: ' + punti2.A + ',' + punti2.B + ',' + punti2.C + ',' + punti2.D);
        }

        var punti3 = new Object({
            A: 20,
            B: 220,
            C: 20,
            D: 220  });
        
         for(i = 0; i < 20; i++) {
            var acqua3 = new game.Sprite('proto_acqua.png');
                acqua3.position.set(punti3.A, punti3.B, punti3.C, punti3.D);
                acqua3.addTo(this.stage); 

                punti3.B = punti3.D;
                punti3.D = punti3.B + 20;
//              alert('Coordinate attuali: ' + punti3.A + ',' + punti3.B + ',' + punti3.C + ',' + punti3.D);
        }

//fine   - ANGOLI & BORDI N#1
//inizio - ANGOLI & BORDI N#2
        
        var angoloB1 = new game.Sprite('proto_acqua.png');
                angoloB1.position.set(800, 600, 800, 600);
                angoloB1.addTo(this.stage);
        var angoloB2 = new game.Sprite('proto_acqua.png');
                angoloB2.position.set(985, 200, 985, 200);
                angoloB2.addTo(this.stage);  
        var angoloB3 = new game.Sprite('proto_acqua.png');
                angoloB3.position.set(985, 600, 985, 600);
                angoloB3.addTo(this.stage);  
        var angoloB4 = new game.Sprite('proto_acqua.png');
                angoloB4.position.set(800, 200, 800, 200);
                angoloB4.addTo(this.stage);  
        
        var puntiB1 = new Object ({
            A: 800,
            B: 600,
            C: 800,
            D: 600 });
        
        var puntiB2 = new Object ({
            A: 985,
            B: 200,
            C: 985,
            D: 200 });
        
        var puntiB3 = new Object ({
            A: 985,
            B: 600,
            C: 985,
            D: 600 });
        
        var puntiB4 = new Object ({
            A: 800,
            B: 200,
            C: 800,
            D: 200 });
        
        for(i = 0; i < 21; i++) {
            var acquaB1 = new game.Sprite('proto_acqua.png');
                acquaB1.position.set(puntiB1.A, puntiB1.B, puntiB1.C, puntiB1.D);
                acquaB1.addTo(this.stage);
            
                puntiB1.B = puntiB1.D;
                puntiB1.D = puntiB1.D - 20;
        }
        
        for(i = 0; i < 21; i++) {
            var acquaB2 = new game.Sprite('proto_acqua.png');
                acquaB2.position.set(puntiB2.A, puntiB2.B, puntiB2.C, puntiB2.D);
                acquaB2.addTo(this.stage);
            
                puntiB2.B = puntiB2.D;
                puntiB2.D = puntiB2.D + 20;
        }
        
        for(i = 0; i < 11; i++) {
            var acquaB3 = new game.Sprite('proto_acqua.png');
                acquaB3.position.set(puntiB3.A, puntiB3.B, puntiB3.C, puntiB3.D);
                acquaB3.addTo(this.stage);
            
                puntiB3.A = puntiB3.C;
                puntiB3.C = puntiB3.C - 20;
        }
        
        for(i = 0; i < 11; i++) {
            var acquaB4 = new game.Sprite('proto_acqua.png');
                acquaB4.position.set(puntiB4.A, puntiB4.B, puntiB4.C, puntiB4.D);
                acquaB4.addTo(this.stage);
            
                puntiB4.A = puntiB4.C;
                puntiB4.C = puntiB4.C + 20;
        }

//fine   - ANGOLI & BORDI N#2
//inizio - RIEMPIMENTO N#1
        
        var p1 = new Object ({
            A: 40,          //punti3.A + 20;
            B: 220,         //punti3.B;
            C: 260,         //punti2.C + 20;
            D: 460 });      //punti2.C + 20;
        
        var pd20 = Math.round(p1.D / 20);
        var temp;
        
        for(i = 0; i < 9; i++) {
            
            var ogg = new game.Sprite('proto_acqua.png');
                ogg.position.set(p1.A, p1.B, p1.C, p1.D);
                ogg.addTo(this.stage);
            
                p1.A = p1.A + 20;
                p1.C = p1.C + 20;
                
        }
        
        for(temp = 0; temp < pd20 + 1; temp++) {
            
                p1.B = p1.B - 5;//offset
                p1.A = p1.A / 10;//reset punto A
                p1.B = p1.B + 20;//scendo di un tile
            
                for(i = 0; i < 10; i++) {

                    var ogg2 = new game.Sprite('proto_acqua.png');
                        ogg2.position.set(p1.A, p1.B, p1.C, p1.D);
                        ogg2.addTo(this.stage);

                        p1.A = p1.A + 19;//un pixel di troppo
                        p1.C = p1.C + 20; } }
        
//fine   - RIEMPIMENTO N#1
//inizio - RIEMPIMENTO N#2, sapendo le coordinate di origine e di fine (cornerstones)
        
        var cornerstone1 = new game.Sprite('proto_acqua.png');
            cornerstone1.position.set(820, 220, 820, 220);
            cornerstone1.addTo(this.stage);
        var cornerstone2 = new game.Sprite('proto_acqua.png');
            cornerstone2.position.set(965,220,965,220);
            cornerstone2.addTo(this.stage);
        var cornerstone3 = new game.Sprite('proto_acqua.png');
            cornerstone3.position.set(820, 580, 820, 580);
            cornerstone3.addTo(this.stage);
        var cornerstone4 = new game.Sprite('proto_acqua.png');
            cornerstone4.position.set(965, 580, 965, 580);
            cornerstone4.addTo(this.stage);
        
        
        var pos = new Object ({
            x1: 800,
            x2: 800,
            y1: 200,
            y2: 220,
            limitex: (Math.round((cornerstone4.x - cornerstone1.x) / 20) + 2), //(Math.round(965 - 820) / 20),
            limitey: (((cornerstone4.y - cornerstone1.y) / 20) + 2) });        //(580 - 220) / 20 });
        
//          alert('valore limite asse x' + pos.limitex);  //145 / 20 = 7.25 (round = 7)
//          alert('valore limite asse y' + pos.limitey);  //240 / 20 = 12

        for(temp = 0; temp < pos.limitey; temp++) {
            
//              alert('entrato');

            var ogg4 = new game.Sprite('proto_acqua.png');
                ogg4.position.set(pos.x1, pos.y1, pos.x2, pos.y2);
                ogg4.addTo(this.stage);
//              alert('ogg4 fatto');
                            
                pos.y1 += 20;
                pos.y2  = pos.y1; 
                pos.x1 = 800;
            
            
            for(i = 0; i < pos.limitex; i++) {
                
//                  alert('entrato 2');
                    pos.x1 += 20;
                    pos.x2  = pos.x1; 
                
                var ogg3 = new game.Sprite('proto_acqua.png');
                    ogg3.position.set(pos.x1, pos.y1, pos.x2, pos.y2);
                    ogg3.addTo(this.stage); } }
//                  alert('ogg3 fatto'); } }
        
//fine   - RIEMPIMENTO N#2
        throw 'prima della chiamata al giocatore: ' + this;
        var chiamata = this.giocatore();
},

        
});
    
});

Don't mind the bad scripting, i'll set it as soon as i fix the main problems.

Thanks for your help!

Link to comment
Share on other sites

Hi,

You've posted quite a lot of scripting! :)

I don't really understand what you are doing with the 'throw' lines.

I would recommend you to have a look at the examples on the panda fiddler that I uploaded a while ago.

furthermore i think you should try to take advantage of the build in object oriented programming possibilities that panda offers. perhaps you could rewrite your main file and move part of the logic to a separate class? It would make debugging a lot easier. This wat you can test the small pieces before you wire them all together.

A starting point: perhaps you could try to get your base class working with a very basic scene. From there you could slowly expand your code.

 

hope this is useful.

stephan

Link to comment
Share on other sites

Hi Stephan!

I've followed your useful suggestions and i get rid of the various throw, which had no propose that debugging (badly), and separated the various parts in tiny more manageable pieces.

Now everything work just fine, except the player class.

Thanks again ad sorry for the code wall! 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...