Yann's Forum Posts

  • That's an easy one

    Global encounterChance = 0
    Global maxChance = 10
    tallGrassColl | On collision with Player Col
       System | encounterChance < maxChance  -> add 1 to encounterChance
       System | random(maxChance) < encounterChance -> Go to Brawl

    I think it makes more sense to start from 0 to go to maxChance...

    so basically you will have encouterChance/maxChance ... Chance of encounter :D

  • There's a solution.

    Your main problem is that you put your Array in a layout that appear after the first layout that have to USE this array.

    Basically, you want to move the array to the other layout.

    1/ Save as Project in projectfolder (name it as you see fit)

    2/ Go to projectfolder/Layouts/

    3/ Open the xml file of layout where your array is

    4/ Locate it in the xml gibberish it should look like :

    <instance type="Array">
        <properties>
            <width>10</width>
            <height>10</height>
            <depth>10</depth>
        </properties>
    </instance>

    5/ cut this

    6/ Open the xml of the layout you want your array to be

    7/ locate the nonworld-instances element

    8/ if you don't have non world element in this layout it should look like

    <nonworld-instances/>

    That's the syntax for empty element

    In this case you will have to change this markeup to

    <nonworld-instances></nonworld-instances>

    To be able to put something inside.

    9/ paste inside the nonworld-instances element

    <nonworld-instances>
        <instance type="Array">
            <properties>
                <width>10</width>
                <height>10</height>
                <depth>10</depth>
            </properties>
        </instance>
    </nonworld-instances>

    10/ save and close both xml file

    11/ open the projectfoler/project.caproj

    it should work...

    in any case you take no risk as you always have your original .capx

    also if you manage to get the hang of xml syntaxe, you can easily make some "replace" operation in the event sheet xml (projectfolder/Event sheets/)

  • In physic, doing a 0->maximal speed instantly means you are applying an incredible force on the object...in an instant

    well... try that rocketScience.capx

    Just click

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Nope no debugger, some uses firebug to track them down (a firefox plugin)

    I don't really know how to use it effectively.

    So yeah it would be great to have a debugger somewhere... And I think it's somewhere in ash's awesomely big todo list (I hope)

    We probably just have to be patient (:

  • Well you made a lot of mistake

    The bigger one is that you forgot to set world gravity to 0 (easy to miss)

    Others are in how you use foreach and how you nest things

    Also you added gravity to mass at some point

    And you didn't need to use an Array object, global variables are better

    etc, etc, etc

    Just compare I hope you'll understand

    gravity.capx

  • The best method I can think of is :

    1/ make your game with simple recangle, tweak it until you get the right speed, jump, fall... all the motion should feel right and properly balanced

    2/ then, as you parallely developped a character design, you begin to flesh out simple key poses (4 key for a walk cycle, one for a jump, one for a fall pose). Just simple sketchs to test :

    - the size of your character

    - the rythm (you might change animation speed to fit the speed of your walking rectangle and avoid sliding walk)

    - the poses themselves

    - if you didn't destroy the balance achieve in step 1 (it could come from bad animation rythm or too unrealistic motion: imagine a human moving like super meat boy...)

    3/ Once you get things right, you sketch the needed in-between (if you just have 4 keyposes and you put animation speed to 6, you might need to add some in-between to smooth the animation. animation speed to 12 should be better) - of course once you sketched the in-between, you test them because after all, a sketche is mentally easier to correct than a fully rendered frame

    4/ You go wild and fully render your neat sketches OR you go 3D from there and try to fit your sketch the best as you can.

    Yeah sketching is often better than going 3D too fast. 3D is great, but there's some thing you can find quicker with a sketch than disentangle your keys and curves. Some will probably say that they suck at drawing and moving bones is easier... You know... matter of taste :D

    Oh and I tend to keep the rectangle from step 1 as a collision box, and just play anim on top of it with a every tick : sprite set position to spriteCollision (just example of naming)

  • xVector and yVector are indeed just mere private variables

    So is mass

    Basically a force is what make things accelerate or decelerate.

    If you don't apply any force to an object, it's speed will never change

    A force is generally modeled as a vector, because as a vector, a force has a direction and a quantifiable value (how much) which is represented by the length (norm/magnitude) of the vector.

    A vector in 2D has two composants often described as X and Y

    In construct (classic or 2) you can't store a vector in one variable, you need one variable by composant. It is the purpose of xVector and yVector.

    To calculate each composant of a vector oriented you have to find orientation and length.

    gravity = G*m1*m2/d? gives you the length

    the orientation is just the direction toward the considered object.

    so you just have to find the unit vector (vector whose length = 1) representing this direction and multiply it by the length calculated above ('cause 1 * gravity = gravity hoho)

    the unit vector is simply calculated by

    cos(angle)

    sin(angle)

    angle = angle(source.X,source.Y,target.X,target.Y) (neat function in construct)

    so just have to do a

    xVector = gravity * cos(angle)

    yVector = gravity * sin(angle)

    I also added many times this kind of calculation because adding vector is the same as adding its composant

  • selecting something would be possible by having a "selected" boolean private variable you set to true if the unit is selected.

    you just have to foreach the units and check for these variable set to true and apply your actions.

    To group, you could have a 2 dimensional array sized this way :

    DIM X = maximum number of groups

    DIM Y = maximum number of units per groups

    and then you select the units you want to group (that is to say, their "selected" variable get set to true)

    and when you use your shortcut to groupe them, you foreach them and store their UID in the arrayat(IDofTheGroup,loopindex)

    If you want to recall your selection, you just have to do a

    for 0 to DIM Y

        if unit.UID == arrayat(IDofTheGroup,loopindex) -> unit set selected to true

    I hope you have some knowledge of c2 else I might be a bit hard to understand... If you don't understand, you don't have enough knowledge yet to make a RTS I guess (:

  • For MoonShield I moved the moon with events and the asteroids with physics :

    basically for the moon I increase an angle private variable (I have the distance from the earth in another pv) and then I just position them with

    moon.X = earth.X + cos(moon.angle)*moon.distance
    moon.Y = earth.Y + sin(moon.angle)*moon.distance

    For the asteroids it's a bit more complicated. I calculate the gravity force of each asteroids toward each moons and the earth

    Moons, Earth and Asteroids have all a "mass" private variable (so I can tweak it)

    And I just have to :

    foreach asteroid
       /// Calculating the gravity vector toward the earth following the gravity formula G*m1*m2/d?  (G is multiplied when I apply force at the end)
       asteroid.xVector = (asteroid.mass* earth.mass/distance(asteroid.X,asteroid.Y,earth.X,earth.Y)^2)*cos(angle(asteroid.X,asteroid.Y,earth.X,earth.Y)
       asteroid.yVector = (asteroid.mass* earth.mass/distance(asteroid.X,asteroid.Y,earth.X,earth.Y)^2)*sin(angle(asteroid.X,asteroid.Y,earth.X,earth.Y)
    
       /// adding the other gravity vector
       foreach moon
          ADD (asteroid.mass* moon.mass/distance(asteroid.X,asteroid.Y,moon.X,moon.Y)^2)*cos(angle(asteroid.X,asteroid.Y,moon.X,moon.Y)
          ADD (asteroid.mass* moon.mass/distance(asteroid.X,asteroid.Y,moon.X,moon.Y)^2)*sin(angle(asteroid.X,asteroid.Y,moon.X,moon.Y)  
    
       /// Applying the result gravity vector
       Every Tick asteroid Apply physics force (Clamp(asteroid.xVector*gFactor*dt,minVect,maxVect),Clamp(Self.yVector*gFactor*dt,minVect,maxVect)) at image point 0

    And that's all, the physics behavior use the force I calculated to create the movement.

    Oh and I clamped the vector because the asteroids tended to go to fast and the gFactor is a global variable used to tweak the gravity a bit for better gameplay

  • find(varload, "|") = position of the first | in the string

    basically you get each token ( = part between separators) by incrementing an iterator

    the iterator can be a simple variable or a loopindex

    global iterator = 0
    every 5.0 seconds :
        set text to tokenat(varload,iterator,"|")
        add 1 to iterator[/code:32ezzhr4]
    
    or
    
    [code:32ezzhr4]for "itLoop" from 0 to tokencount(varload,"|")-1
        append to text : tokenat(varload,loopindex("itLoop"),"|")[/code:32ezzhr4]
  • Oh yeah you're completely right

    I just tested with your idea

    But! mine works too, I modified the acts.pasteObject function this way :

    ctx.save();
    ctx.scale(this.canvas.width/this.width, this.canvas.height/this.height);
    ctx.rotate(-this.angle);
    ctx.translate(-this.bquad.tlx, -this.bquad.tly);
    ctx.globalCompositeOperation = "destination-out";
    instances[x].draw(ctx);
    ctx.globalCompositeOperation = "source-out";
    ctx.restore();
    

    And it erase perfectly, even if it's a bit weird now that I think about it.

    But yeah I'll stick with your idea... it's simpler

  • r0j0, thanks for this great plugin, I was trying to come up with a line/box/circle plugin but the Canvas is more than enough. Great work.

    Just one feature, I'd like to have. But I wonder if it's feasible. Being able to erase part of the canvas, either by pasting a sprite or drawing something. I tried drawing lines or points with rgba(0,0,0,0) but it seems the drawing logic just add stuff.

    So yeah basically, is it possible to have an "erase part of the canvas" feature?

    Edit: after some research, maybe :

    acts.PasteErase = function(object)
    {
      // erase mode inside the canvas plugin object
      this.ctx.globalCompositeOperation = "destination-out";
    
      [acts.PastObject code]
    
      // back to normal mode
      this.ctx.globalCompositeOperation = "source-out";
    
    }

    Edit Bis:

    HOHOHO that works =D

  • Theme is funnier

    'cause you know, game is challenge and challenge induce fun

    Fixed Theme is challenge, Therefore it's funnier

    And I'm tired...

  • s there a possibility to include gifs?

    Nope!