Advice and tip for assignment new parent Sprites?

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,606
Reaction score
1,399
First Language
French
Primarily Uses
RMMV
hi
What are your advices or tricks for new parent assignment to a Sprites and the opportunity to return to the original parent.
example:
to change parent i do this
PHP:
Game_Picture.prototype.spine = function(id){
        var newParent = SceneManager._scene._spriteset._pictureContainer.children[id-1];
        var targetSprite= SceneManager._scene._spriteset._pictureContainer.children[this._PID-1];
        targetSprite.parent=newParent;
        return this
    };
For the moment I do as like this for keep the original parent sprites.
But I am not sure of the validity of this procedure.
PHP:
Game_Picture.prototype.spine = function(id){
        var newParent = SceneManager._scene._spriteset._pictureContainer.children[id-1];
        var targetSprite= SceneManager._scene._spriteset._pictureContainer.children[this._PID-1];
        targetSprite.originalParent = targetSprite.parent; // store Original parent in originalParent , for comeBack if need !
        targetSprite.parent=newParent;
        return this
    };
so when delete picture
PHP:
Game_Screen.prototype.erasePicture = function(pId) {
    this._pictures[pId] = undefined;

    var pictureChild = SceneManager._scene._spriteset._pictureContainer.children[pId-1];
    if(pictureChild.originalParent){// reset to original parent // TODO: check other way if possible
         pictureChild.parent = pictureChild.originalParent;
    }
};
Is there a way to go back (set Back) to the original parent, without making a total copy, for performance reasons?
Or can you confirm that this is the right ways to do?
thanks in advance for your suggestions
 
Last edited:

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
454
Reaction score
209
First Language
English
Primarily Uses
RMMV
Why not just store the id of the parent instead of the whole object? That way should be easy to go back to the original parent without having to store everything about it. :)
Also why are you returning this in the spine function? Basically you are returning the entire Game_Picture object, shouldn't it just be the targetSprite?
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,606
Reaction score
1,399
First Language
French
Primarily Uses
RMMV
Why not just store the id of the parent instead of the whole object? That way should be easy to go back to the original parent without having to store everything about it. :)
The parent assign by default are not all different?
What class do they come from?
I do not use id because original parent they seem to be all different.
Or I'm wrong.
this is example original parent from
SceneManager._scene._spriteset._pictureContainer.children[141]
And all picture seem to have diferent parent !?
Where i can find the containe of those original parent ?
44tt4t.jpg
Also why are you returning this in the spine function? Basically you are returning the entire Game_Picture object, shouldn't it just be the targetSprite?
This is the only technique I have found for chaining
awf3gt.jpg
Do you have another suggestion?
Ideally I allowed myself to add additional method chain, for some picture that will need it
PHP:
$gameScreen.showPicture('pid', 'fn', [origin], 'x', 'y').spine(id).setAngle(aN).setRot(sP).bindToMap(true).addProp({i:i})
is the good way ?
thank for your help

this is the entir proto i add.
PHP:
//□▼↓▼□═══════════════════════════════════════════════════□□═══════════════════════════════════════════════════□↓↓↓
Game_Picture.prototype.spine = function(spineID){
        this._parentSpinePID = spineID; // parent Reference info
        var parentSpine = SceneManager._scene._spriteset._pictureContainer.children[spineID-1];
        var childSpine = SceneManager._scene._spriteset._pictureContainer.children[this._PID-1];
        childSpine.originalParent = childSpine.parent;
        childSpine.parent=parentSpine;
        return this
    };
//□▲↑▲□═══════════════════════════════════════════════════□□═══════════════════════════════════════════════════□↑↑↑
//□▼↓▼□═══════════════════════════════════════════════════□□═══════════════════════════════════════════════════□↓↓↓
Game_Picture.prototype.setAngle = function(a){
        this._angle = a; return this
    };
//□▲↑▲□═══════════════════════════════════════════════════□□═══════════════════════════════════════════════════□↑↑↑
//□▼↓▼□═══════════════════════════════════════════════════□□═══════════════════════════════════════════════════□↓↓↓
Game_Picture.prototype.setRot = function(r){
    this._rotationSpeed = r; return this
    };
//□▲↑▲□═══════════════════════════════════════════════════□□═══════════════════════════════════════════════════□↑↑↑
//□▼↓▼□═══════════════════════════════════════════════════□□═══════════════════════════════════════════════════□↓↓↓
Game_Picture.prototype.bindToMap = function(){
    // voir si on peut ajouter le child a spritmap plutot TODO:
    this._BindToMap=true; return this
};
//□▲↑▲□═══════════════════════════════════════════════════□□═══════════════════════════════════════════════════□↑↑↑
//□▼↓▼□═══════════════════════════════════════════════════□□═══════════════════════════════════════════════════□↓↓↓
Game_Picture.prototype.addProp = function(prop){
    this._prop = prop; return this
};
//□▲↑▲□═══════════════════════════════════════════════════□□═══════════════════════════════════════════════════□↑↑↑
//□▼↓▼□═══════════════════════════════════════════════════□□═══════════════════════════════════════════════════□↓↓↓
// ERASE PICTURE AND PIXI PICTURE BINDED TO IM
Game_Screen.prototype.erasePicture = function(pId,trigger) { // trigger true , also deletter trigger
this._pictures[pId] = undefined;
if(trigger){delete this._lePictureTriggers[pId]}; // TODO: check if bug
var pictureChild = SceneManager._scene._spriteset._pictureContainer.children[pId-1];
if(pictureChild.children.length){ // removePixiText child
$gamePixiBank.removePixi(pId);
pictureChild.removeChildren();
};
// reset to original parent // TODO: voir les parent si bug pour reatribustion
if(pictureChild.originalParent){
pictureChild.parent = pictureChild.originalParent;
}
};
//□▲↑▲□═══════════════════════════════════════════════════□□═══════════════════════════════════════════════════□↑↑↑
 
