random boolean + reverse equation?

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
hi, there is a more elegant way to write this code ?
in my context, i would like to inverse the proprety easeX but randomly.

PHP:
            if(Boolean(Math.round(Math.random()))){ obj.easeX = ~obj.easeX+1;};
            if(Boolean(Math.round(Math.random()))){ obj.easeY = ~obj.easeY+1;};
if one have a beter sugestion.
because it is a little heavy for make a simple random reverse.
but I can't imagine another way cleaner.
thank you
 
Last edited:

Clock Out

Veteran
Veteran
Joined
Jun 14, 2016
Messages
92
Reaction score
45
First Language
English
Primarily Uses
RMMV
So the code should flip the sign of the number and the expression of the if statement generates either a 1 or 0. I think this can be simplified.
Code:
if (Math.random() < 0.5) {
    obj.easeX  *= -1;
}
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
yes thank you, after sleeping, the solution jumps to my eyes, these fascinate how the brain becomes useless with exhaustion.

PHP:
var end = (function(){ //register Closures setup
        var easeX = setup.xStrength||0;
        var easeY = setup.yStrength||0;
        var rot = setup.rotStrength||0;
        var time = setup.time||100;
        var oX = pixiBox.x;
        var oY = pixiBox.y;
        return function(obj){
            var rand1 = Math.random();
            var rand2 = Math.random();
            if(rand1>0.5){ easeX = ~easeX+1;};
            if(rand2>0.5){easeY = ~easeY+1;};
          this._valuesEnd = {x:oX+(rand1*easeX+1), y:oY+(rand2*easeY+1), rotation:(rand1*rot)/100 };
          this.duration(rand1*time+time);
          this.start();
        };
    })();
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,865
Messages
1,017,059
Members
137,575
Latest member
akekaphol101
Top