AllanR's Forum Posts

  • sebastiangohhy

    I just happened to make a log system for a project I am working on last night.

    I have a global text variable called Log.

    at every point in the event sheet where I want to add something to the log I do a "System > Add to Global variable Log" and add NewLine & "whatever text to add"

    Then at the end you can do what ever you want with the results: display it, save it, send it to a database, etc

  • Set the Text objects Text field to something like:

    "a=" & SpriteA.count & ", b=" & SpriteB.count & ", c=" & SpriteC.count

  • 99Instances2Go ha, we were definitely thinking along the same lines. You must have a really nice laptop!

    HessamoddinS

    I just added another optimization that I was thinking about adding to the first version - limiting how many sprites it checks per tick.

    this version bumps the sprite count up to 300, but only checks 5 per tick. So, it takes a whole second for them all to have a turn looking for connections - but because there are so many, most of them will already have the connection made to them. Since it checks the same number every tick, there is no jerkiness.

    it runs very smoothly on my computer, cpu is under 50% as reported by C2 (but Windows says it really is only about 27%). If you watch really closely you can occasionally see where a connection should have been made but didn't get checked in time. But since there are so many other connections going on, I doubt anyone would ever notice.

    http://www.rieperts.com/games/forum/DotEffect2.capx

    if you play with the SpriteCount and CheckPerTick variables, keep SpriteCount an even multiple of CheckPerTick, otherwise some will never get checked, or it may even go into an infinite loop or something...

  • HessamoddinS

    You got me curious, so I tried a completely different approach...

    instead of comparing every sprite to every other sprite, I used a larger sprite "detector" to find sprites within 50px of the active sprite.

    plus I found a number of other ways to reduce the work it has to do every tick:

    • only look for close sprites 4 times a second
    • simplified the dictionary look-up
    • only calculate distance once per line per tick
    • don't update the text object every tick

    now it hits 60 fps, and averages around 15 to 20% cpu

    you can take a look at my code here: http://www.rieperts.com/games/forum/DotEffect.capx

    Then I though it would be fun to make one sprite "sick" and see how long it takes to spread. So, press x on the keyboard to turn a random sprite red, then any time it connects to another sprite, that one gets infected and turns red too. (it doesn't take very long!)

    press the space bar to turn them all back to black. (And then press x again to start another wave of zombie sprites)

  • pikazho

    Just took a look at your code, and the only big problem I see is that you are setting a text object every tick. That causes major trouble on mobile. Instead, only update the text object when the distance changes. Better yet, use a sprite font... although, with only one text object being rarely updated (only when it needs to change) you will probably not see much difference.

  • Just tried on my old iPhone 5, and it seemed pretty smooth to me (got a distance of 70 on my second try).

    What you see is pretty much what you get with an HTML game on a phone that is a couple years old. Make sure your OS is as up-to-date as possible. One of the biggest disadvantages of HTML is that it can only use one core of a cpu. So, while things have improved over the last few years (because cpu's are getting so much better), it still takes a lot of low level optimization to make a game run smoothly on mobile.

  • Just read how you wanted two arguments per username...

    The first version I made would only keep the arguments from the first time the username appears.

    I wasn't sure if there was some other method you would want to use to decide which arguments to save if the username appears multiple times in the original text file, so I made a new version that compares the arguments if the username is found and keeps the lowest values... (This gives the results you asked for in the first post).

    http://www.rieperts.com/games/forum/split_userdata2.capx

  • vila4480

    you are very close to how I would do it...

    just use tokenat again to split the username from the other argument...

    see my example:

    http://www.rieperts.com/games/forum/split_userdata.capx

  • willmonteirofx

    I was going to say I made an angry bird demo a couple years ago - but then I noticed the link was to that message thread, and lamar's capx was based on my example...

    so, the only thing I will add is that if you want the dots to fade out like in the image you made at the beginning of this thread, then add an action at event 4 (Draw dotted line) that says:

    Dot5 > Set opacity to (DotCount-loopindex) / DotCount * 100

    and you may want to reduce the DotCount global variable to 40 or less. Otherwise they will always know they are going to get a basket!

  • Try Construct 3

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

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

    well, I walked through it and didn't see any smoking guns. I was remotely concerned that the camera could get to the player before the last tile timers finished their fade-in (and then the fade-in group is getting deactivated - I though that might lock a tile in a state that prevents it from being destroyed). But I ran a test, and that would not be a problem.

    I notice you set the MapArray to mapwidth+1 but the Random and Temp arrays are only mapwidth. Any chance there is a rogue tile in the data being imported?

    The only way I could get a tile to fail to fade out was if it did not pass the overlap test at event 92. If the collision map for one of the animations (on a less common tile does not have a point inside the x+16, y+16 spot you are checking, then it will not get removed. So check collision maps, and origin points - I routinely accidentally click somewhere I shouldn't and change an origin (and not notice) , or forget to make one of the animations match all the others...

    For debugging purposes, I would zoom the layout scale out so you can see the whole map at the start of the fade out group, and show a live tile count in a debug text box so you know for sure whether the tile count is not getting "less than or equal to 1" to satisfy event 94. Or if maybe some other strange combination of events is happening somewhere else (like somehow disabling the fade out group before it gets finished). The fact that it happens rarely certainly makes it harder to track down - but there always is a logical explanation.

  • helena

    well, hard to say without seeing more of the code, but if the event isn't running then the tile count isn't getting down low enough to trigger it.

    which would indicate the timer is never getting started for one or more tiles. The most likely cause of that would be a glitch in your RandomTileArray, or a problem with the overlapping, or a tile not where it is supposed to be.

  • HessamoddinS

    the way I usually do what you want is to put the sprite in a family. Then you can compare an instance to the family

    spritefamily.x > sprite.x would then pick all the instances with an x greater than the one you are interested in

    and then you can do a for each spritefamily to compare them individually to sprite... or whatever else you want.

  • Lerp would certainly work, although it might be easier to just calculate a scale factor...

    if the top of the screen is 0 and the bottom is 800. And you want it to be full size (100%) at the bottom, and say 10% at the top then: (whenever you change the y value)

    sprite > set scale to Sprite.Y/800 * 0.9 + 0.1

    if the screen bottom is 1024 and you want it to be 20% when at the top:

    sprite > set scale to Sprite.Y/1024 * 0.8 + 0.2

    You would also want to adjust the speed as it shrinks to help sell the idea that it is moving away from you...

    EDIT: ok, just read your post again, you mention that there would be a set point where it would be full size... so you want to clamp it

    at the top of screen set it to 10% and at y=500 and below have it at 100%:

    sprite > set scale to Clamp(Sprite.Y/500 * 0.9 + 0.1, 1, 0.1)

    clamp will now prevent it from getting bigger than 100%, or smaller than 10%, so it will stay 100% between 500 and the bottom of the screen, but will scale smoothly towards the top of the screen once y is less than 500...

  • corlenbelspar

    adding variables to objects is a great way to do things. Variables take up very little room. The graphics, sounds, music take up a lot more memory.

    Try exporting and running to see if that takes an acceptable amount of time to start, and compare that to a preview.

    Or try running the debugger and see what is slowing things down.

  • maordany

    It gets surprisingly complicated. There is no pre-built scroll bar, so you have to make your own. I just happened to make one recently, so I thought I would share a simplified version of it.

    This version scrolls the whole layout (with a tall picture on it). You need a top layer that contains the scroll bar, and doesn't scroll with the rest of the layout (set its parallax to 0,0). It automatically adapts to the layout, so if you change screen dimensions and it will snap to the right side of the screen, and position and resize itself.

    You can change the speed at which it scrolls by changing the ScrollSpeed instance variable in the ScrollBar sprite. You can also change the ScaleSize to make it appear bigger or smaller if necessary. This version only works with a mouse. Touch adds more complexity - like how do you properly handle multi-touch, do you want to pan around, pinch to zoom, etc...

    If you were wanting a scroll bar to scroll an image inside a window on the layout, without scrolling the whole layout, that gets even more complicated. Then you need a whole separate layer for that, then need to mask off the parts to not show...

    Hopefully, this will get you started.

    http://www.rieperts.com/games/forum/Scroll.capx