yahiko Posted July 6, 2017 Share Posted July 6, 2017 I would like to know if by default drawing graphics (PIXI.Graphics) with pixi.js implicitly uses a buffer or if we have to do that explicitly. If so, is there a way to do that natively with pixi.js? For the moment, I have implemented a small class for this purpose, but maybe this feature already exists in the core library. Thanks for your replies Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted July 6, 2017 Share Posted July 6, 2017 What kind of buffer are you talking about? Quote Link to comment Share on other sites More sharing options...
Taz Posted July 6, 2017 Share Posted July 6, 2017 Maybe cacheAsBitmap could serve your purpose if the issue is optimizing for things that don't change often? Quote Link to comment Share on other sites More sharing options...
yahiko Posted July 6, 2017 Author Share Posted July 6, 2017 Let's say I want to animate 10k rectangles on the canvas. I maybe wrong, but I would draw these rectangles on a buffer first before displaying it all at once, by switching the visible attribute of PIXI.Graphics. This is what I call a drawing buffer Quote Link to comment Share on other sites More sharing options...
Exca Posted July 6, 2017 Share Posted July 6, 2017 Render your graphics into renderTexture and then use that as texture for 10k sprites. ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
yahiko Posted July 6, 2017 Author Share Posted July 6, 2017 In fact, I don't really want to turn my 10k rectangles into sprites since they could change at every frame (shapes and colors). Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted July 6, 2017 Share Posted July 6, 2017 Just take "Texture.WHITE" as texture, it will be 10x10 size, change width/height of every sprite (however i recommend to change scale instead). For color - change "sprite.tint". Quote Link to comment Share on other sites More sharing options...
yahiko Posted July 6, 2017 Author Share Posted July 6, 2017 That's absolutely true, I know this feature in Phaser which is based on Pixi.js until v3, but I forgot to mention that my graphics' lifetimes (not only rectangle in fact) are limited, and I produce new ones constantly, like a particule system in fact. Say differently, I really need to draw them programmatically at every frame. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted July 6, 2017 Share Posted July 6, 2017 Reuse old ones Just dont screw up remove operation. Whether its just visible=false or remove from array, it can have O(N) complexity instead of O(1) per one removed element. That's O(N^2) if you remove everything and its really bad. yahiko 1 Quote Link to comment Share on other sites More sharing options...
yahiko Posted July 6, 2017 Author Share Posted July 6, 2017 Good and quick discussion. I am going to stay with my home made implementation, but I will keep in mind what you have said guys. That could be a way to optimize my project ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted July 7, 2017 Share Posted July 7, 2017 18 hours ago, yahiko said: Good and quick discussion. I am going to stay with my home made implementation, but I will keep in mind what you have said guys. That could be a way to optimize my project Some people have inventors mind and find it difficult to use things they dont understand. Good luck to you! Quote Link to comment Share on other sites More sharing options...
yahiko Posted July 7, 2017 Author Share Posted July 7, 2017 As a matter of fact, I keep my home made implementation for the moment because it is satisfaying enough, performance wise, tt is also because I need to finish more important stuffs before optimization, and because of some lazyness of course! But what you and the others have written will surely inspire myself when I will be forced to optimize thouroughly with increasing objects and computations. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.