lars

Members
  • Content Count

    61
  • Joined

  • Last visited

Posts posted by lars


  1. Thank´s a lot for the answer 

     

    Hhmmm. That did not do it :-)

     

    Im a little bit confused about the bind method ... here is the class im working on. I would be very thankful if you have the time to have a look:

     

     
       game.createClass('Pumpkins', {        init: function() {               var myPumkingsVelocityArray=[100,80,60,50,40,32,45,67,78,98,90];         var pumkingVInterval = myPumkingsVelocityArray[Math.floor(Math.random()*myPumkingsVelocityArray.length)];                               var x = Math.random(16, game.system.width);                        //this.pumkins = new game.Sprite('pumkings');                         this.pumkins = new game.Animation('media/pumkings.png');             this.pumkins .animationSpeed = 0.3;             this.pumkins .position.set(230, 350);            this.pumkins.anchor.set(0,1);             this.pumkins.play();               this.poffedPumkins = new game.Animation(            'media/pum1.png',            'media/pum2.png',            'media/pum3.png',            'media/pum4.png',            'media/pum5.png'        );                                    this.pumkins.anchor.set(0.5, 0.5);            this.body = new game.Body({                position: {                    x: x ,                    y:  - this.pumkins.height                },                velocity: {                    x: 0,                    y: pumkingVInterval                },                collisionGroup: 1,                collideAgainst: [0],                mass: 0,                         });            this.body.collide = this.collide.bind(this);            this.body.addShape(new game.Rectangle(20, 20));            game.scene.addObject(this);            game.scene.world.addBody(this.body);            game.scene.stage.addChild(this.pumkins);            this.update();        },        collide: function() {          this.pumkins.textures=this.poffedPumkins.textures;this.pumkins.currentFrame=0;//In this case just run it oncethis.pumkins.loop=false;            //this.remove();            this.pumkins.onComplete(this.remove.bind(this));                         // this is the one i have been trying before                        /*              this.pumkins.onComplete = function(){                  this.remove();          };   */        },        update: function() {            this.pumkins.position.x = this.body.position.x;            this.pumkins.position.y = this.body.position.y;                        if (this.pumkins.position.y - this.pumkins.height / 2 > game.system.height) this.remove();            //this.body.position.x += 50 * game.system.delta;        },                 remove: function() {            game.scene.removeObject(this);            game.scene.world.removeBody(this.body);            game.scene.stage.removeChild(this.pumkins);        }    });

  2. I have the following collide function in a class:

     

    collide: function(opponent) {this.pumkins.textures=this.poffedPumkins.textures;this.pumkins.currentFrame=0;this.pumkins.loop=false; this.pumkins.onComplete = function(){this.remove();};}

    I get the following error:

    Cannot read property 'updateTransform' of undefined

    on the this.remove();

     

    It work allright when I call the this.remove() directly in the collide function. 

     


  3. Simple ...  cant make this work 

    game.module(    'game.main').body(function() {    game.addAsset('_ninja_1.png', 'ninja');    game.addAsset('pumkings.png', 'pumkings');    //game.addAsset('ninja.json');    game.addAudio('swipe.mp3', 'swipe');    game.createClass('Alien', {        speed: 500,        init: function() {            this.sprite = new game.Sprite('ninja');            this.sprite.anchor.set(0.5, 0.5);            this.body = new game.Body({                position: {                    x: game.system.width / 2,                    y: game.system.height - this.sprite.height / 2                },                //velocityLimit: { x: 150, y: 150 },                velocity: {                    x: 0,                    y: 0                },                collisionGroup: 1,                collideAgainst: [0],                mass: 0            });            this.body.collide = this.collide.bind(this);            this.body.addShape(new game.Rectangle(this.sprite.width, this.sprite.height));            game.scene.addObject(this);            game.scene.world.addBody(this.body);            game.scene.stage.addChild(this.sprite);        }, //init        collide: function(opponent) {            console.log("Collision!");        },        update: function() {            if (this.body.position.x > game.system.width) this.body.position.x = game.system.width;            if (this.body.position.x < 0) this.body.position.x = 0;            if (game.keyboard.down('LEFT')) this.body.velocity.x = -this.speed;            else if (game.keyboard.down('RIGHT')) this.body.velocity.x = this.speed;            else this.body.velocity.x = 0;            this.sprite.position.x = this.body.position.x;            this.sprite.position.y = this.body.position.y;        },    });    game.createClass('Pumpkins', {        init: function() {            this.radius = 40;            this.sprite = new game.Sprite('pumkings');            this.sprite.anchor.set(0.5, 0.5);            this.body = new game.Body({                position: {                    x: 100,                    y: game.system.height - this.sprite.height + 50                },                velocity: {                    x: 0,                    y: 0                },                collisionGroup: 0,                collideAgainst: [1],                mass: 0            });            this.body.collide = this.collide.bind(this);            this.body.addShape(new game.Circle(this.radius));            game.scene.addObject(this);            game.scene.world.addBody(this.body);            game.scene.stage.addChild(this.sprite);        },        collide: function(opponent) {            console.log('Collision!')        },        update: function() {            this.sprite.position.x = this.body.position.x;            this.sprite.position.y = this.body.position.y;            //this.body.position.x += 50 * game.system.delta;        }    });    game.createScene('Main', {        backgroundColor: 0x630909,        init: function() {            console.log("Scene");            this.world = new game.World(0, 0);            this.initGame();        },        initGame: function() {            pumkings = new game.Pumpkins();            player = new game.Alien();        },    });}); //body

    Any help would be so kind :-)

     


  4. Hello

    Im struggling with some understanding of useing the World obejct  for collision.

     

    The problem is:

     

    I having a Pumking class where im trying to create body for collision detection.

     

       game.createClass('Pumpkins', {        init: function() {            console.log("Pumkings");            this.sprite = new game.Sprite('pumkings');            this.sprite.y = game.system.height / 2 - this.sprite.height / 2 + 150            this.sprite.interactive = true;            this.sprite.addTo(game.scene.stage);            /*              this.world = new game.World();             */            this.body = new game.Body({                position: {                    x: 100,                    y: 100                },                velocityLimit: {                    x: 150,                    y: 150                },                velocity: {                    x: -100,                    y: -50                },                collisionGroup: 1,                collideAgainst: 0,                mass: 0            });            this.body.collide = this.collide.bind(this);            this.body.addShape(new game.Rectangle(60, 60));            game.scene.addObject(this);            this.world.addBody(this.body);// this is where my error is thrown            game.scene.stage.addChild(this); },        collide: function(opponent) {          console.log("Collision!");           return true;        },        update: function() {   this.sprite.position.y += 50 * game.system.delta;        } });

    then in my Main scene, which for now is in the same file, I create my World object:

     

        game.createScene('Main', {        backgroundColor: 0x630909,        init: function() {            console.log("Scene");    this.world = new game.World(0, 0); // my world    this.initGame();        },        initGame: function() {       player = new game.Alien(100, 100);//just another class       pumkings = new game.Pumpkins();             }    });

    Im getting the following error:

     

    Cannot read property 'addBody' of undefined. 

     

    So ... maybee my World is´nt global or ...?

     

    I posting my entire code below:

     

    game.module(    'game.main').require(    'engine.core',    'engine.keyboard',    'engine.tween',    'engine.physics').body(function() {    var player;    var Ninja;    var myPumkings;    game.addAsset('ninja_1.png', 'ninja1');    game.addAsset('ninja_2.png', 'ninja2');    game.addAsset('ninja_3.png', 'ninja3');    game.addAsset('pumkings.png', 'pumkings');    //game.addAsset('ninja.json');    game.addAudio('swipe.mp3', 'swipe');    game.createClass('Alien', {        name: 'Hans',        health: 10,        init: function(myX, myY) {            console.log("Alien");            Ninja = new game.Animation('media/ninja_1.png', 'media/ninja_2.png', 'media/ninja_3.png', 'media/ninja_4.png');            Ninja.animationSpeed = 0.1;            Ninja.position.set(game.system.width / 2 - Ninja.width / 2, game.system.height - Ninja.height);            //Ninja.anchor.set(0,1);            Ninja.addTo(game.scene.stage);        }, //init        mousedown: function() {            console.log("allo");            game.audio.playSound("swipe", false);        }    });    game.createClass('Pumpkins', {        init: function() {            console.log("Pumkings");            this.sprite = new game.Sprite('pumkings');            this.sprite.y = game.system.height / 2 - this.sprite.height / 2 + 150            this.sprite.interactive = true;            this.sprite.addTo(game.scene.stage);                         this.world = new game.World();                     this.body = new game.Body({                position: {                    x: 100,                    y: 100                },                velocityLimit: {                    x: 150,                    y: 150                },                velocity: {                    x: -100,                    y: -50                },                collisionGroup: 1,                collideAgainst: 0,                mass: 0            });            this.body.collide = this.collide.bind(this);            this.body.addShape(new game.Rectangle(60, 60));            //add sprite to scene            game.scene.addObject(this);            //add body of this sprite to the world object         this.world.addBody(this.body);            /*        //add sprite to display container        game.scene.stage.addChild(this);                 */        },        collide: function(opponent) {            console.log("Collision!");            //opponent.remove();            return true;        },        update: function() {            //myPumkings.position.x = this.body.position.x;            //myPumkings.position.y = this.body.position.y;            //this.sprite.position.y += 50 * game.system.delta;        }    });    game.createScene('Main', {        backgroundColor: 0x630909,        init: function() {            console.log("Scene");            this.world = new game.World(0, 0);            this.initGame();            /*         var tweenPumkings = new game.Tween(myPumkings.position);        tweenPumkings.to({            x: (100)                   }, 1000);tweenPumkings.easing(game.Tween.Easing.Elastic.Out);   tweenPumkings.start();    */        },        initGame: function() {            player = new game.Alien(100, 100);            pumkings = new game.Pumpkins();                    },        keyup: function(key) {            if (key === 'RIGHT') {                Ninja.gotoAndStop(2);                game.audio.playSound("swipe", false);                goTweenAlien(+150);            }            if (key === 'LEFT') {                Ninja.gotoAndStop(1);                game.audio.playSound("swipe", false);                goTweenAlien(-150);            }            if (key === 'UP') {                Ninja.gotoAndStop(3);                game.audio.playSound("swipe", false);                jumpAlien();            }        } //end keyup    });    function goTweenAlien(move) {        var tweenRight = new game.Tween(Ninja.position);        tweenRight.to({            x: (game.system.width / 2 - Ninja.width / 2) + move        }, 300);        tweenRight.easing(game.Tween.Easing.Elastic.Out);        tweenRight.onComplete(function() {            tweenOver();        });        tweenRight.start();    }    function jumpAlien() {        var tweenUp = new game.Tween(Ninja.position);        tweenUp.to({            y: (0)        }, 300);        tweenUp.easing(game.Tween.Easing.Elastic.Out);        tweenUp.onComplete(function() {            tweenOver();        });        tweenUp.start();    }    function tweenOver() {        var tweenBack = new game.Tween(Ninja.position);        tweenBack.to({            x: (game.system.width / 2 - Ninja.width / 2),            y: game.system.height - Ninja.height        }, 50);        tweenBack.delay(100);        tweenBack.start();        tweenBack.onComplete(function() {            Ninja.gotoAndStop(0);        });    }    //tweenRight.chain(tweenBack);});

    Hope someone can help me here ... 

     

     

     

     


  5. Hello

     

    Im new to panda, so this is proberly a very basic q:

     

    game.createClass('Alien', {        name: 'Hans',        health: 10,        init: function(myX, myY) {            Ninja = new game.Animation('media/ninja_1.png', 'media/ninja_2.png', 'media/ninja_3.png','media/ninja_4.png');            Ninja.animationSpeed = 0.1;            Ninja.position.set(game.system.width / 2 - Ninja.width / 2, game.system.height - Ninja.height);            //Ninja.anchor.set(0,1);            Ninja.addTo(game.scene.stage);              this.shape = new game.Rectangle(Ninja.width,Ninja.height);                        this.body = new game.Body({            position: {x: 100, y: 100},            collisionGroup: 1,            collideAgainst: 0          });                    this.body.addShape(this.shape);          //this.body.collide = this.collide.bind(this);                                 }, //init        mousedown: function() {            console.log("allo");            game.audio.playSound("swipe", false);        }    });

    I keep getting a error when I add this:

    this.body.collide = this.collide.bind(this); 

    The error is:

    Cannot read property 'bind' of undefined

     

     

     

     


  6. I have the following:

     

    game.createScene('Main', { backgroundColor: 0x630909,init: function(message) {var player = new game.Alien(100,100);},         keyup: function(key) {        if (key === 'SPACE') {               var tween = new game.Tween("call my player object here");       tween.to({x:800}, 1000);       tween.start();                    }    }});

    How can i call the "player" object in my tween