Toddler's Recent Forum Activity

  • // 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 ?

  • The whole construct 2 Admob thingy has been a problem for a while now...

    I have long given up on Construct 2 and Admob integration.

  • Is there a plugin [this is definitely not a behavior but a plugin] that can detect what is the current vertical and horizontal mouse direction ?

    For example:

    mouse.getHorizontal :: returns "left" or "right"

    mouse.getVertical :: returns "up" or "down"

    I can handle the javaScript code:

    addEventListener("mousemove", getMouseDirection, false);

    var xDirection = "";

    var yDirection = "";

    var oldX = 0;

    var oldY = 0;

    function getMouseDirection(e)

    {

    //deal with the horizontal case

    if (oldX < e.pageX)

    {

    xDirection = "right";

    }

    else

    {

    xDirection = "left";

    }

    //deal with the vertical case

    if (oldY < e.pageY)

    {

    yDirection = "down";

    }

    else

    {

    yDirection = "up";

    }

    oldX = e.pageX;

    oldY = e.pageY;

    console.log(xDirection + " " + yDirection);

    }

    But I do not know how to "package" this into a plugin, does anyone know how to pack this into a plugin ?

  • Is anyone still using this Addon ?

    I checked out the example and I see no real advantage over the native scrollTo effect beyond the "catching up to the player" effect while the native one follows directly with no lag.

    What are you using this for that the native scrollTo can't do ?

  • First of all, thank you.

    I appreciate the effort you took to type out all these codes, really thank you.

    However, it is just not the same, I do not know how to call that function from within JavaScript, this only works for hovers and stuff, it's not like I can call that CSS function from JavaScript when an enemy is attacked shake the enemy right ?

    Second of all, even if that were possible, that CSS alternative is just no match for the real deal in this add-on.

    It not only have control over Magnitude and Duration [Duration is a big deal], you also have the almighty "Reducing Magnitude" mode.

    AND AND AND it have the ability to enforce its position at the end !

    This is truly the most powerful add-on for object shake, I just wish I can isolate the add-on's code that does this, there are so many wrapper codes in the add-on to make it into an add on :-(

  • This is such a useful plugin, can someone PLEASE convert this to a basic JavaScript function like:

    shake(object, are the rest of the argument this add-on requires);

    So that we can use it for everyday JavaScript DOM elements outside Construct 2 ?

  • Hi, not sure if this is a bug, but it can be replicated.

    Apply the behavior to a button .

    Make it so that when you click it it shakes [Enforce Position].

    If you click and wait for the shake to end, the position will indeed be respected.

    Now...

    Click it again and again really fast.

    Soon the button will no longer be at its original position even though Enforce Position is on.

  • Man I hate to put it to you like this man but I am SICK of your condescending attitude.

    First of all you should thank the people here who have been helping you improve your plug-in instead of constantly berating whether they can pick up a spoon every time they are asking a question.

    I am so SICK of your attitude that I really hope I can restraint myself from replying to your thread ever again.

    Frankly, you are not that smart yourself, your code is an extrapolation of at least three existing construct 2 plug-in on further inspection and you did NOT once give ANY credit to the developer you rip the idea off of, I am not going to name names, you really should do the right thing yourself before you got found out anyways.

    ========================================================================

    One:

    valerypopoff

    I don't think that you actually meant polymorphism. Polymorphism means something else.

    ========================================================================

    First of all, it means EXACTLY what I say it means, I said it is a form of "extends", let me just bring out one example, this applies to any programming language that support it and not just AS3.

    adobe.com/devnet/actionscript/learning/oop-concepts/polymorphism-and-interfaces.html

    Notice method two, the usage of "extends" to create Polymorphism.

    So, to use the same attitude you have been using towards everyone here, do you even know what Polymorphism is ?

    The audacity to say it have nothing to do with extends is not only incorrect, but misleading to anyone who is trying to learn programming beyond drag and drop Construct 2.

    You are not really as smart as you paint yourself up to be so I would suggest your tone down your baseless constant need to put people down.

    ========================================================================

    Two:

    valerypopoff

    I don't know what you mean by "make instance of a sprite HAVE an instance of js class". You certainly can if you just imagine that this is the case. Create two instances of a sprite. Create two instances of a js class. Done. They HAVE each other. Do whatever you want with them.

    ========================================================================

    That would defeat the very purpose of object orientated programming, that would defeat the whole reason why I would even create a class for a sprite in the first place which is what your plug-in will be use for.

    The idea is for every new sprite/object spawned, it will have its own base class during runtime, not just and only during editing.

    You mentioned your plug-in is to be used for the "view-model-controller" model, I hate to break it to you man, but since you are absolutely insidious on anyone who even ask you a question, any question at all and have seemingly no respect to your user at all, I am going to give you a feel of your own speech and to you, do you even know what true view model controller actually is ?

    I have been programming using Objective-C using XCode and the way it works is the true assertion of the "model-view-controller" framework and your plug-in ain't it.

    Your plug-in could be used to extend a sprite, but seeing that your answer is first to insult my intellect and then proceed to say the most ridiculous answer which is manually create a class for each object during editing time, dude, all I am going to say is, you are really not as smart as you make yourself up to be and that is putting it mildly.

    I am done with your condescending attitude and I am going to restrain myself from replying from now on.

  • Thanks for telling me that you have creating html 5 projects from scratch.

    I use CreateJS and Babylon.js to do massive html 5 projects that isn't game based so I am not exactly "stupid" if that is what you are implying.

    And I can play sound in createJS JUST FINE without needing to upload to a server/proxy server.

    No I still DON'T see the point of construct 2 needing to be uploaded to a server or proxy server just to be viewable, it STILL doesn't make sense.

    What is it that construct 2 need that required a server situation ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • What exactly is construct 2 doing that NEED it to be uploaded for it to be viewable ?

    I type HTML code all the time and I don't see no need to "upload to a server" to view it unless I use offline CDN links and libraries.

Toddler's avatar

Toddler

Member since 19 Jan, 2012

Twitter
Toddler has 1 followers

Trophy Case

  • 12-Year Club
  • Forum Contributor Made 100 posts in the forums
  • Email Verified

Progress

14/44
How to earn trophies