Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - hansbe

Pages: 1 2 3 4 ... 18
16
Paid Work / Re: I am looking for a team
« on: June 19, 2012, 09:16:48 am »
I'll give you a +3 rob. How's that for popular? :)

17
There is a block "set volume for channel X to Volume %"

As long as you always start the music in the same channel (f.ex. 0) you can control the music volume individually. The same goes for sound effects. All the other channel volumes that you use for sound effects need to be set to the volume you want for the sound effects.


18
Resolved Questions / Re: Does the Stop block stop code for...
« on: June 19, 2012, 07:24:56 am »
If your code gets to "stop" it would exit the event there. It doesn't prevent the event from being triggered again later. If you are inside a custom block stop would return to the event that used the custom block.

19
Ask a Question / Re: Some questions about sound/audio in Stencyl...
« on: June 19, 2012, 05:32:29 am »
I don't know the best way.
I got a custom package to work by copying it into the preview folder.
Not sure if it is safe there though, so you should keep a copy.

20
Ask a Question / Re: Saving
« on: June 18, 2012, 08:24:20 pm »
Actually there is also the problem of loading the saved game.
Then you must have saved the game with the correct value for gaText in between.
The load game is maybe unnecessary ?

21
Ask a Question / Re: Saving
« on: June 18, 2012, 08:22:23 pm »
gaText is a text attribute not a boolean, so you should test it against a text string.
When I imported the behavior the initial condition of gaText was 0
So if you want to test it against 0 you can wrap 0 in the "anything as text" block.
Then you can set gaText to 1, for instance.

The always event requires a similar change to the tests, e.g. test for a string. The content of this can also be moved to the when created event, as it will only be required to run once after the scene loads.

