Sign in to follow this  
Apathy

update function of a class object not working

Recommended Posts

I started playing with the pandajs library only yesterday so maybe it is some really small problem. But i would like some help. I create a scene, and 2 objects of class Bubble I created on it. The init function of these object gets called but not the update function as shown by the console.log lines I put on the 2 functions.

 

Anyway here is the code.

game.module('game.main').require('engine.core').body(function(){ game.addAsset('media/Background1.png','Background');game.addAsset('media/Menu/Menu2.png','Menu');game.addAsset('media/Player/Bubblo0001.png','Bubble1');game.addAsset('media/Player/Bubblo0002.png','Bubble2');game.addAsset('media/Player/Bubblo0003.png','Bubble3');game.addAsset('media/Player/Bubblo0004.png','Bubble4');game.addAsset('media/Player/Bubblo0005.png','Bubble5');game.addAsset('media/Player/Bubblo0006.png','Bubble6');game.addAsset('media/Player/Bubblo0007.png','Bubble7');game.addAsset('media/Player/Bubblo0008.png','Bubble8');game.addAsset('media/Player/Bubblo0009.png','Bubble9');game.addAsset('media/Player/Bubblo0010.png','Bubble10');game.System.orientation = game.System.LANDSCAPE;Bubble= game.Class.extend({	anima: new Array(),	cont: 0,	con: 0,	sprite: null,	init: function( x,y,cont, scale ){				this.cont=cont;		this.anima.push('Bubble1');		this.anima.push('Bubble2');		this.anima.push('Bubble3');		this.anima.push('Bubble4');		this.anima.push('Bubble5');		this.anima.push('Bubble6');		this.anima.push('Bubble7');		this.anima.push('Bubble8');		this.anima.push('Bubble9');		this.anima.push('Bubble10');				this.sprite=new game.Sprite(this.anima[this.cont-1]);		this.sprite.anchor.x=0.5;		this.sprite.anchor.y=0.5;		this.sprite.position.x=x;		this.sprite.position.y=y;		this.sprite.scale.x=scale;		this.sprite.scale.y=scale;		game.scene.stage.addChild(this.sprite);		game.scene.addObject(this);		console.log('BUT');	},			update: function(){		console.log('WHYYYYYY');	}}); SceneGame = game.Scene.extend({con: 0,spriteMenu: null,scx: 0,bub1: null,bub2: null,init: function() {this.scx=game.system.width/800;	var spriteBackground = new game.Sprite('Background');this.stage.addChild(spriteBackground);spriteBackground.anchor.x=0;spriteBackground.anchor.y=0;spriteBackground.position.x=0;spriteBackground.position.y=0;spriteBackground.scale.x=this.scx;spriteBackground.scale.y=game.system.height/480;this.spriteMenu = new game.Sprite('Menu');this.stage.addChild(this.spriteMenu);this.spriteMenu.anchor.x=0.5;this.spriteMenu.anchor.y=0.5;// Tween sprite positionthis.spriteMenu.position.x=game.system.width/2;this.spriteMenu.position.y=game.system.height/2;this.spriteMenu.scale.x=0.1*this.scx;this.spriteMenu.scale.y=0.1*this.scx;},click:function(event){	},update: function(){	if(this.con<9){		this.con+=1;		this.spriteMenu.scale.x+=0.1*this.scx;		this.spriteMenu.scale.y+=0.1*this.scx;				if(this.con==9){			this.bub1=new Bubble(238*this.scx,352*this.scx,9,1.2*this.scx);			this.bub2=new Bubble(399*this.scx,347*this.scx,9,1.6*this.scx);		}	}}}); game.start(SceneGame);	});

Hope to solve it. Really like this engine. Keep up the good work to the creator and contributors.

Share this post


Link to post
Share on other sites

Thanks for the fast reply. But I have used in the bubble init function the game.scene.addObject(this); to do that. I also tried the way you suggested but its the same result.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.