Spoiler
Adding a function to the Game_Variables prototype will make that function callable from any instance of it, as you've seen. The reason the second bit doesn't work is that Hud_Displacement doesn't have an A function. You would have to define A in that class for it to be callable this way.
Yes but should not it inherit methods of gameVariables?
because i create it in $gameVariables at start
$gameVariables.Hud_Displacement= new Hud_Displacement();
Of what I read, even if a method does not exist, javascript will search all the existing sub-methods of the object.
What would be the right way, because for now, I am forced to add it manually to each object, and I find it not super clean.
The real context is this.
Boot Game
Spoiler
Code:
// les item action son mintenant lier a des etiquette dans le menue
//-----------------------------------------------------------------------------
/////////////CONSTRUCTOR OBJET DEPENDANCE (WHEN GAME BOOT)/////////////////////
/////Tous les objets, stokage variable permanante nessesaire a ce plugin //////
//-----------------------------------------------------------------------------
// ici on ajoute tous les besoin constructeur au boot.
alias_HUDSTATS_initialize = DataManager.setupNewGame;
DataManager.setupNewGame = function() {
alias_HUDSTATS_initialize.call(this);
// LES PLUGIN
$gameVariables.Avatar1 = new Avatar1(); //built avatar 1
$gameVariables.Avatar2 = new Avatar2(); //built avatar 2
/*
L'ordre des builts ici a une important carlinitialisation renvoi le pid final dans objets
une foi lorbjet pid final existe il reste permanent
*/
var NewPid = 20; // pid de depart pour built tous les menue visuel // en theorit less 2 pid disponible entre chaque menue et hud
// GIVE FINALPID IF FIRT TIME CONSTRUCTOR
//Hud_PinBoard
Hud_PinBoard.prototype.RequestStopAnimation = RequestStopAnimation; // PROTOTYPE
Hud_PinBoard.prototype.MoveAnime = MoveAnime; // PROTOTYPEA
$gameVariables.Hud_PinBoard = new Hud_PinBoard(NewPid);
var NewPid = Preload_Hud_PinBoard(); // initialise et return End.Pid
console.log('Preload_Hud_PinBoard EndNewPid: ', NewPid);
//Hud_Displacement
Hud_Displacement.prototype.RequestStopAnimation = RequestStopAnimation; // PROTOTYPE
Hud_Displacement.prototype.MoveAnime = MoveAnime; // PROTOTYPEA
$gameVariables.Hud_Displacement = new Hud_Displacement(NewPid);
var NewPid = Preload_Hud_Displacement(); // initialise et return End.Pid
console.log('Preload_Hud_Displacement EndNewPid: ', NewPid);
//Hud_Info
Hud_Info.prototype.RequestStopAnimation = RequestStopAnimation; // PROTOTYPE
Hud_Info.prototype.MoveAnime = MoveAnime; // PROTOTYPEA
$gameVariables.Hud_Info = new Hud_Info(NewPid);
var NewPid = Preload_Hud_Info(); // initialise et return End.Pid
console.log('Preload_Hud_Info EndNewPid: ', NewPid);
//Hud_States
Hud_States.prototype.RequestStopAnimation = RequestStopAnimation; // PROTOTYPE
Hud_States.prototype.MoveAnime = MoveAnime; // PROTOTYPEA
$gameVariables.Hud_States = new Hud_States(NewPid);
var NewPid = Preload_Hud_States(); // initialise et return End.Pid
console.log('Preload_Hud_States EndNewPid: ', NewPid);
console.log('window: ', window); // HELPER CONSOL
};
The method i tries to add to all my object Without doing it manually, with prototype is
Spoiler
Code:
//STOP ANIMATION
//OBJECT ARE VAR IN $gameVariables:: PBoard, DHud, HStat, HInfo, Avatar ....
//RequestStopAnimation.call(Object)
function RequestStopAnimation() {
for (var i = 0; i < this.LavraAnime.length; i++) {
this.LavraAnime[i].stop();
}
}
//CREATE ANIMATION IN [ARRAY]
//OBJECT ARE VAR IN $gameVariables:: PBoard, DHud, HStat, HInfo, Avatar ....
//MoveAnime.call(Object,param1, param2,)
function MoveAnime(PID, Proprety, EaseType, EaseMode, TimeMove, Delay) {
if (!(Proprety instanceof Array)) {
this.LavraAnime.push(new IAVRA.ANIMATE.Tween($gameScreen.picture(PID), Proprety).easing(IAVRA.EASING[EaseType][EaseMode]).duration(TimeMove).delay(Delay).start())
} else {
this.LavraAnime.push(new IAVRA.ANIMATE.Tween($gameScreen.picture(PID), Proprety[0]).easing(IAVRA.EASING[EaseType][EaseMode]).duration(TimeMove).delay(Delay).chain
(new IAVRA.ANIMATE.Tween($gameScreen.picture(PID), Proprety[1]).easing(IAVRA.EASING[EaseType][EaseMode]).duration(TimeMove)).start())
}
}
//TIME ANIMATION CALCULATOR MS
function SpeedFrameForMove(TimeMove) {
return ((TimeMove * 1000) / 60);
}
And this is a example of one of
object created.
with the proprety this.LavraAnime, And I want to call the method to modify the objects consequently
Spoiler
Code:
//-----------------------------------------------------------------------------
/////////////CONSTRUCTOR OBJET DEPENDANCE (WHEN GAME BOOT)/////////////////////
/////Tous les objets, stokage variable permanante nessesaire a ce plugin //////
//-----------------------------------------------------------------------------
// Built 1 time at BOOTGAME or NEWGAME
// $gameVariables.Hud_Displacement
// Objet parametre Hud_Displacement, tous les objets important du Hud_Displacement, + objet predefenie ou variable
function Hud_Displacement(NewPid) {
//STATUS
this.Status = function () { if($gameScreen._pictures[this.Pid()] !== undefined) { return true; } return false; } //Check si initialiser(PreLoad) true sinon false
this.PositionMode = null; // THE CURRENT HUD POSITION (Null: DELETED IN MEMORY, 'HideXY': HIDE, 'MapBaseXY': SHOW...)
//--PICTURE ID
this.Pid = function () { return this.NewPid }; // RETURN INITIAL PID
this.NewPid = NewPid; // GET THE PID PROPRETY FROM THE BOOT CONSTRUCTOR: ANFT_BOOTGAME.js
this.EndPid = null; // GET THIS VALUR AT END OF PRELOAD_FUNCTION
//--GLOBAL POSITION [x,y]
this.HideXY = [-50, 980]; // POSITION FOR TEMPORY HIDDING HUD
this.MapBaseXY = [100, 800]; // DEFAULT POSITION FOR GAME PLAY
this.SelectOptionXY = [700, 300] // POSITION WHEN SELECT OPTION HUD ARE SHOW
//--TIMER
this.Timer = null; // ALL TIMER RELATED TO THIS HUD IF NEED
//--FUNCTION MOVE LAVRA
this.LavraAnime = []; // Stoke les animation easing
//SLOT ITEM
this.SlotPos = [[-65,39],[0,65],[65,39]]
//--FUNCTION DE CALCUL ET RETOUR
//--// PIXITEXT MODELE
// pour LV,
this.TextStyle1 = { align: 'center',fontSize: 38,fontWeight: 'bold',strokeThickness: 8 }
// SOUS LE STAMINA INFO RESET ... ?
this.TextStyle2 = { align: 'center',fontSize: 12,fontWeight: 'bold',strokeThickness: 6 }
}
//---