Loading PVRs on the iPhone
by Nate Gertsch · in iTorque 2D · 08/14/2009 (10:53 am) · 13 replies
I'm trying reduce the memory used by my iphone game and I've converted most of my images from pngs to pvrs as I heard that those take up less memory when loaded. I've also moved most of my image datablocks to separate files that I exec when loading up the screen they appear on. My problem is that, while my pngs are loading on the device, my pvrs are not. Everything works if I run it in the torque game builder but if I actually run the game on the itouch I'm using for testing, none of the pvrs appear.
Here's an example of a datablock that I'm using. I did a direct cut/paste from the datablocks.cs file in the managed code folder and then changed a few fields. I read on the forums here that if you did not include the extension that torque would load the .pvr version of the file.
I do the following when I load my level up. The datablock above is contained in ShopImages.cs.
Is this the correct way to go about it? It seems to be the same as what other people have done from the examples I've found on the forum but it is certainly possible that I'm missing something.
I also have another question that may be totally unrelated. When building a new version of my game after making changes, I've been just going into xCode, cleaning the project and then rebuilding. I've avoided TGB's build project menu with a superstitious dread as I'm not sure what's going on there. Yet, I've been having some issues with the simulator where it would consistently play an old version of my game and refuse to update even after rebuilding the project. Are my current steps sufficient or do I need to do something more like uninstalling the app everytime I want to try a new version?
Here's an example of a datablock that I'm using. I did a direct cut/paste from the datablocks.cs file in the managed code folder and then changed a few fields. I read on the forums here that if you did not include the extension that torque would load the .pvr version of the file.
new t2dImageMapDatablock(Explosion_01_IconImageMap) {
imageName = "~/data/images/Explosion_01_Icon";
imageMode = "FULL";
frameCount = "-1";
filterMode = "SMOOTH";
filterPad = "0";
preferPerf = "1";
cellRowOrder = "1";
cellOffsetX = "0";
cellOffsetY = "0";
cellStrideX = "0";
cellStrideY = "0";
cellCountX = "-1";
cellCountY = "-1";
cellWidth = "0";
cellHeight = "0";
preload = "0";
allowUnload = "1";
compressPVR = "0"; //Doesn't seem to change anything if I make this 1
};I do the following when I load my level up. The datablock above is contained in ShopImages.cs.
exec("game/GameScripts/ShopImages.cs");
ExplosionUpgrade1Button.setImageMap(Explosion_01_IconImageMap);
//Many more like this that don't show upIs this the correct way to go about it? It seems to be the same as what other people have done from the examples I've found on the forum but it is certainly possible that I'm missing something.
I also have another question that may be totally unrelated. When building a new version of my game after making changes, I've been just going into xCode, cleaning the project and then rebuilding. I've avoided TGB's build project menu with a superstitious dread as I'm not sure what's going on there. Yet, I've been having some issues with the simulator where it would consistently play an old version of my game and refuse to update even after rebuilding the project. Are my current steps sufficient or do I need to do something more like uninstalling the app everytime I want to try a new version?
#2
And do as Marc says for rebuilding - delete your app (or the build directory) and do a rebuild. You don't need to delete the directory or app if you only made engine changes however, only if you made script level changes.
08/17/2009 (11:56 am)
Make sure that your PVRs are all power of 2. TGB will load up PNGs that are not power of 2, but the iPhone requires PVRs to be.And do as Marc says for rebuilding - delete your app (or the build directory) and do a rebuild. You don't need to delete the directory or app if you only made engine changes however, only if you made script level changes.
#3
08/17/2009 (12:28 pm)
Is it just script changes or any changes to your resources? I thought it was the latter.
#4
08/17/2009 (12:33 pm)
Anything thats not a source / XCode side change.
#5
08/17/2009 (4:28 pm)
The PVR generator will not build PVRs which are not powers of two, so if the PVRs generate they should be OK.
#6
08/17/2009 (4:33 pm)
Ronny: I've worked with a number of PVR generators that will pump out non-power-of-2 PVRs. It had me confused for awhile at first why many of my PVRs wouldn't work on the iPhone until I realized only the ones that weren't power of 2 wouldn't work.
#7
08/17/2009 (4:33 pm)
Hmm I swear all my pngs are square powers of two. I wonder if I just wasn't rebuilding the application correctly and that it didn't update my latest changes. I'll play around with it some more to see if it is really updating when I rebuild.
#8
08/17/2009 (4:34 pm)
@Nate: If you want to be super extra safe, then remove the project files from the Releases folder in Xcode, do a project 'Clean All', drag/drop your files back into the Release directory, then delete the build directory, then do a full rebuild. I have seen some cases where the project gets locked in a certain state and I have to perform that set of steps to un-freeze it and move forward.
#9
08/17/2009 (6:54 pm)
@Dave: Well, Apple's generator (which is used by the iTGB generator on Mac) refuses to accept bad PNGs ;)
#10
08/17/2009 (6:56 pm)
Ah! Yes, that one. I've never gotten that one to work, lol... that one always spits out either corrupt files or nothing at all for me.
#11
08/17/2009 (8:30 pm)
Works perfectly fine here - I can use them in Apple's examples and Cocos2D. With the tool from iTGB, the header is correct for iTGB use too.
#12
08/19/2009 (7:24 pm)
To add further confusion to the issue, I asked our artist to make a pvr file for me and his worked fine. I was using apple's generator and he was using a tool that worked on his PC. At this point, I'm inclined to blame apple and convert everything using his method.
#13
08/20/2009 (4:38 am)
Nothing wrong with Apple's tool - it's just that iTGB doesn't load the format it produces.
Torque 3D Owner Marc Dreamora Schaerer
Gayasoft
As for rebuilding: all you need to do is kill the app file actually. thats the fastest solution.