1 light ok, 4 light = game crash

Usernoob

  • Posts: 27
Hi, i'm the noob who sometimes try to make new thing in stencyl.

Now i'm trying to make light effect with image API. I create a black wall and clear some circles for the light.

It works for one light, but whit 2, 3 or 4 the game go more and more slow.

In this game you have a light in the mouse, and can create more static light with click:

http://www.stencyl.com/game/play/39632

here is the code, what i'm doing wrong ?


merrak

  • *
  • Posts: 2738
Image API does image manipulations in software, which is slower. You can make it work, but you'll need to minimize the number of drawing operations. For example, you probably don't need to redraw all the lights that are placed by clicking. You'll need to redraw the area that the mouse leaves. One thought: Consider two rectangles: One enclosing the light the mouse enters, and one enclosing the light the mouse is leaving. Only redraw the portions of your image that lie in either rectangle.

Usernoob

  • Posts: 27
Yes but, in the future,  the static light will be mobile enemies. so i need redraw the image per each enemy light in movement.

merrak

  • *
  • Posts: 2738
I've done this kind of thing plenty of times before and haven't had any issues. There definitely is a tight upper limit to how many drawing operations you can perform per frame, but 4 seems like such a low number. I'd expect better performance than that. There's probably an important variable in this scenario I'm not able to see... such as image size or screen size.

Do you have a playable demo uploaded somewhere, like on Stencyl Arcade?

domagojbulat

  • *
  • Posts: 207
There is a link in the first post
http://www.stencyl.com/game/play/39632

I think "do for every actor of type" on the very bottom of your screenshot does the trouble. I guess you don't need to clear image each 0.05s. Can you make it so that it clears it just once when mouse is pressed? On mouse input trigger an event that does "do for each actor of type"

Usernoob

  • Posts: 27
I'm thinking stencyl is not a good tool to make RTS like starcraft. I have problem after problem. If 4 static light are too hard to process imagine a full army of 100 warriors with torchs in a night battle...

Maybe if "Drawing" a rectangle in screen and clearing holes (not image API, just "Drawing". But, its posible create holes in a draw figure ??

merrak

  • *
  • Posts: 2738
Whoops. Somehow I missed the link.

That is a huge size for a Flash game. It doesn't even fit in my browser window. I think the first problem you're having is in targeting Flash. Flash will be slower than the other targets.

An RTS of the magnitude you're describing should be doable. A good example would be Dincicode's NC Tactics--although he doesn't have light. You'll want to take advantage of shaders. You would definitely benefit from the improved shaders support Stencyl 3.5 (which uses OpenFL 8+) offers. I forgot what OpenFL version Stencyl 3.4 is built on top of, but it is several generations old. You can do all the light operations in software only, like I did in my game, but optimization is the key.

Maybe if "Drawing" a rectangle in screen and clearing holes (not image API, just "Drawing". But, its posible create holes in a draw figure ??

I don't think you can do that--but even if you could, you don't want to. You're still not solving the optimization problem: redrawing pixels that you don't need to. The problem lies in doing unnecessary work, not in how you do the unnecessary work.

« Last Edit: November 11, 2018, 10:07:18 am by merrak »

Usernoob

  • Posts: 27
Hmm....   I create all my "game attempts" in flash, maybe that is the cause of all my problems.

Thanks a lot.


Fool

  • Posts: 88
Have you considered using transparent masks? This is how I did cheap lighting in my game.

What you do is

1. Create a layer in the scene editor, call it 'lighting' above everything except the ui layer

2. Set the layer background color to some default color, like black. This represents darkness

3. Create a circular sprite, the outer edges that are 'dark', are the same color as the background color for the light layer.
    The 'light' portion is a partially or fully transparent circle in the middle of the sprite

4. Assign the new sprite to your light objects

5. Spawn or place your light objects on the light layer.

I forget which, but be sure to set blending mode (on the layer, or sprite, eh), to either 'add' or 'multiply'.

Might take a little experimentation, but this is what worked for me when I had a lot of lights at once.

In this regard it is more akin to 'fog of war', and in fact, you should be able to do the same thing FOR fog of war.