Cocos2d iphone app runs oddly on actual iphone - iphone

I have a simple application using Cocos2d, and all the images show up fine when running on the simulator. However, when i run it on an iphone, all the images are scaled up and incredible amount, making the game unplayable.
Has anyone got any ideas as to why this is happening, and how to fix it?

You need to consider the possibility that your simulator is running retina. Probably you are trying to display an image that is at the higher resolution on an older, non-retina device.
You can also just add the suffix "-hd" to any image, and then cocos2d will recognize it as being at the higher resolution automatically. But when you actually finish your app you will want to have 2 copies of each image, one at each resolution.

I found out that the problem was that when i initialised the sprite, using spriteWithFile, it set it to a certain size. When i changed the sprites texture later on, it kept the size of the last image, but had a different texture.

Related

Black cocos2d spritesheet in iPhone4

I've got a weird issue that is reported by one of my app users. My app is using UIKit and Cocos2d (the latter for basically just one scene, the rest is all UIKit). The CC scene uses a 2048x2048 spritesheet. The user says that on his iPhone4 running iOS6, the sprites appear black. The app works, no crashes or anything.
I have an iPhone4S to test on hand and all works fine. Looking at the specs, the IPhone4 should be able to support this size for a spritesheet. Only the iPhone3G is not able to, according to the specs (1024x1024 max. size for spritesheets it seems). But since the user is saying that he is running iOS6, he can't be using a 3G, right?
So I'm baffled. He's the only one reporting this issue, too. Is there anything else that could be causing memory or other issues and cause a black spritesheet in an iPhone4?

Cocos2d/Cocos2d-x Retina Issues

