R0J0hound's Forum Posts

  • The customMovement behavior doesn't really add much to be helpful for that. maybe the "stepping mode" where you can check for collisions in the in between positions with the "on step" trigger.

    Pushing out once colliding isn't the best here. It would be better check if the way is clear before moving.

    And actually I would go for doing the whole thing with events.

    I'd put everything I wanted to collide with in a family and call that solid then the simplest example would be this:

    [negated] sprite: overlaps solid at offset (1,0)

    sprite: set x to self.x+1

    You could then extend it with a speed instance variable to make the acceleration and finer motion:

    [negated] sprite: overlaps solid at offset (self.speed*dt,0)

    sprite: set x to self.x+self.speed*dt

    sprite: add 1500*dt to speed

    else

    sprite: set speed to 0

    When hitting a solid it will look to stop short sometimes and close the gap. This can be improved by using a loop to check each step in between. for that add another instance variable called "delta". Another benefit is this keeps the objects on pixel coordinates while staying framerate independent. This adds consistency to the collisions so they always stop the same distance away.

    every tick

    sprite: add 1500*dt to speed

    sprite: add self.speed*dt to delta

    repeat sprite.delta times

    ---[negated] sprite: overlaps solid at offset (1,0)

    --- > sprite: set x to self.x+1

    --- > sprite: subtract 1 from delta

    ---else

    --- > stop loop

    --- > sprite: set delta to 0

    --- > sprite: set speed to 0

    Now you could instead use the custom movement behavior instead by setting the stepping mode property and using the on step trigger. The only issue is "on step" is triggered after the object moves so you'll have to back it up or push out. That can go wrong if it pushes out into another object, which can easily happen with objects with floating point coordinates while being close to each other.

    EDIT:

    Here's an example:

    https://dl.dropboxusercontent.com/u/542 ... _move.capx

    The events are generic for any angle and I shrank the collision polygon a bit.

    One more thing that could be done with this is simultaneous movement of the blocks. Right now their motion is handled on by one, but you also could let each move a pixel, then repeat for all of their deltas are below 1.

    https://dl.dropboxusercontent.com/u/542 ... neous.capx

    Further tweaks would probably be some rounding in some spots to keep things with integer values, but I'm not sure if it's needed.

    EDIT2:

    had a typo in limiting the speed. used max when it should have been min.

  • It shouldn't swing if everything is centered around the fixed joint.

    Here's an example of one way to do it:

    https://dl.dropboxusercontent.com/u/542 ... _lamp.capx

  • There will be no transparency issues, but zorder can be a bit tricky.

    If everything you want to paste is only one object type you can do this:

    for each sprite ordered by sprite.zindex ascending

    paste sprite

    For multiple different object pasted in the correct order here's a capx with a function that can do it.

    https://www.dropbox.com/s/3teztza6jcood ... .capx?dl=1

    /examples30/paster_pasteLayer_solution.capx

    You'll have two duplicate a few events in it for every object type you want to be able to paste, but hopefully it's straightforward to see which ones.

    Basically what it does is find the highest zindex out of all the objects on a layer, then loops over the zindexes and pastes the object with that zindex.

    EDIT:

    And just to be clear this doesn't consider the transparency of the layer.

  • You need to disable the collisions between the objects I think. The simplest way to do that is to make there collision group 1.

  • Yeah, I meant the one you can set from the property on the left.

    Here's a dual example for canvas and paster:

    /examples30/mirror_paster_canvas.capx

    https://www.dropbox.com/s/e19zxibiaehbb ... .capx?dl=1

    Paster doesn't have a paste layer action currently because making it work with C2's webgl is a mess right now. I can't really tweak it to work without major changes.

    Even if you have to loop over the instances and paste them individually you'll still get better performance with paster. With webgl on the canvas object has to copy itself to a webgl texture every frame it changes. That is the main performance hit you were getting from the first example. Using one canvas should help, but it's still inefficient.

  • Sure it is, just not in the editor from what I can tell. You can take a texture and draw one part of it to one quad and another part of it to another. 9patch is a good example of that. You can do that in the editor and at runtime.

    The only limit is you can't set the blend mode with js in the editor. At runtime you can do that no problem, just set the blend mode before each quad drawn.

  • You can use just one canvas object, or even better a paster object. The paster object is about the same as canvas, but is much faster with webgl on.

    Basically to do the reflection you set the origin of the object to be at the top, and position it where you want it in the editor.

    Then with events you'd do this every tick:

    1. clear the texture

    2. set the height to -self.height to flip it

    3. paste anything you want to reflect

    4. set the height to -self.height to flip it back

    The gradient could be done with another object on top, and the wave effect is simple with one of C2's shaders.

  • For something like a gui it's pretty common to have all the peices of the graphics in one texture.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • One way would be to use an imagepoint, and use Sprite.imagepointx(1) instead of Sprite.x. The same for y.

  • An object can either have one image like tiledbg or animations like Sprite defined with the pf_texture or pf_animations flags. Not sure if you can have it load more than one texture by default though.

    As far as drawing goes you can draw the two textures any way you'd like at runtime. The edittime is more limited though. You'll have to look at the Sprite plugin to see how different animation frames are used for drawing in the editor. Also it doesn't look like you can control the blend modes for the editor from the sdk, but maybe I haven't looked well enough.

  • I can have another go at it on another PC if I get a chance, but it's not simple to add. Previous attempts were requiring too much code to tweak.

    Overall C2's webgl renderer is made to work well with the screen and not arbitrary rectangles like this plugin does. Ideally I'd just call some functions from the renderer but as it turns out instead I needed to copy and heavily modify most of those functions. Pasting objects with effects is one such example and there are differences with my code that can make the pasted image not look the same. There's probably a simpler solution I haven't come up with yet but it'll probably be very hacky.

    That is probably one good reason why such a plugin like this would have benifited from being made officially. They could then be able to tweak their renderer to make such a plugin more streamlined.

  • You can do what you want with a instance variable "parent" that you'd set the the parent's uid.

    The tediousness would be the picking other instances of the same type. The two way is either a family or storing values from another instance to variables. Functions would also be useful here to make the events more readable.

    For example if your object types look like this:

    sprite: ogre

    family: otherOgre

    variable: parent=-1

    Then your events could look like this:

    // this creates the hierarchy
    //  Ogre spawn 5 ogres, those ogres spawn 2 ogres
    
    Start of layout
    repeat 5 times
    for each ogre
    

    ogre: spawn otherOgre

    otherOgre: set parent to ogre.uid

    ---repeat 2 times

    ---> otherOgre: spawn ogre

    ---> ogre: set parent to otherOgre.uid

    on function "getParent"

    function: set return value to -2

    ---pick ogre by uid function.param(0)

    ---> function: set return value to ogre.parent

    global number dist=0

    global number ang=0

    global number X=100

    // ogre is the grandson, otherOgre here is the grandfather

    // i don't want the grandsons to be further than X distance from his grandfather

    for each ogre

    pick otherOgre by uid function.call("getParent", ogre.parent)

    set dist to distance(otherOgre.x, otherOgre.y, ogre.x, ogre.y)

    set ang to angle(otherOgre.x, otherOgre.y, ogre.x, ogre.y)

    --- dist > X

    ---> ogre: set position to otherOgre

    ---> ogre: move X pixels at angle ang

    //the grandfathers will move to his sons

    // here otherOgre is the father, ogre is the son

    for each ogre

    pick otherOgre by uid ogre.parent

    otherOgre: move 100*dt pixels at angle angle(otherOgre.x, otherOgre.y, ogre.x, ogre.y)

    //At the same time, the 5 grandfathers are not related so they will fight each other but will not harm their own family and will not damage grandsons of anybody, but the grandsons may hurt their own brothers but not their fathers.

    // If I understand that correctly you want

    // 1. gradparents to fight with each other

    // 2. grandchildren to fight with brothers

    // ogre and otherOgre are grandparents

    ogre: parent=-1

    otherOgre: parent=-1

    for each ogre

    for each otherOgre

    fight

    // ogre is a grandchild, and otherOgre is a brother

    ogre: pick by comparison function.call("getParent", ogre.parent) = -1

    for each ogre

    otherOgre: parent = ogre.parent

    for each otherOgre

    fight[/code:143vi5gb]

  • It's actually pickable at the next toplevel event too.

  • korbaach

    The difference is how colors are matched there. It checks if the colors are close, not exact.

  • rufson

    I couldn't get the "load texture from canvas" action to work reliably when I was implementing it. The issue is it seems to rely on some undefined behavior with webgl unfortunately, so it should probably be removed from the plugin.

    On another note webgl support for my graphics card is poor so even with webgl on it's not used when I preview. Support was better with older browsers oddly enough. As a result I have done nothing with webgl for a while now, so I probably won't have a fix for this.