ios - ccDraw. Fill screen everywhere except on sprite -


so trying basic "flashlight"-style thing going in 1 of games.

the way getting work, having layer on top of game screen, , layer draw black rectangle ~ 80% opacity, creating of darkness on top of game scene.

ccdrawsolidrect(ccp(0,0), ccp(480,320), ccc4f(0, 0, 0, 0.8)); 

what want draw rectangle everywhere on screen, except around cone of vision represent "light source".

what create dark overlay on top of except light, giving illusion of torch/light/flashlight.

the way can foresee happening using ccdrawsolidpoly(), since position of light source changes, vertices poly.

any suggestions on how achieve great.

you can use ccdrawsolidpoly() , avoid having manually update vertices. can create new subclass of ccnode representing light object, , custom shape drawing in -(void)draw method.

the ccdraw...() functions draw relative local sprite coordinates, can move , rotate new sprite suit needs , cocos2d vertices transformations you.


update: found out might better off subclassing ccdrawnode instead of ccnode, has facilities raw opengl drawing (opengl's vertexarraybuffer , vertexbufferobject internal variables , buffer vertices, colors , texcoords). if stuff simple, maybe subclassing plain ccnode enough.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -