Jump to content

Can't extend classes


slappy101
 Share

Recommended Posts

I'm just starting with Panda.js and am having issues with extending the 'Sprite' and 'Graphics' classes when creating my own classes. I keep getting an error with the following code:

game.module(	'game.main').body(function() {	game.addAsset('characters/ball.png');	game.createClass('Ball', 'Sprite', {		init: function(x, y) {			this._super('characters/ball.png', x, y, {anchor: { x: 0.5, y: 0.5 }});			game.scene.addObject(this);			this.addTo(game.scene.stage);		},		update: function(){			this.position.x += 1;		}	});	game.createScene('Main', {		backgroundColor: 0xe1d4a7,		init: function() {			var ball = new game.Ball(100, 100);		}	});});

In Chrome the error is "Uncaught TypeError: undefined is not a function", and in Firefox I'm getting "TypeError: game[extend].extend is not a function". I'm using pandatool to create projects.

 

Thanks for any help

Link to comment
Share on other sites

Ah okay thank you. This is a somewhat unrelated question but it arose from me trying to extend the Sprite class, but how can I make custom classes react to events such as mousemove or mousedown? ie I have a class and I need something to happen everytime the mouse is moved anywhere on the screen. I've tried adding the mousemove event to the class but the event is never fired

Link to comment
Share on other sites

You can do something like this:

game.createClass('MyClass', {    init: function() {        this.sprite = new game.Sprite('mysprite.png');        this.sprite.interactive = true;        this.sprite.mousedown = this.mousedown.bind(this);    },    mousedown: function() {            }});
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...