Yann's Recent Forum Activity

  • rexrainbow

    I have no idea, I don't have anything to test that, if you have time to try I'd be intersted to know the answer (although I don't know if I would be able to do anything about it if it doesn't work)

    What I can tell you is that it runs with webgl on and off (:

  • I just tested with physics, and although I get a scary error message on preview, it seems to work super fine (some one said Crayon Physics Deluxe?)

    https://dl.dropbox.com/u/23551572/C2-Games/Physics%20Test/index.html

    Maybe Ashley can shed some lights on it:

    is it a bad idea to used physics with my plugin? or can the error message be disabled somehow?

  • Hi! guys

    Last-Edit 2013-04-23:

    bug fix: ctx.drawImage() didn't like textures of size (0,0)

    Edit 2013-03-03:

    bug fix: wrong bounding box expressions.

    I made a plugin to draw polygons (:

    Properties:

    • Collision: Enabled|Disabled
    • Debug Mode: Enabled|Disabled

    Condition:

    • Is overlapping another object

    Same as Sprite is overlapping

    • Is overlapping at offset

    Same as Sprite is overlapping at offset

    • Collisions enabled

    Same as Sprite collision enabled (return true if collision is enabled)

    • On Drawn

    Trigger when the Draw action is executed

    • Compare area

    Compare the area of the drawn polygon

    Actions

    • Add Vertex(x,y,local or world-space)

    add a vertex to the vertex list

    • Remove Vertex(index)

    remove a vertex from the vertex list

    • Insert Vertex(index,x,y,local or world-space)

    insert a vertex in the vertex list

    • Move Vertex(index,x,y,local or world-space)

    move a vertex of the vertex list

    • SetOrigin(x,y,local or world-space)

    change the origin of the polygon

    • Log Vertex List

    print vertex list in the console log

    • Draw Polygon(fillColor,lineWidth,lineColor)

    draw the polygon using the vertex list, filling the shape with fillColor and stroking the outline with a line of thickness lineWidth and color lineColor

    • Clear Polygon

    clear the vertex list and erase the polygon

    • Load(JSON)

    load a vertex list in JSON format

    • Download

    open a window with a download link of a JSON file containing the a vertex list

    Expression

    • Area: area in px of the shape. gives a wrong results for invalid polygons (when edges cross each other)
    • asJSON: return the vertex list as a JSON string (to use in the load action)
    • OriginalWidth: width of the original polygon texture
    • OriginalHeight: height of the original polygon texture
    • LocalVertexX(index): the original values entered in Add Vertex (local-space)
    • LocalVertexY(index): the original values entered in Add Vertex (local-space)
    • VertexX(index): X position of the vertex (by index) in world space
    • VertexY(index): Y position of the vertex (by index) in world space
    • VertexCount: total number of vertices in the vertex list (usefull to loop through them)
    • Left: X position of left of unrotated bounding box
    • Right: X position of right of unrotated bounding box
    • Top: Y position of top of unrotated bounding box
    • Bottom: Y position of bottom of unrotated bounding box
    • CenterX: X position of center of unrotated bounding box
    • CenterY: Y position of center of unrotated bounding box
    • BarycenterX: X position of barycenter (average of vertices position)
    • BarycenterY: Y position of barycenter (average of vertices position)

    How does it work?

    A polygon is defined by an ordered list of vertices.

    To create this list you use the action Add Vertex.

    The order in which you add vertices is important. The plugin will draw the polygon starting from the first vertex you added until the last one and close the shape back to the first.

    Another thing to keep in mind, when you Add vertices, you add them relatively to the position/orientation/scale of the object (local space) or directly in the world position (world-space)

    So if you want to make a square around the origin of the object you will have something like that:

    global number sideLength = 100
    Polygon: Add vertex -sideLength/2, -sideLength/2 (local-space)
    Polygon: Add vertex sideLength/2, -sideLength/2 (local-space)
    Polygon: Add vertex sideLength/2, sideLength/2 (local-space)
    Polygon: Add vertex -sideLength/2, sideLength/2 (local-space)

    But if you do only that, nothing will happen. Once you've built your vertex list, you have to tell C2 to draw the polygon (it's not done after each Add for obvious reasons (:)

    To draw the polygon, it looks like that:

    Polygon: draw with outline (1.0 px, "rgb(255,0,0)") and fill with ("hsl(180,50%,50%)")

    (you have to specify color with a string (in "") and you can use either rgb(r,g,b), hsl(hue,saturation,lightness) or "#rrggbb" or special recognized values like "black" "red" "green" etc)

    You can move, or remove vertices via their indexes (0-based)

    If the index you specify is negative or greater than the index of the current last vertex, it won't do anything and will write a warning message in the javascript consol (only in debug mode and preview).

    You can insert a vertex inside the list by giving an index.

    If the index you specify is negative or greater than the index of the current last vertex, it will be respectively clamped to 0 or [index of the last vertex] + 1

    Clear polygon will do two things at the same time:

    empty the vertex list and delete the current polygon texture.

    JSON support

    I basically copied the piece of code from the Array plugin. So you can load and save a vertex list in JSON format.

    It can be usefull if you want to copy a polygon shape or save some shape for later uses (polygon editor?)

    Scaling

    When you use the draw polygon action, you basically create a texture. This texture can then be scaled using width/height, and rotated using angle.

    But remember that since it became a texture, you will see stretching artefacts.

    Another thing to be aware of, if you stretch your polygon, you basically modify the relation between originalWidth (which is the distance between the left most and the right most vertex in local space) and current Width of the object.

    The draw polygon action will keep this relation.

    If your width is twice your originalWidth, and you modify your vertex list and draw, the ratio will be kept.

    Local-Space vs World-Space

    Add, Insersion and move can be either done in local space or world space.

    Local-space means relative to the space of the polygon object. So if you add vertices and then change the angle of the object, you'll have the same result the other way around.

    Via expression, you have access to the local coordinate (LocalVertexX,LocalVertexY) or the world-space coordinate, their real position in the world (VertexX,VertexY)

    Area

    The value you get from the Area expression or evaluated with the Compare area condition will be right for convex and concave polygon but wrong for invalid polygons (when two edge cross each other).

    Origin

    You can set the Origin of the polygon wherever you want to, even after your vertex list is built.

    The vertex list will be recalculated accordingly, and the position will be changed so the origin is moved but nothing is changed visually.

    It may be usefull to set a new rotating point or anything you want to do in runtime.

    You can test it in the demo.capx in the zip or Creation/Edition demo below.

    Debug

    To help you during development, you can enable the debug mode property.

    When this property is enabled, and ONLY in preview (this way if you forget to disable it for export it won't be a problem) each action will throw a message in the javascript consol.

    This way you can see what vertex are added, inserted or removed, when polygon are drawn and when JSON's are loaded

    But sometimes you don't need that much, or you would prefer triggering debug information yourself via event.

    For that, you have the log vertex list action. It will write the list of vertices in the console (only in preview)

    Demo

    You can test everything about scaling, rotating, vertex creation here:

    Creation/Edition

    Just to fool around

    Creating random graphs

    One possible application of it:

    Split poly

    <show off>

    One crazy really unusable and "you shouldn't do that" application:

    3D rendering

    </show off>

    Download

    Here is the plugin with the capx of the demo in it.

    (I didn't provide the 3D one because I don't want to encourage anyone to use that method (:)

    polygon.zip

    I made some video to show you how I to use it

    Polygon Plugin:RamblingActionsExpressionsPolygon Splitting:Starting ShapeCutting NodesNode SelectionSplit FunctionLine EquationGroupingChildren CreationPolygon SelectionHelper FunctionsFeedbacksNode FilteringLittle BugFinal Rambling

    Do remember that drawing a polygon is an expensive computation, avoid as much as possible to do that every tick.

    I hope you like it and don't hesitate to report bug and tell me how you used it (:Yann2013-04-23 00:21:22

  • for 4. you could use your own stack

    create an array, name it stack, give it the size 0,1,1

    save your function parameter by doing stack.push(back, value, on X-axis)

    after your wait action you do a

       set object.angle to stack.front

       stack: pop front value.

  • Joannesalfa

    The drawing part ressemble the draw line and fill action. But it's simplified since you don't have to do the beginPath, moveTo and lineTo, endPath, fillPath, strokePath etc

    you just have to do a serie of Add Vertex action followed by a draw Polygon action where you specify the fill color and line width/color.

    Everything else is handled under the hood.

    And since you give the vertices in local space, you can more or less dynamically position the origin. And also the collision polygon is automatically created to fit your polygon.

    So yes... ressemble canvas plugin but way more specialized toward polygons.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ashley

    Alright (: since there are workarounds, I think it's not that big of a deal.

    Thanks for the explanation.

  • Other than using a plugin, you could simply build a list in an array

    on start of layout
       local text letters = "abcdefghijklmnopqresuvwxyz"
       set codeToChar size to (256,1,1)
       repeat 26 times:
          //letters
          set codeToChar.At(65+loopindex) = tokenat(upperCase,loopindex,"")
       repeat 10 times:
          //numbers
          set codeToChar.At(48+loopindex) = loopindex
          //numpad
          set codeToChar.At(96+loopindex) = "numpad "&loopindex

          //F1 to F12

       repeat 12 times:

          set codeToChar.At(112+loopindex) = "F"&(loopindex+1)

    so you can do

    codeToChar.At(keyboard.LastKeyCode)

    to get the key

    You'll have to fill the other possible key more... manually though (:

  • I adapted the algorithm Ashley came up with here for C2

    I also modified the comments for the smart aiming formula to make the explanations slightly easier to understand (although it's still complex math)

    aiming.capx

    Ah it ends up behing exactly equivalent to what squid came up with.

    since

    asin(targetSpeed * sin(angle(target,turret) - targetMovingAngle)

    = asin (((targetX-turretX)*targetVectorY - (targetY-turretY)*targetVectorX)/distance(target,turret))Yann2013-01-15 14:48:05

  • I'm currently working on a Polygon plugin. You basically feed it some vertices (in the proper order) in local space and then draw.

    It also handles collisions.

    What I have done so far:

    Condition:              ?

    • Is overlapping another object
    • Is overlapping at offset
    • Collisions enabled
    • On Drawn
    • Compare area

    Actions

    • Add Vertex (x,y) \\ in local space
    • Log Vertex List \\ outputs the vertex list in the js consol
    • Draw Polygon (fillColor,lineWidth,lineColor) \\ every change in vertex list needs a draw call to be seen
    • Move Vertex (index,x,y)
    • Remove Vertex (index)
    • Clear Polygon \\ empty the vertex list and erase the poly)
    • Load (JSON)
    • Download (JSON)

    Expression

    • VertexX(index) (in world space)
    • VertexY(index) (in world space)
    • VertexCount
    • Area
    • LocalVertexX(index) (the original values entered in Add Vertex)
    • LocalVertexY(index) (the original values entered in Add Vertex)
    • asJSON

    Basically everything in this list is done and I'm already using it for a project so I can thorouoghly test it.

    Also it might not be super easy to work with since I'm mixing local and world space. But that's what I found the most practical.

    You create vertices relative to the position of the object so you can feed the same vertex list to other instances an have the same shape drawn.

    And you retrive the vertex position in world space so you can "pin" some objects to them or do some calculations.

    You can copy polygons using either the LocalVertex expressions or Get as JSON -> Load

    I don't support textured polygon for now at least... If it's not too hard to implement and if it doesn't make the plugin too complex I might.

    I think I'll be releasing it this month so we'll be able to talk about it in its own topic =)

  • Hi! It's me again torturing this poor function object

    I just discovered that functions seem to destroy their parameters (local variables and function arguments) before any action after a wait triggers. So basically

    on Function "test"
       -> wait 0.01
       -> Text: set text to Function.param(0)[/code:1y45gh1g]will always print 0
    
    one work around for now is to do:[code:1y45gh1g]on Function "test"
       + local static text persist = ""
       -> set persist to Function.param(0)
       -> wait 0.01
       -> Text: set text to persist[/code:1y45gh1g]
    
    little capx just in case
    [url=https://app.box.com/s/jzhqvlifaxdv5xyd0vma]functionsDontWait.capx[/url]
  • rexrainbow

    Bitwise operations affect the bits themselves

    NOT(0000) = 1111

    but in signed int it's interpreted as -1

    and in unsigned int it's interpreted as 15

  • rexrainbow

    Hey didn't know you could do that (:

    Ok I'll implement your multiple idea in the coming days =)

    As far as NOT(0) being -1

    I think, since my plugin handle signed integers, it would be weird to make an exception with 0.

    And it might go against some common bitwise operation.

    I would prefer making signed and unsigned functions, like uNOT(0)/sNOT(0).

    In short, I don't like when weird operations are hidden from the user. For the sake of an apparent "better" result.

Yann's avatar

Yann

Member since 31 Dec, 2010

Twitter
Yann has 5 followers

Connect with Yann