R0J0hound's Forum Posts

  • You could look in the "exporters" folder to look at the source code of the pin behavior. If you want to do it in Construct Classic I think in the examples section there is an example of arrows sticking into an object, which does basically the same thing as the pin behavior.

    Off the top of my head you could do pin like this:

    1 Create two sprites, childSprite and parentSprite.

    2 Give childSprite four instance variables: parent,dist,ang,relAng.

    Parent will store the uid of the parentSprite to be pinned to, use -1 for none.

    Dist and ang are the distance and angle to position from the parent.

    RelAng is the relative angle between the parent and child.

    3 Here's an example of an event to setup a pin.

    On ChildSprite collides with parentSprite

    • --childSprite: set parent to parentSprite.uid
    • --childSprite: set dist to distance(parentSprite.x,parentSprite.y,self.x,self.y)
    • --childSprite: set ang to angle(parentSprite.x,parentSprite.y,self.x,self.y)
    • --childSprite: set relAng to self.angle-parentSprite.angle

    4 Then position the pinned objects with:

    For each childSprite

    Pick parentSprite by uid childSprite.parent

    ---childSprite: set position to parentSprite

    ---childSprite: move self.dist pixels at angle self.ang

    ---childSprite: set angle to parentSprite.angle+self.relAng

    Edit

    The collision response will be interesting, you have choice of either doing the motion yourself or seeing if you can bend the physics behavior to your own devices. Either way you'll want the center of mass. Instead of just finding an average of the positions you need to incorporate mass which is simple enough.

    COMx =(mass1*x1+mass2*x2...)/(count*total_mass)

    COMy =(mass1*y1+mass2*y2...)/(count*total_mass)

    And then you can calculate the force and torque to apply to it with roughly this:

    Linear force =applied force magnitude* dist from com to applied force loc * cos(angle of applied force- angle from applied force to com)

    Angular torque is the same as above except use sin instead of cos.

  • Outside of an effect the paster plugin has a draw quad action that could be used to do a skew of an image. You just need to calculate the positions of each corner. I think there is a capx on the paster topic demonstrating the action.

  • The math as newt wrote works. As you wrote it is incorrect, you added some parenthesis that weren't there.

    Edit:

    Well, since I posted you edited your post or some nonsense like that. So now the formula is correct and the numbers look to be in the range you'd expect. If you want to be more sure of the formula then I recommend reading up on converting polar coordinates to Cartesian coordinates.

  • As a start you could download the canvas plugin. With it you can draw shapes and such. It's topic has some examples that help show it's use. The only documentation it has can be seen when adding events in the event editor.

  • What newt said, I always forget something if I don't actually implement it.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Looking in C2's exporters directory I found that yes, javascript's Math.random() is used for random. But the algorithm used is left up to the browser's javascript engine as per the Javascript spec. However generally from what I found they all use Linear congruential generators. But I didn't bother to look further to see if anything has changed with newer browsers.

  • Basically this:

    newX = oldX + 10*cos(angle)

    newY = oldY + 10*sin(angle)

    But depending on the programming language you may need to convert the angle from degrees to radians.

  • Another idea is to try removing the else condition. As I recall the else will only be run if nothing was picked in the event above.

  • RenatoB

    It doesn't work 100% because the newly created object can't be picked in the function.

    The solution is to either add a wait 0 before calling zorder or just run it every tick.

  • hopr37

    Other than changing the sprite sizes from 133 you'll also need to change all the 133's to the new size. That and reposition the sprites in the editor to be positioned on a grid size of the same value.

  • You can create a var in JavaScript with for example execute js( 'this.premium=1337‘ ) and just set your global with an event with eval js( 'this.premium'). That will work with minifying as well. As a rule of thumb it's not reliable to access the runtime stuff unless you use the sdk with a plugin.

  • Instead of using the warp behavior do an event like this:

    Bkgd_road: Y>480

    --- Bkgd_road: move 480*2 pixels at angle 270

  • You need to add quotes in the expression around the encoded string, otherwise js thinks it's just a long variable name.

    Try this. Notice the added single quotes.

    Browser.ExecJS("window.var ='" & AJAX.LastData & "';")