notalentgeek Posted August 25, 2015 Share Posted August 25, 2015 I have an error of "this.onTextureUpdate is not a function" when I tried to inherit a prototype function of Phaser.Sprite.I have two "classes" the first one is ObjectPhysics of which inherit Phaser.Sprite and the second one is ObjectCoin of which inherit from ObjectPhysics. Here are the code for both "classes". When I run the game it returns.This error happens after this line of code. The code works if I remove ObjectPhysics and use ObjectCoin that inherit directly from Phaser.Sprite. So I think the problem here is that I do not know how to inherit class to another class yet. So, if someone know the solution I will be very happy . Link to comment Share on other sites More sharing options...
drhayes Posted August 25, 2015 Share Posted August 25, 2015 Your call to ObjectPhysics' constructor in ObjectCoin is wrong; its first param should be "this":ObjectPhysics.call(this, _x, _y, 'ImageCoin'); notalentgeek and samme 2 Link to comment Share on other sites More sharing options...
notalentgeek Posted August 25, 2015 Author Share Posted August 25, 2015 Okay it is working now. But what is "this" used for? I do not even put "this" as my first argument there in ObjectPhysics.Thanks! Link to comment Share on other sites More sharing options...
Staafsak Posted August 25, 2015 Share Posted August 25, 2015 Okay it is working now. But what is "this" used for? I do not even put "this" as my first argument there in ObjectPhysics.Thanks!https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this Link to comment Share on other sites More sharing options...
drhayes Posted August 26, 2015 Share Posted August 26, 2015 Functions are first-class in JavaScript, which means they can have properties, methods, and get passed around just like numbers and strings and objects. One of the methods on a function in JS is "call". The first parameter to call is the context in which the function will execute; i.e. what the value of "this" is within the function. Every other argument after the first is passed as an argument to the function. If I have a function defined like this:function foo(one, two) { this.one = one; this.two = two; this.three = this.dog + this.horse;}I can invoke its "call" method like this on any object I want:var catpants = { dog: 'hat', horse: 'poo'};foo.call(catpants, 'a', 'b');That would leave me with the object "catpants" with a property named "three" with the value of "hatpoo". Make sense? Here's the documentation for the call method. Link to comment Share on other sites More sharing options...
espace Posted November 8, 2016 Share Posted November 8, 2016 hi, i will follow this link especially with the object_physics.prototype i have this : //object_physics.js object_physics=function(Group,_x,_y,_sprite){ this.Group=Group Phaser.Sprite.call(this,game,_x,_y,_sprite) this.enableBody=true game.physics.arcade.enable(this) this.body.immovable=false this.Group.add(this) } object_physics.prototype=Object.create(Phaser.Sprite.prototype) object_physics.prototype.constructor=object_physics an in my paper.js : //paper.js Paper = function(game,Group,posx,posy) { this.posx=posx this.posy=posy this.Group=Group object_physics.call(this,game,this.Group,this.posx,this.posy,'rect_invisible') this.inputEnabled=true this.ombre=game.add.sprite(0,0,"sprite_paper") this.paper=[] for (var j = 0; j < 5; j++) { this.paper[j] = [] for (var i = 0; i < 1; i++) { this.paper[j][i] = this.ombre this.paper[j][i].tint=black this.paper[j][i].alpha=.2 this.paper[j][i].x = 2 this.paper[j][i].y =j*dim.paper this.Group.add(this.paper[j][i]) } } for (var j = 0; j < 5; j++) { for (var i = 0; i < 1; i++) { this.addChild(this.paper[j][i]) } } Paper.prototype = Object.create(object_physics.prototype) Paper.prototype.constructor=Paper and i have the same error : TypeError: this.onTextureUpdate is not a function [En savoir plus] what i'm doing wrong ? Link to comment Share on other sites More sharing options...
espace Posted November 9, 2016 Share Posted November 9, 2016 ok finded by myself https://jsfiddle.net/espace3d/9ubd4uhd/ Link to comment Share on other sites More sharing options...
Recommended Posts