Draw.withCode or using Sprites?


(christopf) #1

Hi, i’m wondering how i shall create a lightning around my hero the way performance is untouched most. To now i use different images on canvas (they are big as the screen of the game) and switch them with a switch { case } method and a timer. but i think it may be better to let the canvas draw with code only or i am wrong on that thought? Its important for me i get a specific flickering and and the circle shouldnt be a clean one.

i think i can manage everything this way but i fear performance loss in the end when i added more entities in the game and they all appear on the screen. additional for understand the case better: i want to have kind of 10 different light radii with each 3 different kinds for a flickering effect.

i brought a gif for a better understanding (i’m sorry for the size i tried to keep it small)



hopefully i could describe my idea well enough. thank you


(Jacob Albano) #2

This looks really neat!

If you only have one light source, this approach will be just fine. If you need multiple sources (like torches or lamps in the world), you’ll want to look into subtractive rendering, or use this lighting engine.

I’m confused what you mean by “drawing with code only”, though. Can you elaborate?


(christopf) #3

Thanks :blush:

I already found lit and maybe give it a try. with subtractive rendering you mean the blendmode? i tried the subtract mode with the light circles you can see (slighty different) but it didnt allowed every degree of opacity so i dropped it.

i thought of a possibility to draw a circle in as3 with code and then subtract it with different alpha channels. maybe using a small noise code or imagepattern to add a flickering. this would cause less imageload but more code for constructing (i’m pretty new to programming so i dont know the exact terms :/). its more like a genereal logic question since the imagefile itself is purecode too isnt it?


(Jacob Albano) #4

Yeah, that’s what I mean. Lit uses subtractive rendering to do its work.

If you’re considering using the Flash drawing API or the Draw class in the name of speed, don’t bother. The reason I discourage use of Draw is because it’s much slower than Flashpunk’s renderer. If performance is ever a concern, the drawing API isn’t a good solution.


(christopf) #5

Thats what i wanted to hear, guess i’m heading for the multiple images for now and try to solve performance issues in another way.


(rostok) #6

If memory isn’t an issue here just add as many circle images as you want. Remember though that each image will take app. 1MB of ram.

BTW why are you talking about blending modes? Since this is the top most layer all that is needed to have dark image with blank (no opacity) circle in center


(Jacob Albano) #7

I brought up blend modes in case he wanted to have multiple lights.


(christopf) #8

Is it 1mb for every image whatever size and is it for every image in game but not on screen?


(rostok) #9

Your GIF is sth like 640x480 so raw data for full screen bitmap is 6404804=1228800 bytes. Note that PNGs or JPEGs are kept in memory uncompressed. There are however some tricks to reduce this, for example having only a quarter of image and they copy it to other parts. Not sure if it is worth the effort.

@jacobalbano Ah yes. now I get it