I have a multiplatform iOS/Android game that I programmed in Cocos2d-x. I have only one set of images to use (I'm only after high res devices) that get scaled according to the device's resolution. For example all images are for the iPad but if you are using a Galaxy S then the image locations and scaling are affected by GalaxyS_screenWidth/iPadscreenWidth.
This works fine for all Android devices and on iPad, iPad2 and old iPhones, but with Retina iPhone there is a problem. On the iPhone 4 all my images look extremely pixelated, a result from the images being scaled to iPhone non-retina resolution then scaled back up to fill the screen.
I tried enabling Retina Mode and the images are half of their intended size (maybe due to the usage of get winsize() which uses points) and scaling manually causes other sorts of problems. I tried playing with a lot of options and attributes but to no avail, so what should I do now?
EDIT:
This is not only a graphics issue, as text gets automatically scaled down then up and appears pixelated.
EDIT 2:
Fonts are bitmaps so my bad. But I don't want to use retina as all images are already retina by default. All of my images are set up for the iPad so for iPhone 4 I just scale them down a bit. This works with Android phones.
For example I have an image, depending on screen resolution obtained through getwinsize():
If current resolution width is 1024 then image stays the same.
If current resolution width is 900 then image gets scaled by 900/1024, no problem.
If device is iPhone 4 resolution width is 480, so image gets scaled by 480/1024, then cocos2d-x automatically scales the resulting image by 2 thus the pixelation. I tried using getwinsizeinpixels, I tried multiplying the screen size, I tried many things but nothing worked out of the box unless I am to redo many of my code.
So the question is, how can I just let the damn engine treat the iPhone 4 as an Android phone with resolution of 960x640?
If you want Retina resolution images to look like Retina resolution images, then those images need to be in Retina resolution (960x480).
If you first scale down the image to 480x320 and then upscale it on the device, it will of course look blurred. You can't magically make the Retina pixels appear from a lower resolution image by scaling it up.
SI couldn't get to the bottom of it so I employed a hack. I enabled Retina Display then I scaled everything x2 through code except for the text. Sounds stupid, but it worked, and pixelation is gone. Thanks everyone who spent time trying to help me.
I tried enabling Retina Mode and the images are half of their intended size
when you enable retina support, cocos2d gets images by appending #"-hd" to their provided filenames. Such images are meant to be double the "visual" size (in iOS terms, pixels vs. points), so that they can be sort of scaled down to make full use of device resolution.
If you have a look at the CCDirectorIOS class, you will find there a couple of methods dealing with this, especially those dealing with the scalingFactor. I don't know what kind of changes you should do to make it work, but if you step into those methods and look at the value of various objects, you might find a way to modify cocos2D default behavior for your specific case.
If this seems to complicated, one thing you could try is changing the CC_RETINA_DISPLAY_FILENAME_SUFFIX so that cocos2d will not look for specially-named files for the retina iPhone, but just use the normal ones.
For example all images are for the iPad but if you are using a Galaxy S then the image locations and scaling are affected by GalaxyS_screenWidth/iPadscreenWidth.
Another thing you might try is not using winSize, but winSizeInPixels, so that when you scale down, you down do it down to the point resolution, but just to the pixel resolution (which is double the point resolution).
Hope this helps.

Will images look different from the iPhone Simulator to an actual iDevice?

Images that I add to the layer in Cocos2d look pixelated around the edges of the image (i.e. a hillside, the rounded part of the hill, where the sky and the hill meet). I don't know if it's the image quality, or just because the graphics processor on my 'older' MacBook Pro is not as advanced as the iPhone 4 or iPod Touch 4 or iPad 2. Is it because of that?
I have ran into an instance where a large resolution image was being used in the context of a locally packaged HTML file in a UIWebView. The image looked fine in the simulator, but when ran on a hardware device, a bug was exposed in the rendering engine where it would invert the colors. Here's a bug report as an example of this. The solution was to scale the image down a bit in photo editing application.
While an extreme corner case, this is an example of the simulator not quite living up to how things will work on a hardware device.
The simulator usually does a pretty good job representing what the final image will look like. For the image quality on a normal computer to be worse than that of an iPhone for it to make a large enough difference, your MacBook Pro has to be really bad. So I doubt it.
However, if you really want to make sure, the best way to check would be to transfer the image you are using to another machine to see if it still looks pixelated. If it does, its a problem with your image.
Hope this helps and good luck!

Upgrading a cocos2d iPhone game to work at iPhone4 resolution using #2x

I am trying to add art to my game for the iPhone4 resolution. The images i am using are twice the original and i have added the #2x suffix to the image names.
When i load in a sprite like this:
[CCSprite spritewithFile:#"example.png"];
where example.png is the original image and example#2x.png is the scaled up version. When running on the original iPhone it loads the low res image and when running on the iPHone4 it loads the high res image, but it doubles the size of the image. So the high res image appears the same on the iPhone4 as on the original iPhone. Each pixel on the image takes up 4 pixels on the screen.
Any idea why this might be happening? Is there something I am supposed to do to tell the app not to double the size of the art?
Are you using the latest version of cocos2d?
The entire cocos2d API was converted
to Points. Previous versions were
using Pixels.
If your using v0.99.4:
cocos2d v0.99.4 has RetinaDisplay
support, however it required you to
use two different sets of positions
depending on the device , since the
API was in Pixels. (more)
If your using >= v0.99.5-rc0
But in v0.99.5-rc0 (and newer) the only thing that you have to do is[...] (more)
Have you read the "Retina Display in cocos2d" section of the cocos2d for iPhone wiki? (It pretty much tells you all you need to know.)

iphone 4 higher resolution pics vs 3gs

i just have a 3gs for testing (here in romania i still cant get a iphone 4)
When I just create full screen images for iPhone 4 .. would they be displayed resized on the 3gs?
I just cant make a bundle version for 3gs and 4 with 2 times my images, they are already a lot. Do I have to make now 2 Apps ??
Could this be a trick: In my xib i define a 320x480 UIImageView (it will be resized automaticly on the iPhone4) when I there define "scale to fill" and make high resolution images, would they come more sharp on the iPhone 4?
Now I am just wondering how to work best right now for big animations.
thx
Just found out in my case its fine to use higher resolution pics into a 320x480 frame like for 3GS and make Aspect FILL.
When I test on a iPhone 4 Simulator it shows much higher resolution and same on iPad if I click 2x :)
you can also create alternative high resolution images with a name ending in "#2x". so if you have an image called "arrow.png", create one with twice the resolution called "arrow#2x.png" and the iphone 4 will use that.
check out this article: http://thomasmaier.me/2010/06/dealing-with-iphone-4-resolution-2x-inside-of-photoshop/
Try it and find out, but my suspicion is that even if they do work, they won't work on OS 3.0 or OS 3.1, and plenty of people have not upgraded yet.
Also note that even if it displays them at half-size, I'm pretty sure that they'll still be "#2x" images. This means they'll use more memory and generally perform worse.
What's wrong with adding a handful of new images? The normal-size images are a lot smaller than the #2x images.
EDIT: If you have a lot of images, you may find it beneficial to use JPEGs where appropriate (e.g. for photos or photo-like backgrounds). I'm not sure, but I think they should work with +[UIImage imageNamed:] though you might have to specify ".jpg" explicitly.