Toddler's Forum Posts

  • Is there a way to create my own updated version of nw.js since construct 2's is not update anymore ?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Lite Tween have an "Enforce Mode": Enforce and Compromise.

    What does either of the two means ?

  • It's ok I have fixed it !

    Looks like my Delta time function works !

    Hopefully someone will find this useful.

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Delta Time</title>
    <style type="text/css">
    body,td,th 
    {
    	font-family: consolas;
    	font-weight:bold;
    	font-size: 50px;
    	color: #F90;
    }
    body 
    {
    	border:0;
    	margin:0;
    	padding:0;
    	background-color: #000;
    	overflow:hidden;
    }
    #container
    {
    	width:100vw;
    	height:100vh;
    	display:grid;
    	place-items:center;
    }
    #delta_Time
    {
    	color:#7f84ff;
    }
    </style>
    <script src="jquery-1.11.1.min.js"></script>
    <script>
    
    var Delta_Time_Last_Update = Date.now();
    var Delta_Time_Now = 0;
    var Delta_Time = 0;
    
    var delta_time_enterframe_handle = requestAnimationFrame(delta_time_enterframe);
    function delta_time_enterframe(event)
    {
    	Delta_Time_Now = Date.now();
    	Delta_Time = (Delta_Time_Now - Delta_Time_Last_Update) / (1000/60);
    	Delta_Time_Last_Update = Delta_Time_Now;
    	
    	$("#delta_Time").html(Delta_Time);
    	$("#ball").css("left",(parseFloat($("#ball").css("left").replace(/[^-\d\.]/g, ''))+(0.2 * Delta_Time))+"px");
    	console.log($("#ball").css("left").replace(/[^-\d\.]/g, ''));
    	
    	delta_time_enterframe_handle = requestAnimationFrame(delta_time_enterframe);
    	//cancelAnimationFrame(delta_time_enterframe_handle);
    }
    </script>
    
    </head>
    
    <body>
    <div id="container">
    <table width="800px" border="1">
    <tr>
    <td align="right" style="color:#cc99cc;" width="330px">Delta Time:</td>
    <td>
    <div id="delta_Time" style="margin-left:7px;">
    0000
    </div>
    </td>
    </tr>
    </table>
    </div>
    <div id="ball" style="position:absolute; left:10px; top:10px; background-color:#0F0; width:100px; height:100px; border-radius:100px;"></div>
    </body>
    
    </html>
    
    
  • <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Delta Time</title>
    <style type="text/css">
    body,td,th 
    {
    	font-family: consolas;
    	font-weight:bold;
    	font-size: 50px;
    	color: #F90;
    }
    body 
    {
    	border:0;
    	margin:0;
    	padding:0;
    	background-color: #000;
    	overflow:hidden;
    }
    #container
    {
    	width:100vw;
    	height:100vh;
    	display:grid;
    	place-items:center;
    }
    #delta_Time
    {
    	color:#7f84ff;
    }
    </style>
    <script src="jquery-1.11.1.min.js"></script>
    <script>
    
    var Delta_Time_Last_Update = Date.now();
    var Delta_Time_Now = 0;
    var Delta_Time = 0;
    
    var delta_time_enterframe_handle = requestAnimationFrame(delta_time_enterframe);
    function delta_time_enterframe(event)
    {
    	Delta_Time_Now = Date.now();
    	Delta_Time = (Delta_Time_Now - Delta_Time_Last_Update) / (1000/60);
    	Delta_Time_Last_Update = Delta_Time_Now;
    	
    	$("#delta_Time").html(Delta_Time);
    	$("#ball").css("left",(parseFloat($("#ball").css("left").replace(/[^-\d\.]/g, ''))+0.2)*Delta_Time+"px");
    	console.log($("#ball").css("left").replace(/[^-\d\.]/g, ''));
    	
    	delta_time_enterframe_handle = requestAnimationFrame(delta_time_enterframe);
    	//cancelAnimationFrame(delta_time_enterframe_handle);
    }
    </script>
    
    </head>
    
    <body>
    <div id="container">
    <table width="800px" border="1">
    <tr>
    <td align="right" style="color:#cc99cc;" width="330px">Delta Time:</td>
    <td>
    <div id="delta_Time" style="margin-left:7px;">
    0000
    </div>
    </td>
    </tr>
    </table>
    </div>
    <div id="ball" style="position:absolute; left:10px; top:10px; background-color:#0F0; width:100px; height:100px; border-radius:100px;"></div>
    </body>
    
    </html>
    
    
    I couldn't get it to work, deltatime is not accurate, if I remove delta time everything works perfectly.
    
  • var Delta_Time_Last_Update = Date.now();
    var Delta_Time_Now = 0;
    var Delta_Time = 0;
    
    var delta_time_enterframe_handle = requestAnimationFrame(delta_time_enterframe);
    function delta_time_enterframe(event)
    {
    	Delta_Time_Now = Date.now();
    	Delta_Time = (Delta_Time_Now - Delta_Time_Last_Update) / (1000/60);
    	Delta_Time_Last_Update = Delta_Time_Now;
    	
    	$("#delta_Time").html(Delta_Time);
    	
    	
    	delta_time_enterframe_handle = requestAnimationFrame(delta_time_enterframe);
    	//cancelAnimationFrame(delta_time_enterframe_handle);
    }

    This code works and almost always reports 0.969999998~

    Is this more or less the way Construct 2 get its dt ?

    Thanks !

  • What is the diff between a global variable and a local variable with static checked ?

    They both retain their data so...

  • BadMario, your method is insane ! You must be a genius, this is way too much for me.

    I will use dop2000 is sleeping method for now.

  • How do I detect when all physics object has finally come to a complete stop ?

  • Found it:

    "https://www.scirra.com/manual.zip"

  • Here:

    scirra.com/manual/87/8-direction

    On the left side it says "Download the Official Construct 2 Manual (2.2mb)".

    It will try to link to "https://www.scirra.com/manual/87/manual.zip"

    which will bring you...back to the page you click it from...

  • Wow, that's just painful...

  • Simplifying the codes, removing all unnecessary stuff, I know there are two functions with the same name but I am still simplifying the function to make it a self contain useful function for now so naming doesn't matter for now, still work in progress:

    function shake()

    {

    this.shakeMag = 0;

    this.shakeStart = 0;

    this.shakeEnd = 0;

    this.shakeMode = 0;

    this.shakeEnforcePosition = 0;

    this.shakeOriginalX = 0;

    this.shakeOriginalY = 0;

    this.axis = 0;

    }

    function tick2()

    {

    if (!this.enabled)

    {

    return;

    }

    // Is in a shake?

    var now = this.runtime.kahanTime.sum;

    var offx = 0, offy = 0;

    if (now >= this.shakeStart && now < this.shakeEnd)

    {

    var mag = this.shakeMag * Math.min(this.runtime.timescale, 1);

    // Mode 0 - reducing magnitude - lerp to zero

    if (this.shakeMode === 0)

    {

    mag *= 1 - (now - this.shakeStart) / (this.shakeEnd - this.shakeStart);

    }

    var a = Math.random() * Math.PI * 2;

    var d = Math.random() * mag;

    offx = Math.cos(a) * d;

    offy = Math.sin(a) * d;

    }

    //update only when necessary and one more time to enforce object position

    if (offx != 0 || offy != 0 || (this.shakeEnforcePosition === 1 && this.shakeStart > 0))

    {

    if (this.axis == 1)

    {

    this.inst.x = this.shakeEnforcePosition ? this.shakeOriginalX + offx : this.inst.x + offx;

    }

    else if (this.axis == 2)

    {

    this.inst.y = this.shakeEnforcePosition ? this.shakeOriginalY + offy : this.inst.y + offy;

    }

    else

    {

    this.inst.x = this.shakeEnforcePosition ? this.shakeOriginalX + offx : this.inst.x + offx;

    this.inst.y = this.shakeEnforcePosition ? this.shakeOriginalY + offy : this.inst.y + offy;

    }

    this.inst.set_bbox_changed();

    //turn off

    if (this.shakeEnforcePosition === 1 && now > this.shakeEnd)

    {

    this.shakeStart = 0;

    }

    }

    }

    function Shake(mag, dur, mode, enforcePosition, axis)

    {

    this.shakeMag = mag;

    this.shakeStart = this.runtime.kahanTime.sum;

    this.shakeEnd = this.shakeStart + dur;

    this.shakeMode = mode;

    this.shakeEnforcePosition = enforcePosition;

    this.shakeOriginalX = this.inst.x;

    this.shakeOriginalY = this.inst.y;

    this.axis = axis;

    }

  • // ECMAScript 5 strict mode

    "use strict";

    assert2(cr, "cr namespace not created");

    assert2(cr.behaviors, "cr.behaviors not created");

    /////////////////////////////////////

    // Behavior class

    cr.behaviors.lgshake = function(runtime)

    {

    this.runtime = runtime;

    this.shakeMag = 0;

    this.shakeStart = 0;

    this.shakeEnd = 0;

    this.shakeMode = 0;

    this.shakeEnforcePosition = 0;

    this.shakeOriginalX = 0;

    this.shakeOriginalY = 0;

    this.axis = 0; //eklenen

    };

    (function ()

    {

    var behaviorProto = cr.behaviors.lgshake.prototype;

    /////////////////////////////////////

    // Behavior type class

    behaviorProto.Type = function(behavior, objtype)

    {

    this.behavior = behavior;

    this.objtype = objtype;

    this.runtime = behavior.runtime;

    };

    var behtypeProto = behaviorProto.Type.prototype;

    behtypeProto.onCreate = function()

    {

    };

    /////////////////////////////////////

    // Behavior instance class

    behaviorProto.Instance = function(type, inst)

    {

    this.type = type;

    this.behavior = type.behavior;

    this.inst = inst; // associated object instance to modify

    this.runtime = type.runtime;

    };

    var behinstProto = behaviorProto.Instance.prototype;

    behinstProto.onCreate = function()

    {

    this.enabled = (this.properties[0] !== 0);

    };

    behinstProto.saveToJSON = function ()

    {

    return {

    "smg": this.shakeMag,

    "ss": this.shakeStart,

    "se": this.shakeEnd,

    "smd": this.shakeMode

    };

    };

    behinstProto.loadFromJSON = function (o)

    {

    this.shakeMag = o["smg"];

    this.shakeStart = o["ss"];

    this.shakeEnd = o["se"];

    this.shakeMode = o["smd"];

    };

    behinstProto.tick = function ()

    {

    // Do work in tick2 instead, to eliminate one-frame lag if object position changes in events

    };

    function getShakeBehavior(inst)

    {

    var i, len, binst;

    for (i = 0, len = inst.behavior_insts.length; i < len; ++i)

    {

    binst = inst.behavior_insts;

    if (binst.behavior instanceof cr.behaviors.lgshake)

    return binst;

    }

    return null;

    };

    behinstProto.tick2 = function ()

    {

    if (!this.enabled)

    return;

    // Is in a shake?

    var now = this.runtime.kahanTime.sum;

    var offx = 0, offy = 0;

    if (now >= this.shakeStart && now < this.shakeEnd)

    {

    var mag = this.shakeMag * Math.min(this.runtime.timescale, 1);

    // Mode 0 - reducing magnitude - lerp to zero

    if (this.shakeMode === 0)

    mag *= 1 - (now - this.shakeStart) / (this.shakeEnd - this.shakeStart);

    var a = Math.random() * Math.PI * 2;

    var d = Math.random() * mag;

    offx = Math.cos(a) * d;

    offy = Math.sin(a) * d;

    }

    //update only when necessary and one more time to enforce object position

    if (offx != 0 || offy != 0 || (this.shakeEnforcePosition === 1 && this.shakeStart > 0)) {

    if (this.axis == 1){

    this.inst.x = this.shakeEnforcePosition ? this.shakeOriginalX + offx : this.inst.x + offx;

    }

    else if (this.axis == 2){

    this.inst.y = this.shakeEnforcePosition ? this.shakeOriginalY + offy : this.inst.y + offy;

    }

    else{

    this.inst.x = this.shakeEnforcePosition ? this.shakeOriginalX + offx : this.inst.x + offx;

    this.inst.y = this.shakeEnforcePosition ? this.shakeOriginalY + offy : this.inst.y + offy;

    }

    this.inst.set_bbox_changed();

    //turn off

    if (this.shakeEnforcePosition === 1 && now > this.shakeEnd)

    this.shakeStart = 0;

    }

    };

    //////////////////////////////////////

    // Actions

    function Acts() {};

    Acts.prototype.Shake = function (mag, dur, mode, enforcePosition,axis)

    {

    this.shakeMag = mag;

    this.shakeStart = this.runtime.kahanTime.sum;

    this.shakeEnd = this.shakeStart + dur;

    this.shakeMode = mode;

    this.shakeEnforcePosition = enforcePosition;

    this.shakeOriginalX = this.inst.x;

    this.shakeOriginalY = this.inst.y;

    this.axis = axis; //eklenen

    };

    Acts.prototype.SetEnabled = function (e)

    {

    this.enabled = (e !== 0);

    };

    behaviorProto.acts = new Acts();

    }());

    This is the source code the object shake.

    So useful across the board.

    I am going to try to reduce it to a generic JavaScript function, preferably:

    Object_Shake(Any_Dom_Div, Magnitude, Duration, Reducing_magnitude, Enforce_position, shake_x_y); //Arguments have been exaggeratedly verbose to make it easier to explain intention.

  • You are such a God for helping, thank you !

  • Is there a way to create an external JavaScript file that holds Objects and Functions and basically all the heavy lifting stuff and use Construct 2 merely as a graphic placement IDE ?