Yann's Forum Posts

  • you can always keep a global variable with the name or number of your top layer and use it instead of hard coding.

    I guess that if you're asking that, you might have many object that needs to switch to this layer and don't want to change the events every time you change your layer structure.

    That's the only issue I see about not having a system variable or way to find it out.

    So yeah, I would use a global variable.

  • I don't really understand what it's all about in your capx. But in short you want to make a kind of healthbar on a weird shape withough having to draw all the animation frame.

    I did something similair a while ago. I think if you understand this capx you might be able to adapt it to what you want to do:

    heartHUD.capx

    I just made this version to show how to use a texture as hp "blood"

    heartHUD2.capx

  • you can't force a game to be fast unfortunately (:

    using dt just unsure that if you want an object to move 100px per seconds, it moves exactly at this speed.

    If your fps is at 60, the sprite will move 100px/60 = 1.67 px per tick

    If your fps is at 30, the sprite will move 100px/30 = 3.33 px per tick

    If your fps is at 2, the sprite will move 100px/2 = 50 px per tick

    So the higher the fps, the smoother the movement.

  • Jayjay

    It works only for horizontal movements and also you should multiply by dt to make it framerate independant.

    using the same method for any movement would be

    Sprite: Set X to self.X+cos(angle(self.X,self.Y,B.X,B.Y)*SPEED

    Sprite: Set X to self.X+sin(angle(self.X,self.Y,B.X,B.Y)*SPEED

    and if you want to be framerate independant it will look like

    sprite: Set X to self.X+cos(angle(self.X,self.Y,B.X,B.Y)*SPEED*dt

    Sprite: Set X to self.X+sin(angle(self.X,self.Y,B.X,B.Y)*SPEED*dt

    In fact, it's exactly what "moving at angle" does

    But it might lead to wiggling when the sprite reach the B point. Because you might not end up with B.X,B.Y precisely.

    That's why using lerp is probably better (: you get the framerate independancy and precision.

  • Global number speed=10   //px per second
    Mouse: On left Click
      -> Sprite: set xA to Sprite.X
      -> Sprite: set yA to Sprite.Y
      -> Sprite: set xB to Mouse.X
      -> Sprite: set yB to Mouse.Y
      -> Sprite: set t to 0
      -> Sprite: set moving to true
    Sprite: is moving
      -> Sprite: set t to clamp(self.t+dt*speed*1/distance(self.xA,self.yA,self.xB,self.yB),0,1)
      -> Sprite: set X to lerp(self.xA,self.xB,self.t)
      -> Sprite: set Y to lerp(self.yA,self.yB,self.t)
    Sprite: t = 1
      -> Sprite: set is moving to false

    if you want a constant movement

  • Array are 0-based so the for loop should spanned from 0 to width-1 and height-1

    Also it would help to know why you want to use these number and also yeah the | operator is a OR used with a boolean type of variable.

    Any number except 0 returns TRUE when they are read as boolean.

    0 returns FALSE.

    So when you write

    0|4|9|12

    it's as if you were writing

    FALSE or TRUE or TRUE or TRUE

    which returns TRUE and TRUE into an integer is 1.

    But even if I were to read your code thinking as "this value equal 0 or 4 or 9 or 12" I really don't understand the meaning behind it.

    And last, your text wasn't used the right way to display your array values. Each time you were picking all your text objects. And the even wasn't at the proper nesting level.

    Check that out (I made some uneeded changes like using local variable x and y as loopindex 'cause I like shortcuts )

    arrayRandom.capx

  • In a turned base, you have to isolate phases.

    You could isolate these phases into different groups to switch on and off.

    Or use a variable "phase" like that:

    Global number phase = 0
    +System: phase = 0
      [insert the first phase code]
      +on phase validated
        -> System: set phase to 1
    +System: phase = 1
      [insert the second phase code]
      +on phase validated
        -> System: set phase to 2
    +System: phase = 2
      [insert the third phase code]
      +on phase validated
        -> System: set phase to 0
  • +System: Every 7 seconds
    Local number rndCount = 0
      -> Object: destroy
      -> System: rndCount = floor(random(5))+1
      +System: repeat rndCount times
        +Spawnpoint: [invert] is occupied
        +System: pick random Spawnpoint instance
          -> Spawnpoint: Spawn object on layer 3
          -> Spawnpoint: set occupied to True
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • + System: isMoving = 0
      + Mouse: on Left Click on SpriteA
        -> System: set isMoving to 1
        -> Ajax: request [spritA call] tag:"myCall"
      + Mouse: on Left Click on SpriteB
        -> System set isMoving to 1
        -> Ajax: request [spritB call] tag:"myCall"
    + System: isMoving = 1
      -> SpriteC: move
    + Ajax: on completed "myCall"
      -> System: set isMoving to 0
    // And to not get stuck
    + Ajax: on error "myCall"
      -> System: set isMoving to 0
  • System:Every 5 seconds
    System:Pick random Spawn instance
    [ul]
    	[li]> Create Object Enemy on layer 0 at (Spawn.X , Spawn.Y)
  • Zetar read my previous post

  • Noga I actually provided a capx some months later in this topic http://www.scirra.com/forum/grid-movement-with-gravity-changing_topic48129.html

    But I think how the movement was designed isn't really usefull in a game

  • yeah I was too tired I guess

    You can notice that I didn't even use the "choice" variable I built

    And I also made a mistake building this variable

    Global number Last_Left_Angle=-1 // no discarding at start
    +TrenchTile: Wall = "Left"
    +TrenchTile: Pick nearest to (0,0)
    +TrenchTile: Y > 60
      Local choice = ""  // to store the possible angles 0,1,2,3 * 90
      +System: repeat 4 times
      +System: loopindex is not equal to Last_Left_Angle
        -> System: set choice to (choice = "") ? loopindex : choice&","&loopindex
      -> System: Create object TrenchTile on layer "Tiles Front" at (Left_Wall+Wall_Move, TrenchTile.Y-TrenchTile.Height)
      -> System: set Last_Left_Angle to int(tokenat(choice,floor(random(tokenCount(choice,","))),","))
      -> TrenchTile: set angle to Last_Left_Angle*90[/code:1bw4a28f]
    
    with an example
    [url=https://app.box.com/s/5jdruw05v9s4z5od8sik]randomWithExclusion.capx[/url]
  • Create a detector sprite, make it follow the player sprite but make it so it sticks out of the feet. Then you can check for platform overlap to know on which platform you're on.

    For the every x seconds

    Global number disable = 0
    +System: Every x seconds
    +System: disable = 0
      -> do stuff
    

    If you want to disable the event, set disable to 1