gerard / TwoDeeWars

A 2D space shooter
2 stars 1 forks source link

Game redraws every frame (too computationally expensive) #8

Open gerard opened 12 years ago

gerard commented 12 years ago

Discussion in #kivy, Freenode

01:30 < heoa> https://github.com/heoa/TwoDeeWars/blob/master/main.py <-- could someone explain how to change this game to moving alphabets? 01:31 < heoa> https://play.google.com/store/apps/details?id=net.geeksynapse.geox.TwoDeeWars <-- you can see here a viedo 01:31 < heoa> I want to make the game so that objects moving faster are in the end of the alphabets 01:32 < heoa> I want to understand what the cubes are 01:34 < tshirtman> oooh, another game on market done with kivy :) 01:37 <+tito> heoa: where did you hear about it ? 01:37 < tshirtman> https://github.com/heoa/TwoDeeWars/blob/master/main.py#L130 that's what draws the enemies 01:39 < tshirtman> the way he built it, the drawable class, makes it harder to do what you want i thin ... 01:40 <+tito> tshirtman: he came from pygame world 01:41 < tshirtman> tito: hmm, i do to, that's true i had a hard time 'getting' kivy at first 01:43 <+tito> and the pygame approach is really not efficient at all, but that's how we teach/read about computer gaming in the first place... 01:43 <+tito> tshirtman: http://jsharkey.org/blog/2009/04/22/modifying-the-android-logcat-stream-for-full-color-debugging/ 01:43 < heoa> tito: I am very green here, could help me to make it better or guide how not to do things? ... 02:13 <+tito> heoa: his code start a clock to run an "update()" method 60x per seconds: L305 02:13 <+tito> in the update, at the end, he's updating ennemy, of class L110 02:14 <+tito> in the Ennemy.update() he is recreating a Rectangle()... 02:14 <+tito> Same for Pew class, or Player class 02:16 <+tito> and, because you only see one of them every frame, he's removing the object created from the previous frame L39 02:16 <+tito> => thousand of graphics object are created each frame, and deleted next frame. 02:16 <+tito> so much GPU transactions :/ 02:16 <+tito> and CPU calculations for nothing ... 02:22 <+tito> you have Label for that, you can play directly with Label widget etc 02:22 <+tito> but if you don't know anything about kivy, then just learn by yourself 02:22 <+tito> experiment, read tutorial, redo it, check examples etc. 02:23 < tshirtman> yeah, don't learn from that game's code, it's really not how one should do it ^^ 02:24 < tshirtman> regardless of the game quality ^^ 02:24 < heoa> back to pong? 02:24 <+tito> https://github.com/stocyr/Deflectouch 02:24 <+tito> this game is already more closer about kivy's spirit 02:25 < tshirtman> tito: oh man, you'll love the bug report that just came in ^^