Vallar's Forum Posts

  • You can create a variable called "objectPicker" and assign it to 0 (so it doesn't pick anything) and then when the task is done you can add an action:

    Set Value "objectPicker": int(random(1, 3))

    Then add an event below that (or perhaps a sub event, depending on your task):

    Compare Variable "objectPicker" == 1: Create object 1

    Compare Variable "objectPicker" == 2: Create obejct 2

  • I am not 100% sure of what you are after. I can only guess you want to create a physics based car game?

    If that is the case here are a few links that might help out:

    https://www.scirra.com/tutorials/323/create-car-physics

    behavior-car-physics_t69925

    physics-based-car-driving_t123462

  • Hello guys,

    I am fighting a bit with the Multiplayer plugin following a tutorial that shows you how to make a multiplayer tank game. The person starts off with getting you to make a single player game and then the multiplayer version.

    What I have so far is that the host connects, it detects it is a host and you can control it. Then the peer connects and detects it is a peer and you can control it while the host can't be moved. However, the problem is a peer can see the host but the host can't see the peer. I tried everything I can think of but it isn't working.

    Any idea what might be the problem and how to get it fixed?

    Side note: Since I am working on multiplayer and getting to learn its ins and outs, I'll probably have a few questions; should I stick to one thread (like this one?) or open new threads when the question arises -- I am afraid of being spammy.

  • I have read it a couple of times but unlike what I believe, it is sometimes not easy to get these concepts present in your mind all the time. But you are absolutely right, this is extremely important, thanks for the reminder I'll go through it again!

  • Yeah, I get what you are saying. It is completely different from Unity; there you can do an Enemy.SetActive(false); and there you go, the object is deactivated but the amount of memory allocated to it is reserved so you don't need to add extra memory leg work to delete and recreate. The object doesn't then participate in collisions or anything. You can then go Enemy.SetActive(true); to set it back on and you just saved some performance. Same with UE4 if I recall correctly (unless you manage the garbage collection manually with C++ as I heard)

    That is what I understand at least.

    But I get that Construct 2 is completely different and to be honest... this way much better. I don't have to worry about what object is on or off and where it is. I just can destroy it and forget it about it. Such a heavy load cleared off

    Thanks a lot!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You use a bit more memory then needed by having different objects and by setting them invisible instead of destroying them.

    Setting them invisible will not do the trick. They still collide/overlap. They still count in .. in the iterations and the evaluations, and therefor they also bring performance down. If you really worry about memory and performance, then you destroy them when not needed. Only destroyed sprites have no graphics in memory and are not seen by the events...

    Hmm... I can see what you mean with the invisible not doing the trick. I sometimes fail to separate the logic Unity uses to do things and Construct 2 and things get mixed up (probably because I use both interchangeably and need to focus one project at a time).

    I guess I'll use create and destroy instead. However to answer your comments:

    [quote:3ugksakn]You think to much in 'IF this THEN that'. You must learn to think in service of the PICKLIST (selected objects list)

    To choose a spawner that is not occupied by a 'sprite' you do this ..

    Yes, you are right, sorry about that >.< but good catch, that is just much easier. I didn't notice it until like 15 minutes ago when I was refactoring the code to use create/destroy instead.

    [quote:3ugksakn](I have no idea why your enemypicker goes in steps of 2)

    At this point, come to think of it, you are right. Steps of 1 gives a 1/Enemies.Count chance same as what I have right now with the steps of 2. My math failed when I tried to do this -- I was thinking of making the chance 25% for each. But I realize that isn't the way to do it AT ALL.

    [quote:3ugksakn]Spawn Sprite

    Set Sprite.type to enemypicker (a dot to say it is an instance variable)

    Set sprite's animation to str(enemypicker)

    Set some more abilitys, or have an array with the abilitys on the Y-axis, with the X-axis sync with the types.

    One event for everything.

    I wonder why you need an array with the UID's. You can build that array on any moment with a simple loop, on any moment. Without maintaining it with pushes. Why do you need that anywayz ?

    No reason to use an array aside from saving myself a for loop or something. But either way, what I thought of now is something similar to what you said but outside of families at all. Just 1 object has different animations for each type of object + a variable type like you mentioned and once it set, a sheet exists to dynamically set animations, attacks, etc... to that type.

    That or just use Enemies as you just did and have type determine which object to spawn from it -- I do have the Nickname plugin.

    You and R0J0hound I think confirmed my suspicions this is not worth doing considering the comparison between the two ways in every way. Thanks a lot for the insights guys

  • I haven't tried this in Construct 2 specifically, however this concept is more theoretical so it should apply just fine in Construct 2.

    Your problem is the player's sprite's collider set as a box. Since the floor is a slope and the player's collider is a box, this happens. To evade this problem change the bottom part of the collider to be more like a circle. This would nullify the "falling" and ugly stuff that happens.

    That said, if you are using Physics then you may want to make sure that your collider is balanced so the sprite doesn't fall when moving/standing still (i.e. the right side of the sprite is exactly equal and identical to the left side).

    You can achieve this two ways:

    1- Editing the sprite's collider directly and try to make it a bit spherical at the bottom (not really recommended).

    2- Create your player sprite, remove its bottom collider part. Create another object that is invisible and pin it to the player's sprite. In the new object, set the sprite's bounding box to look as spherical as possible.

    Hope that helps!

  • C2 internally recycles objects so that creating/destroying objects creates a minimal amount of garbage. That said have you measured if you get better performance with what you're doing? I've done stuff that creates/destroys hundreds of sprites every tick without causing more gc pauses.

    I am not going to lie to you, no. I didn't. It has been "ingrained" in my mind that garbage collection is bad and therefore I have to watch out for that from learning Unity.

    That said, I did notice something while working on another much smaller game. The game had 2x Every random seconds (3, 10) loop and each one creates 1 object at a time and the object moves from left of screen to right of the screen and then gets destroyed. When testing (using debug) on Chrome it showed that I am using "Est. CPU utilization" at 45-50 % while frames where anywhere between 45-60. Granted that I always have at least 6-7 tabs open in Chrome and other stuff.

    Anyway, That is what got me thinking that with this game I should try an object pooling.

    But if you think it is unnecessary or I am thinking too much into this area and I should spend that much thought in another place, I would.

  • Hello guys,

    Background:

    I am trying to watch out for performance from the beginning of development with C2 and don't want to refactor my code so I decided instead of creating/destroying objects, I should disable and enable them on run time as needed. However I have a couple of questions about the whole thing before I attempt moving further into it and wanted to see if you guys can help me with it. Note the game is going to be released as an HTML5 game; playable on mobile and browsers.

    Explanation:

    We have a layout where we need to spawn enemies on run time. The enemies are limited to let's say 10 and depending on the level they have different types and chances. The game has a wave system; each level has 3, so each wave being done a new set of enemies should spawn. Note however that waves doesn't relate to number of enemies but rather time, this means that you could have 3 enemies left but the time for wave 1 ended so now you need to spawn 10 more regardless of the 3 that exist. All enemies are stored in a family called Enemies and there is an EnemyList (array object) that will store UID of each object.

    Questions:

    The easy question first; do you think object pooling in Construct 2 is worth it? In Unity for example it saves memory by not triggering the garbage collection memory thingy (I am not a coder so I don't know the full details, just know it saves memory by not activating 2 process, destroying and creating a new object).

    The harder question -- if the first question's answer is yes -- now my pooling logic proved to be exhausting and complicated which drove me to think I might either be missing something or there might be a better way to do all of this. That is the question, is there a way to do the object pooling better than my below code?

    Variables for preparations:

    Now the action:

    Basically handle the call depending on what is going on:

    Pick a random number from the list of numbers in the family + 1 (since the random function isn't inclusive), then set the enemyPicker to that number. Now pick a spawner and pass its ID to the function that spawns the enemy.

    The function that spawns the enemy compares enemyPicker and checks one of 3 scenarios:

    1- If the enemy is invisible but overlaps the spawner -- it is deactivated and therefore we can activate the current type of enemy that is nearby and set its position to where we are.

    2- There are no overlaps but there is the same type of enemy somewhere else in the map -- we then spawn a whole new enemy and push it to the EnemyList array that currently holds all the enemies we have in the level.

    3- There is actually an enemy overlapping the current spawner -- it is taken by an enemy and we can't use it, so we basically call a "Look for Another Spawner" function to find another spawner.

    This of course has to be repeated to all types of enemies in the game manually one by one:

    Finally here is the "Look for Another Spawner" function (bottom 2 lines).

    As you guys can see it gets complicated and really tedious (not to mention confusing) as I go along -- specially if I wanted to increase the variant of enemies (now there are only 6). So I am unsure if what I am doing is worth it to evade the create/destroy process -- maybe even it is worth it but I am doing it wrong. What do you guys think?

    Thanks a lot in advance!

    EDIT: I noticed a few "bugs" with my setup for example the first check with the Goon enemy shouldn't have inverted "Overlapping with Spawner" and also a few other places. I already fixed them in my game but I am a bit lazy to get new shots, upload, crop, save, C&P links here and update the post. Besides, I believe the bugs are irrelevant to the questions.

  • Well I am partially not sure what you are trying to do. However, I can tell you that the "Else" condition only works when it connects to a System condition and not any other (at least that is what I know). If you tried to connect Else to any other object other than the System it won't activate at all. What you can do however is put a condition for each state or lack there of.

    For example, what I see here is that Character is overlapping Spawn or Safehouse. If you want to add a condition where anything else other than the previous ones, just add the above two conditions into one and invert them (right click a condition and choose invert). So it should read:

    Character is overlapping Safe House (x)

    Character is overlapping Spawn (x)

    The (x) denotes the inverted condition.

    Hope that helps or makes sense.

  • I success to move but my rival (peer) can't move his player.. the host can move the player but the peer can't.

    His player stuck.

    What to do?

    I won't lie to you, I haven't dived deep into multiplayer. But have you made sure that both of you have a copy of the player? That you checked which is host and gave him the ability to move AND the peer too?

  • >

    > >

    > >

    > > The name of the game his "charles" and I want to move the player like in this game.

    > >

    >

    > Then what you need to do is do a condition:

    >

    > Every Tick > Set Player Position X: Touch.X - Y: Touch.Y

    >

    But if i do this the player jump tu the position and I want the player move to this positing

    What will happen is that the player's position will be where the touch is. So the player must keep his finger on the device at all times to move, otherwise it will stop.

    The other method is the pathfinding solution. So when the player touches a certain area, C2 calculates a path that tries to avoid solid objects and the player sprite moves along it. Thing is, I don't think you can draw your own path using that behavior. If you want to draw your own path, you might want to look at:

    or

    Hope that helps.

  • With the solution of a bigger layout, on start of the layout use the system action "Scroll to position" using the average middle of your layout as destination.

    As for your GUI, place it on its own layer with parallax parameters set to 0,0 and place it according to the "project size rectangle". (https://www.scirra.com/tutorials/37/beginners-guide-to-construct-2/beginners-guide-to-construct-2/page-7)

    On start of layout, your "camera" will automatically scroll to the middle of your layout, providing the necessary space around to spawn enemies, and your GUI will still be appropriate.

    That actually gave me an idea. What I did to resolve this situation is that I created a sprite with size set to the window size. Placed it on a layer of its own and called it Guide and locked the layer. Next I set the Background layer I had to transparent and did what you mentioned with the GUI's layer being set to 0, 0 in Parallax.

    With this I resolved my primary problem of having some kind of guide when creating the levels so I don't have to guess where to put objects. Also that GUI tip escaped me so that resolved the issue as well with GUI being on different locations. Thank you very much!

  • Yes, the pathfinding works fine if it is inside the layout. However with the current setup, it doesn't. Even with the old setup it worked (With move; once the object is fully inside the layout, it worked). Not sure why with Bullet it doesn't.

  • The name of the game his "charles" and I want to move the player like in this game.

    Then what you need to do is do a condition:

    Every Tick > Set Player Position X: Touch.X - Y: Touch.Y