AllanR's Recent Forum Activity

  • My son has been making games with enemies, and wanted a health bar over each one. So, when he places each enemy on the layout, he puts a health bar near it. Then at the start of the layout he loops through each enemy, picks the nearest health bar, and pins it to the enemy. And puts the health bar UID in an instance variable in the enemy, so when the enemy takes damage he knows which health bar to reduce.

    That is another way to handle this type of problem...

  • Picking by Unique ID is the way I would do it in this case.

    I Added an instance variable to Particles called Victim, and when the Particles object is created I store the Sprite.UID in the Victim variable so we now know the Sprite that the Particle object is associated with.

    Then I added a loop in the Every Tick section, for each Particles, we pick the Sprite with UID = Particles.Victim, then set the Particles position to that Sprite's position.

    I also randomly create new Sprite objects to shoot... :)

    Oh, I also added Fade to Sprite and Particles, so that they fade out of existence - because the bodies were really starting to pile up, and the Particle instances were still active even after the rate was reduced to nothing.

    you can get the file here: rieperts.com/games/forum/sniper.capx

  • in the Start of Layout section, right now you have

    TimeBar set InitialWidth to TimeBar.Width

    what that does is tell C2 to remember the current width.

    You want to tell it to reset the width to full and reset the time to max.

    so, you want:

    TimeBar set InitialWidth to 352   (or whatever you want for full)

    TimeBar set Time to TimeBar.MaxTime

    Then, when the layout restarts it goes back to a full time bar.

  • TokenAt() is a good way to do that. Then C2 manual say:

    tokenat(src, index, separator)

    Return the Nth token from src, splitting the string by separator. For example, tokenat("apples|oranges|bananas", 1, "|") returns oranges.

    tokencount(src, separator)

    Count how many tokens occur in src using separator. For example, tokencount("apples|oranges|bananas", "|") returns 3.

    So, rather than "(av:james) Hi my name is james" you might just want to have "james|Hi my name is james"

    then tokenat("james|Hi my name is james",0,"|") will return the avatar, and tokenat("james|Hi my name is james",1,"|") will return the text for him to say.

    You can chain together strings, using different tokens if you want.

    "james|Hi my name is james#susan|Hello there!#ben|Good day, eh?"

    just be sure to use tokens that wont appear in your text, or if you are going to pass the strings to php (to save in a database) don't use a symbol that may cause trouble there (like "&")

  • TiAm's suggestion is good.

    Another way would be to have the Scroll To behavior for ObjectA enabled, and disabled for ObjectC.

    When the collision happens, disable it for ObjectA and enable it for ObjectC.

  • The distance() function wont distinguish between different x and y target values, so don't check that way.

    instead, directly compare the x values and the y values. Since the enemies can be on either side and above or below, you could end up with either positive or negative values. so, use the ABS() function (which returns the absolute value, always positive).

    So, where you have the first sub event where you check Distance, replace that with:

    System: Compare two values: ABS(BoxWalker.X - BoxPsi.X) <= 200

    then add another condition:

    System: Compare two values: ABS(BoxWalker.Y - BoxPsi.Y) <= 50

    and, as TiAm said, then later use ELSE where you have the second Distance() function.

  • TiAm is correct.

    so, the way to fix it is to have a main event:

    Keyboard on V pressed

    then a sub event:

    System zoom = 0 - set layout scale to 2 and set zoom = 1 (the way you have it above)

    then another sub event that says:

    ELSE - set layout scale to 1 and set zoom = 0

    (the else section wont run if the first sub event is true, when zoom=0, even though the value of zoom gets set to 1)

  • well, it is impossible to tell without seeing your actual code... it could be just about anything.

    you may have placed the code somewhere that never actually runs.

    Random(15) will return a floating point number between 0 and 14.9999, so the chances of getting an integer are almost zero. If the rest of your code is expecting an integer then use something like Round(Random(15))

    or Int(Random(15))+1 if you don't want it to ever pick zero.

  • Well, I just played around with your capx too.

    The problem is that you are converting the coordinates of the Coin being collected to the actual canvas coordinates, but then you are not converting the canvas coordinates to the HUD layer's coordinates. So, when the game screen does not fully fill the monitor it is off.

    I created two local variables for that section: canvasX and canvasY

    and set them too:

    canvasX = LayerToCanvasX("Main",Coin.X,Coin.Y)

    canvasY = LayerToCanvasY("Main",Coin.X,Coin.Y)

    then created the Coins object at:

    Create object Coins on layer "HUD" at ( CanvasToLayerX("HUD",CanvasX,CanvasY), CanvasToLayerY("HUD",CanvasX,CanvasY) )

    That seemed to work fine. (I slowed the speed of the Coins way down because they were moving almost too fast to see!)

    I still think simple is better. Your capx sure has a lot of global variables and a lot of code. I would try to simplify it by using more instance variables, arrays, functions, etc...

    But, the game looks good! You are well on your way to making some great games! :)

    I can't really tell why the FPS would decrease. It does seem to work fine in the version you uploaded. Like zenox98 said, try using the debugger to see what is hogging all the processing time - you probably have more objects than you think, or something isn't getting reset...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • zenox98 was trying to tell you to keep it as simple as possible - make an image point in your player sprite and spawn the coin on that imagepoint. That way it can't miss.

    The canvasToLayer function will give you different results on different screen sizes and orientations, and only makes it more difficult to get the effect you want. Whenever possible, use the simplest method and let the power of C2 do the work.

  • TestaDiDrago

    You can turn Gravity on and off, it is in the "Physics Global settings" for an object (but applies to all objects that use physics).

    So, at start of layout, choose an object that has physics, and set world gravity to off.

  • You can add the Persist Behavior to objects to have then remember where they were (they don't get destroyed when the layout ends and then recreated when you go back to the layout).

AllanR's avatar

AllanR

Member since 21 Nov, 2013

Twitter
AllanR has 23 followers

Trophy Case

  • 10-Year Club
  • Forum Contributor Made 100 posts in the forums
  • Forum Patron Made 500 posts in the forums
  • Forum Hero Made 1,000 posts in the forums
  • Popular Game One of your games has over 1,000 players
  • x2
    Coach One of your tutorials has over 1,000 readers
  • Regular Visitor Visited Construct.net 7 days in a row
  • Steady Visitor Visited Construct.net 30 days in a row
  • RTFM Read the fabulous manual
  • Email Verified

Progress

19/44
How to earn trophies