Ruskul's Forum Posts

  • You can use the layer name in expressions instead of the index. So something like LayerOpacity("Layer 1") would work. You can also do the same thing with imagepoints, either use an index or the name.

    Right, But then those references are prone to being broken if you change the name right? They also don't auto complete unless I am mistaken. I'm not saying its an un winnable situation, just slightly sub optimal. I never notice it until I get into heavy layer usage, which typically I try to keep to a minimum and in locations I can easily change later if I have to reorganize.

  • So I was curious, why are different ways for storing names in construct 2 used?

    Variables can be named and referred to by that name. You can change the name and the change is reflected across the project.

    Layouts are the same - you can only reference them by name and changing the name changes the project references to that layout.

    But groups, function names, and layer names... When referencing these things you get a handy autofill (which didn't used to exist for some things) but nonetheless, if you change anything about these guys it will not change your original references to them... you'll have to go through the project and make sure the changes are reflected when you call them.

    Its no big deal... I think coming up with group and function names and sticking to those names is a simple organizational exercise with a smidgen of foresight... But layers are hard to name and keep in the same order for the duration of the project. I always find myself realizing that I would like an extra layer inbetween these other layers, or something.

    Since you can refer to layers by name, it doesn't matter for actions, but expressions refer to the layer by number! One could set up a system of constants and just refer to the constant, but that seems like the sort of thing construct should already be handling. Its a pain to be half way through a project and realize you need to completely re arrange layers to support some fancy blending mode you realized you couldn't live without. Then you have to go back and manually change all layer expressions

    Am I missing something?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ya you are right, I realized when looking at the change angle that it only changes the angle if it is different. You might try getting Ashley to weigh in on the conversation. There have been a few times when I wanted to do something but didn't know if I was overlooking something or if it was part of the blackbox portion of c2 we can't touch.

    Either way, he might add it to an update if it is something simple. One workaround you might try is simply to add an offset vector and store it to the sprite. you could then use that offset to artificially change its position for visual appearance or use it in collision detection as overlapping offset. I know it doesn't actually address the problem though.... Personally I hate workarounds even if they did work perfectly, lol but here I am offering a "why don't you do this instead" type comment...

    It is a bit of a conundrum.

  • Well, you can strike my last comment. When an angle is changed, contruct 2 calls bbox changed after updating the angle. hmmm

  • Its cool you have gotten this far with it. For claiming to not know much code, you are well on your way. I am curious, I know its not ideal but can you set the angle of the sprite to itself.angle right after changing the polygon. You said that updates the polygon right? You could simply call it good if it works from there... I say this, but that solution would drive me up the wall...

    So, what I think is, I imagine that internally contruct 2 only refreshes the polygon when it needs to. Basically, Lets say you have the polygons points stored in A. When construct 2 runs, it stores a new set of points in B. These are calculated based on the rotation and scale of the sprite. Calculating B takes a bit of work and there is no reason to perform that work every tick unless you have to. Changing an angle or scale would be a good reason to recalculate B. If you think about it, A is only useful for calculating B, where B is actually the real points of a collision polygon in the game world. Does this all make sense? Its the same reason you tell construct 2 to update the bbox. There is no reason to recalculate its position when it isn't changing. The same thing is true of the collision polygons points relative positions based on rotation.

    I think if you look into the sprite you might find a clue in .SetAngle()... I am going to take a peek when I get a chance, but thats where I would start.

    I am completely pulling this out of nowhere, just a hunch. But it would explain why

  • Any chance you could do a quick copy paste of the code? I can't download the files currently but I could look at the code if it were here. Thanks!

  • - sorry about that, glad you figured it out. I typically comment all the things I change so I can find them again but I must have missed that!

  • Colludium - One more thing, make sure you back up any project game file before trying this stuff out. If you add this and then take it out later, or be dumb like me you can find nefarious and subtle ways to corrupt a save file. This is true of adding and changing any behavior in a project. Mostly problems exist when you remove an action or property that a save file references.... and let me tell you, editing the construct 2 json file is not fun but is the only way to fix it if you have no backup.

  • Colludium you may find the above post showing how to enable prismatic joints useful. You might find a use for it that you can't live without

  • Okay, I found the files I needed. I had them saved in a weird spot. If I had lost all that work I would have deserved an award for worst file management ever.

    If you have any trouble understanding my directions, let me know.

    First, make sure you backup the physics behavior. You can edit it directly if you want but as noted above this presents certain risks. Either way you should make a backup of both the vanilla and edited versions.

    If I recall, the prismatic joint can act wonky if you don't understand how it works so if you are not familiar with it you can check out box2d documentation on it. I kept the names of the parameters the same, so it should make sense.

    In the edittime file you will want to add the following action beneath the others:

    --------------------------------------------------------------------------------

    //Limited Prismatic joint

    AddAnyTypeParam("This image point", "Name or number of image point on this object to connect object to. Use 0 for the center of gravity and -1 for the object origin.");

    AddObjectParam("Object", "The object to attach.");

    AddNumberParam("Lower translation", "The lower limit of translation allowed, in pixels.");

    AddNumberParam("Upper translation", "The upper limit of translation allowed, in pixels.");

    AddNumberParam("Angle", "The angle to which translation will be constrained to, in degrees");

    AddAction(28, af_none, "Create limited Prismatic joint", "Joints", "Create {my} limited Prismatic joint at image point {0} to {1}, limited from {2} to {3} pixels, at {4} degrees", "Connect another object to a point on this object and limit the range of movement along a particular Axis.", "CreateLimitedPrismaticJoint");

    -----------------------------------------------------------------------------------------------------------------------------------------------------

    In the runtime file, things are a little less straight forward than kinematics. you need to add the corresponding action: (make sure you add it in the right area, just to keep things tidy. Just scroll down till you find the other Acts.prototype.something.

    ----------------------------------------------------------------------------------------------------------------------------------------------------

    // Added by Ruskul

    // type 3, takes 5 params

    Acts.prototype.CreateLimitedPrismaticJoint = function (imgpt, obj, lower, upper, angle)

    {

    if (!obj || !this.enabled)

    return;

    var otherinst = obj.getFirstPicked(this.inst);

    if (!otherinst || otherinst == this.inst)

    return;

    if (!otherinst.extra.box2dbody)

    return; // no physics behavior on other object

    this.myCreatedJoints.push({type: 3, params:

    });

    this.doCreateLimitedPrismaticJoint(imgpt, otherinst.uid, lower, upper, angle);

    };

    behinstProto.doCreateLimitedPrismaticJoint = function (imgpt, otherinstuid, lower, upper, angle)

    {

    if (!this.enabled)

    return;

    var otherinst = this.runtime.getObjectByUID(otherinstuid);

    if (!otherinst || otherinst == this.inst || !otherinst.extra.box2dbody)

    return;

    otherinst.extra.box2dbody.c2userdata.joiningMe.add(this.inst);

    var myx = this.getInstImgPointX(imgpt);

    var myy = this.getInstImgPointY(imgpt);

    var jointDef = new b2PrismaticJointDef();

    jointDef.Initialize(this.body, otherinst.extra.box2dbody, getTempVec2a(myx * worldScale, myy * worldScale), getTempVec2b(1,0));

    jointDef.set_lowerTranslation(lower * worldScale);

    jointDef.set_upperTranslation(upper * worldScale);

    //if (lower <= 0 & upper >= 0) // make sure upper and lower don't exceed 0

    jointDef.set_enableLimit(true);

    this.myJoints.push(this.world.CreateJoint(jointDef));

    };

    // /End added by ruskul

    ----------------------------------------------------------------------------------------------------------------------------------------------------

    Next , in the following function "behinstProto.recreateMyJoints = function()" add an additional case:

    -----------------------------------------------------------------------------------------------------------------------------------------------------

    // added for ruskuls additions

    case 3:

    this.doCreateLimitedPrismaticJoint(j.params[0], j.params[1], j.params[2], j.params[3], j.params[4]);

    break;

    -------------------------------------------------------------------------------------------------------------------------------------------------------

    This should be in the switch statement right above default:.

    Now, I didn't provide any expressions or the like for determining if this joint exists, but setting those up shouldn't be to hard. I never needed them so I didn't add them but if you find you do and need some help, let me know.

    Also, there may be bugs. I'm not sure because I never use save game, but I imagine if you try to save the game, this might break. I never use the giant save everything feature in construct and only ever save specific variables to local storage so, again, this hasn't affected me. If this makes a bug for you, I'm pretty sure the fix is easy, and I can probably help you out there if you need it.

    lastly, I named it limited prismatic joint because it goes hand in hand with the limited revolute joint. If there was no limit it could move along the chosen axis indefinitely. The limits simply specify how far it can go in a particular direction before stopping.

    Hopefully this runs for you! Let me know if you get it working!

    Cheers

    -Ruskul

  • - Thanks for the reply, it was a good reminder. I took a moment to look into box2d and I think contruct 2 overwrote my physics behavior at some point in its update. I had it saved as vanilla physics, which probably wasn't very smart. This is no problem though, even if I can't recover the file in dropbox or something I can refigure it out. It just take a bit longer than it should of. I'll be back shortly with an update.

  • - Sorry for the slow response, Ive been at my grandparents house for the last week and now I am catching up with work. When I get a chance I'll dig into that. I ended up abandoning the project in favor of writing my own physics system. If you don't hear back from me in a day or two, give me a shout. I don't mean to, but I'll probably get sidetracked and forget without a reminder at some point. If I recall though, the prismatic joint code was pretty easy (I think). If I can't get the code tonight, I probably can't tomorrow, so it may be this weekend before I can get back to you!

    Cheers,

  • Ruskul I do believe you can split global variables as if they were contained within objects. I can't remember how though.

    Really? I must look for this then. It was one of my biggest quams with using them.

  • Colludium nice, nice, Good to hear.

  • Ashley - that makes sense, but again optimizing the source often destroys that continuity. And yes, obviously it isn't a bug if that is how it was meant to work - I agree with though, I like many I think, thought it was a copy feature -

    On a side note, the separate feature I describe would provide the same benefit it does in its current format but would be a much more useful and robust feature.

    I think plenty others on the forum thought it was a copy paste toll from the work area, not the source. But since we are on the topic.... is this feature planned? Also, how about clearing a tilemap?