slappy101 Posted April 9, 2015 Share Posted April 9, 2015 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 Quote Link to comment Share on other sites More sharing options...
enpu Posted April 9, 2015 Share Posted April 9, 2015 You cannot extend Pixi classes on current Panda version, but that will change on Panda 2.0 Quote Link to comment Share on other sites More sharing options...
slappy101 Posted April 9, 2015 Author Share Posted April 9, 2015 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 Quote Link to comment Share on other sites More sharing options...
enpu Posted April 9, 2015 Share Posted April 9, 2015 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() { }}); Quote Link to comment Share on other sites More sharing options...
slappy101 Posted April 9, 2015 Author Share Posted April 9, 2015 Thank you, that's exactly what I was looking for! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.