Last edited:

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
454
Reaction score
209
First Language
English
Primarily Uses
RMMV
The parent assign by default are not all different?
I haven't worked much with sprites myself so I am not completely certain about the parent part but:
The _pictureContainer is a Sprite object this is all of your pictures top level parent. The next parent in the list will be either Spriteset_Map or Spriteset_Battle (both are in turn children of Spriteset_Base which is a child of Sprite) in order to check which one you are currently using you could check to see if the party is in battle or by using the instanceof method.

The Game_Screen.prototype.showPicture function creates a new Game_Picture object meaning you should be able to access all Game_Picture functions from the $gameScreen._pictures array. Instead of chaining your functions, I suggest putting the arguments for those other functions inside your spine function then have your spine function call the appropriate functions. Then all you would have to do is something like:
Code:
$gameScreen.showPicture('pid', 'fn', [origin], 'x', 'y');
$gameScreen._pictures[pid].spine(id, aN, sP, true, {i:i});
Basically by doing this you won't have to retype every function name every time you want to reuse your code.
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,606
Reaction score
1,399
First Language
French
Primarily Uses
RMMV
Basically by doing this you won't have to retype every function name every time you want to reuse your code.
$gameScreen.showPicture('pid', 'fn', [origin], 'x', 'y');
$gameScreen._pictures[pid].spine(id, aN, sP, true, {i:i});
I was using something similar before.
The problem is that duplicating code lines, and it quickly becomes hard to read.
I have to do some testing with performance.now();
To check if we have a very big difference of performance between return picture; and direct afectacion.

But logically only the sprite is returned.
because I return picture; at the time of creation.
PHP:
//□▼↓▼□═══════════════════════════════════════════════════□□═══════════════════════════════════════════════════□↓↓↓
    //QUAND AFFICHE UNE PICTURE AJOUTE AUSSI UN CONTENEUR EASING [DANS LE BON PID ARRAY]
    Game_Screen.prototype.showPicture = function(pictureId, name, origin, x, y, scaleX, scaleY, opacity, blendMode) {
        var picture = new Game_Picture();
        picture.show(pictureId, name, origin, x, y, scaleX, scaleY, opacity, blendMode);
        this._pictures[pictureId] = picture;
        this.iniEasingIAVRA(this._pictures[pictureId]); // create IAVRA to _picturesEasing[]
        return picture; // or this._pictures[pictureId]: TODO:need check performance.now();
    };
//□▲↑▲□═══════════════════════════════════════════════════□□═══════════════════════════════════════════════════□↑↑↑
And if I only want to activate the Bind, for example, without going through the other properties, the code becomes dificil to read.
PHP:
$gameScreen._pictures[pid].spine('', '', '', true); // hard to read. // hard read
/////
$gameScreen.showPicture(pid, fn, [], x,y).bindToMap();
The _pictureContainer is a Sprite object this is all of your pictures top level parent.
In fact after verification, it would seem that it works.
Instead of creating a copy of the parent to assign it when delete.
Simply add line at the time of suppressing the image.

I think this is the best way.
Or if i see other better suggestions.
PHP:
    // FAST WAY TO REASIGN PARENT ?
    if(this._parentSpinePID){
        pictureChild.parent = SceneManager._scene._spriteset._pictureContainer;
    }
 

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
454
Reaction score
209
First Language
English
Primarily Uses
RMMV
Alternatively instead of having more arguments, you could use a single object as the argument in the spine function. So something like this for instance:
Code:
//an example of using an object for arguments
Game_Picture.prototype.spine = function (object) {
    object.id ? console.log('id', object.id) : false;
    object.aN ? console.log('aN', object.aN) : false;
    object.sP ? console.log('sp', object.sP) : false;
    object.bind ? console.log('bind', object.bind) : false;
};
Then you can have a call like so without the other possible arguments:
Code:
$gameScreen._pictures[id].spine({bind: true}); // logs bind
$gameScreen._pictures[id].spine({id: 4, sP: 15}) // logs id and sP
Anyway I hope these suggestions help. :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 2)

Latest Threads

Latest Profile Posts

This little brat (my nephew) just invent a new way of enjoying his orange juice by pouring it inside of used perfume bottle and sprayed it to his mouth...
Jamaica? No, Aunty. I said, I'm on RPG Maker :*/
Lunar New Year is over :( but it's time to get back to work!
I keep giving myself deadlines because I'm so excited to finish something but I notice areas where I'm rushing the story and that's what's gonna weaken my overall project, gotta stop that

Forum statistics

Threads
93,690
Messages
914,658
Members
123,289
Latest member
mintminstrel
Top