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

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.)

Related

CGRectGet doesn't work well

I'm working in Swift with XCode 6 and Sprite Kit and I want to have the biggest pixel in y, so i'm using this function :
CGRectGetMaxY(frame)
and I tested my code with the iPhone 6 simulator, so the value should be 1334.0 but the console shows me only 667.0 ...
What is wrong ?
It appears you're working in "point-space" and not "pixel-space". Depending on your settings, your image (I'm assuming that's where 1334 comes from) is likely at a #2x resolution.
Check your assets folder to make sure the image is defined how it should be.
Check your scale settings
UIKit (and most of iOS) runs on point-space, so try to work in these coordinates - they abstract device resolution (important now that we have #1x, #2x, and #3x devices).
Point-space:
The original iPhone was 320x480 pixels. In order to have your code be device-agnostic, when they went to Retina, the screen and all the logic stayed at a resolution of 320x480. These didn't always correspond to pixels, so the terminology changes to "points". That's why when you grab the screen size for an iPhone 4 it still reports 320x480.
Apple's Documentation on this.

XCode iOS simulator - application is pixelated

I'm a beginner with XCode and I've encountered an issue. When I build my application, it looks fine in the standard iPhone simulator, but when I change the hardware to a retina device, the UI elements of my application become pixelated. How can I fix this?
You're seeing that because the retina screen is stretching the image you're supplying across more points on the screen. You can supply hi-res images in your bundle by appending #2x to the filename
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImage_Class/Reference/Reference.html: "If you load an image from a file whose name includes the #2x modifier, the scale is set to 2.0. You can also specify an explicit scale factor when initializing an image from a Core Graphics image. All other images are assumed to have a scale factor of 1.0. "
Here's a guide to supporting high-resolution screens.
As #RobotWoods mentioned, all images in your app need to have #2x versions.
If you're using OpenGL ES, custom code that creates images, or core animation, you need to make sure your code accounts for the display's scale.
If you're using only standard UIKit elements like UIButton, UILabel, UITableView, etc. then all you need to do is provide the #2x images.
If that doesn't help, please post screenshots and relevant code of what looks blurry.

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.

Cocos2d iphone app runs oddly on actual 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.

can the ui design for old iphone be used on iphone4?

I'm developing my software, all the ui is drawn based on 480x320 size screen, can my software run on iphone4 without any modification?
Yes it can run with no modification.
If you'd like to create "retina" assets you can create all of your images at the double resolution and include copies with '#2x' appended to the filename in your Application bundle. The iPhone will automatically load the correct images.
Example:
existing image - myImage.png
new up-sampled image - myImage#2x.png
Yes, but any images sized for the earlier iPhone models will look chunky compared to custom-designed iPhone 4 images.
Both the iPhone 4 and older devices are 320x480 points in size, which is the coordinate system that Core Graphics and UIKit uses. So your software will run the same.
Only the automatic scaling between your bitmaps and the display will be different. If you have bitmapped content or images, you can optionally provide #2x sized versions that will look somewhat smoother without the 2X scaling on iPhone 4 devices. This is nice, but optional.