22
Ask a Question / Re: Saving
« on: June 18, 2012, 08:09:41 pm »
Ok. The little camera button in the corner can be used to create an image of the behavior such as this. (I'll comment in another post)

23
Ask a Question / Re: Flash vs Browser
« on: June 18, 2012, 01:42:55 am »
It could be that the flash player bundled with stencyl is kind of old, compared to what you probably have installed. Testing, and having it work with two different versions of the flash player isn't a bad thing though.

24
Resolved Questions / Re: Files corrupted. What can I salvage?
« on: June 18, 2012, 01:38:41 am »
Wow, that must suck, yeah. Feel for you.. I had a look and it's not just the xml's. Many other files are overwritten completely with '00' bytes. Some things are still there though, scenes 0, 2 and 3. A few behaviors. Which behavior was the desired one ?

25
Ask a Question / Re: Saving
« on: June 18, 2012, 01:21:29 am »
Hi, again. Sorry I can't see what you have done since last time. If you post the new behavior, but this time using the screenshot / camera button, so we can see the code directly in the browser, then I think people here will be much quicker to help :)

26
The content of this post shows how to do some rudimentary profiling, that is, how to figure out how much time a piece of code takes. The basic idea presented here is to use a stopwatch method:
  • Measure the current system time (tic)
  • Execute code under test
  • Measure the current system time (toc)
  • Present the measurement result (toc-tic)

I only use stencyl for flash, but if anyone posts a method for iOS, I can update this post.

Flash AS3 method
The basic idea is to use the flash.utils.getTimer() method which reports time since a flash application started in milliseconds. Unfortunately I know of no more accurate timer in flash, therefore it will be necessary to wrap most bits of code in a loop to test it.

    Step 1 : Put this in a code block at the beginning of the behavior/script/class:
    [/list]
    Code: [Select]
    import flash.utils.getTimer;
    var tic,toc : int;
    Step 2 : Do a tic measurement and wrap the code you want to test in a loop.
    Code: [Select]
    tic = flash.utils.getTimer();
    for(var index0:int = 0; index0 < 10000; index0++)
    {
    Step 3 : End the loop, do a toc measurement and print.
    Code: [Select]
    }
    toc = flash.utils.getTimer();
    print("[loop] time taken:"+(toc-tic));
    Interpreting results:
    • Results vary linearly from CPU to CPU based on operating frequency.
    • Results can vary a LOT from CPU to CPU based on architecture (pipelining, branch prediction).
    • If the code is 'memory intensive' the size of the cache is important, as well as the speed of memory retrievial itself.
    • GPU capabilities and similar can also affect results a lot, for rendering, etc.

    Flash AS3 Examples:

    My laptop CPU runs at 2.26 GHz
    An empty loop with 10 million iterations took about 43 ms on average. Indicating that each iteration took on average: (0.043/10000000)*2260000000 ~= 9.73 cycles.
    (This isn't entirely accurate of course. The most important source of error is that the code may be interrupted by other tasks by the operating system.)

    A loop containing 'foo=foo+1;' with 10 million iterations took about 1018 ms on average. Indicating that each iteration took on average: (1.018/10M)*2260M = 230 cycles.
    A loop containing 100 'foo=foo+1;' with 100k iterations took about 430 ms on average. Indicating that each iteration took on average: (0.430/0.1M)*2260M = 9718 cycles.
    However each instruction took on average: 9718/100 ~= 9.7 cycles.

    This performance is pretty nasty (bad) and I the issue probably with pipelining. E.g. for the foo=foo+1; instruction my cpu must wait until foo in the previous instruction is calculated before starting on the next instruction.

    A loop containing 10 repeated calls to 'foo2();' where foo2() is an empty function (custom event) with 33k iterations took about 10 ms. Indicating that each function call took on average: (0.010/0.033M)*2260M ~= 684 cycles.

    Some possible performance hogs

    • You don't want these inside inner loops (so they execute many many times)

    A loop containing 2 game text attribute setters;'. I.e.:
    Code: [Select]
    setGameAttribute("gaText", "cba");
    setGameAttribute("gaText", "abc");
    with 100k iterations took about 77 ms. Indicating that each setter call took: (0.077/0.1M)*2260M/2 ~= 870 cycles.

    A loop containing 2 behavior boolean attribute setters;'. I.e.:
    Code: [Select]
    _Collided = false;
    propertyChanged("_Collided", _Collided);
    _Collided = true;
    propertyChanged("_Collided", _Collided);
    with 100k iterations took about 128 ms. Indicating that each behavior setter call took: (0.128/0.1M)*2260M/2 ~= 1446 cycles.
    (It is obviously the call to propertyChanged that takes so much time, and it is likely not neccessary inside an inner loop. (Note to self:There were 12 other attributes in this behavior.))

    An obvious optimization is to remove propertyChanged(). I believe it is unneccessary unless you use attribute listeners. It might be a mistake of the code generation to generaty this code bit for all attribute setters.
    Now I also hypothesize without testing that the dynamics of setGameAttribute() and propertyChanged() can change according to how many attributes you have. So if you have many game attributes,  behavior attributes could be faster. Re. Tom in this post.


    I hope this can lead people to experiment, discuss, and from that understand a little bit about how to write faster code. If you share experiences I can try to summarize results in this first post, from time to time.

    27
    Old Questions (from 1.x/2.x) / Re: Why do x-speeds look so bad?
    « on: June 16, 2012, 02:22:20 pm »
    I don't know exactly. Since you said tweens look better I figured it might be an anti-aliasing thing. I think my main hypothesis is that actor's that are set to 'can not rotate' will get anti-aliasing turned off. I don't know this though, but I 'feel' I remember it from somewhere. You can test it, even try rotating them by 0.1 degrees maybe. But to be fair I feel like I don't know squat right now. You should research it or someone else with some more knowledge should comment on this.

    28
    Ask a Question / Re: Some questions about sound/audio in Stencyl...
    « on: June 16, 2012, 08:39:21 am »
    Just for synchronization of sound effects and actor animations I think a lot could be done based on  flash.utils.getTimer()

    When you start the background track you need to know its BPM and a starting offset, then you record the starting time. Then you can make a sound event queue in a couple of lists. Events would trigger a callback based on if you passed the relevant time or beat.

    29
    When you select a group of actors you can find a little hot-spot outside the corners of the selection area. You can use this to rotate a group of actors. Hold shift to snap to 45 degrees.

    30
    Old Questions (from 1.x/2.x) / Re: Why do x-speeds look so bad?
    « on: June 16, 2012, 03:36:30 am »
    Hmm.
    Do you see any FPS drops ?
    Or you have large scaling (4x) or anti-alias / smoothing isn't on.
    Is there any source of friction ?

    Pages: 1 2 3 4 ... 18