Jump to content

Inheritance (OOP) error in Phaser "this.onTextureUpdate is not a function".


notalentgeek
 Share

Recommended Posts

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".

52Fegvz.png

QmPEtwN.png

 

When I run the game it returns.

6xootl8.png

This error happens after this line of code.

ke38soC.png

 

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

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

  • 1 year later...

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...