Update: Ouch... don't use "develop" branch... it is totally broken. I'm working on it.
[devel] Creating Hi-Res/Low-Res App in Cocos2D v0.99.4 and v0.99.5
(194 posts) (42 voices)-
Posted 1 year ago #
-
Fixed. Everything seems to be working OK.
Internally the Sprite is very Point oriented... probably I'll remove all the "point" API but the ones that are needed, and convert the rest to pixels.
Posted 1 year ago # -
Ok... I'm somewhat happy the current implementation.
CCSpriteandCCSpriteFrameAPI's are both pixel and point friendly.The Point method should be used by users, and the pixel method should be used by complex nodes like
CCSpriteFrameCache,CCTMXLayerandCCLabelBMFont.Example of point API:
CCSprite *sprite = [CCSprite spriteWithTexture:tex rect:rect];Example of pixel API:
CCSprite *sprite = [CCSprite spriteWithTexture:tex rectInPixels:rect offset:offset rotated:NO untrimmedSize:size];What I like about the new pixel methods is that there is at most 1 conversion from points to pixels per node. The previous API was converting pixels to points, and later it was converting those points to pixels.
http://github.com/cocos2d/cocos2d-iphone/commit/82e6026a761eff74ddcdf45a48bf186da3d2932c
Posted 1 year ago # -
@riq, for the debug draw in cclabelatlas, we have
#if CC_LABELATLAS_DEBUG_DRAW CGSize s = [self contentSize]; CGPoint vertices[4]={ ccp(0,0),ccp(s.width,0), ccp(s.width,s.height),ccp(0,s.height), }; ccDrawPoly(vertices, 4, YES); #endif // CC_LABELATLAS_DEBUG_DRAWShouldn't it be contentSizeInPixels (see below) ?
#if CC_LABELATLAS_DEBUG_DRAW CGSize s = [self contentSizeInPixels]; CGPoint vertices[4]={ ccp(0,0),ccp(s.width,0), ccp(s.width,s.height),ccp(0,s.height), }; ccDrawPoly(vertices, 4, YES); #endif // CC_LABELATLAS_DEBUG_DRAWPosted 1 year ago # -
Despite reading back through this long thread, I haven't quite caught being new to Cocos2d.
I have downloaded the updated version form github, however after enabling iphone 4 scale factor in app delegate, on older devices its too small, so what is it exactly I need to do to enable proper scaling across devices?
Say I just have a single image, standard and retina version what is the specific method I need to make these in to make scaling work? Or is there more a setting rather than method of loading images?
Posted 1 year ago # -
@jptsetung: fixed
http://github.com/cocos2d/cocos2d-iphone/commit/0ffefba14fd672ed42b7018e1f6f322c784ba221@kahanejosh:
You should only enable retina display on iPhone4. eg:
// Enables High Res mode on iPhone 4 and maintains low res on all other devices if ([UIScreen instancesRespondToSelector:@selector(scale)]) [director setContentScaleFactor:[[UIScreen mainScreen] scale]];See the cocos2d tests, they use that code, and all the tests were updated to support retina display on iPhone4.
Most of them are using high res images, but not all the images were converted to High Res, so you might find that some tests have the "expected" images, while other tests have smaller (SD) images.Posted 1 year ago # -
Thanks Riq, that code worked great.
Posted 1 year ago # -
Ok, forum noob here, so be gentle :)
Anyways, after scanning this long and wonderful topic (read the first few pages looking for something concrete, then went to the end and saw something that I *think* is concrete).
1) What release is this HiRes/LowRes patch in? Or should I use the git link above and merge it into my coco2d build directory?
2) How to implement the changes? Am I missing instructions/examples somewhere?
3) What cocos2d release should I be using? I'm using .99.5aThanks a ton. Love love love cocos2d and the community. I've just never had the need to post due to me always finding the answer.
Posted 1 year ago # -
I'll add the documentation here:
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:how_to_develop_retinadisplay_games_in_cocos2dFor the moment it is almost empty but I'll add the missing info today/tomorrow.
Posted 1 year ago # -
@riq, congratulations. As always, you are doing a great work.
Thanks.
RRdaS
Posted 1 year ago # -
I've just updated the documentation:
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:how_to_develop_retinadisplay_games_in_cocos2dFeel free to complete it, fix it, edit it, etc.
Probably it has many grammar errors. Feel free to fix them too! thanks.Posted 1 year ago # -
Thanks, Riq, for the documentation update! A few quick questions:
Could one put the @2x suffix in ccConfig.h to replace the -hd? Wouldn't this force the cocos engine to use the @2x images, overcoming whatever problems the standard Apple implementation has? Or is there a conflict there?
Zwoptec files - Can I use a -hd suffix for those or will I have to manually check for the screen size and load the higher res sprite sheet and its .plist as needed?
Lastly, how does this work for iPad universal apps? Does cocos2d respect the ~iPad file suffix?
Posted 1 year ago # -
Thanks for all your work on this Riq :) You've really made it work properly. Great stuff.
Posted 1 year ago # -
Yeah some strange behaviours happend to me with the @2x suffix. I'm using the default -hd suffix, but when I load the "Default.png" bitmap in iPhone4, it actually loads the "Default@2x.png". Well that's what I wanted actually, but this behaviour suprirsed me.
Posted 1 year ago # -
Thanks again, Riq. I'll stick to using the -hd suffix.
@jptsetung The app looks for Default@2x.png as it's launching, so it makes sense that it wouldn't know about the -hd version yet, since cocos2d isn't loaded yet. I'm not sure what's keeping @2x from working all the time, but I certainly appreciate the efforts of Riq, the contributors, and people on this post to find a workaround. I'd sure hate to have to check manually every time I had to load a Sprite! :)
Posted 1 year ago # -
Ouch, I tested on the iPad simulator with contenScale=2 and the game is totally broken. With contentScale=1, it works as expected.
I've sent an iPad owner and waiting for the results but I'm a little bit scared by what I've seen in the iPad simulator.Any feedback by other testers with the scaleContent=2 in the iPad simulator ?
@eshirt, actually, I'm loading the Default.png image with cocos2D after the iOS splash screen to make a smooth transition to the game.
Posted 1 year ago # -
I may be wrong, but I think the contentScale on the iPad is supposed to be 1.
I'm still looking into it myself, but I think you'll either have to use separate class files (e.g. HelloWorld~iPad.m) or manually check for the iPad screen size and load the appropriate resources.
EDIT: Looks like Riq beat me to it. :)
Posted 1 year ago # -
Sorry for the pseudo-code, but I don't have any samples yet. My guess is he did something like
if (screen size matches iPad) { load the HD files } else { load the file (and let cocos2d pick the SD or HD version) }An alternative would be to create separate classes for the iPad specific layout. This would cut down on conditional checks and make the code cleaner, but may require more maintenance than it's worth.
Posted 1 year ago # -
Yeah I basically did what eshirt said, except I check for "iPad" being in the device name. It's really sweet, because you get nice high-res graphics on the iPad, even though it's not a universal app, and you don't have to change any of your game code, and it uses your exact same retina graphics.
Riq, if you can make the Director emulate the scale factor, I think that will be the best, because then it'll just work on iPad in "iphone emulator" mode, and if people want universal apps, they won't set the scale factor at all and it'll work like normal. In my experience this was actually pretty easy to do, but maybe you've spotted some other issues that'll make it trickier?
Posted 1 year ago # -
Thanks Matt, I'm playing right now with no luck with the scalecontentfactor emulator, but I'm pretty sure we can do it. But as you tell maybe riq knows some difficulties I'm not aware of.
openGLView_.bounds = CGRectMake(0, 0, openGLView_.bounds.size.width * __ccContentScaleFactor, openGLView_.bounds.size.height * __ccContentScaleFactor); openGLView_.transform = CGAffineTransformScale(openGLView_.transform, 1 / __ccContentScaleFactor, 1 / __ccContentScaleFactor);Posted 1 year ago # -
Another thing to be wary of, Riq:
if ([UIScreen instancesRespondToSelector:@selector(scale)]) [director setContentScaleFactor:[[UIScreen mainScreen] scale]];With this code right now, the iPad app will sometimes start with a contentScaleFactor of 2. Despite the docs saying it doesn't, the iPad actually *does* have [UIScreen scale], which will return either 1 or 2, depending on the zoom mode the app starts in. I think it's better to check for the existence of contentScaleFactor on the window.
Posted 1 year ago # -
@riq, I got something more or less working in iPad contentScaleFactor x2 with the following code modification in the CCDirectorIOS.m. I'm testing in landscapeleft only. I'm pretty sure it's dirty code, but maybe that could help you understand a clean way to make it. The display is OK but the touch events doesn't work (the transformCoordinatesXxxxToXxxxx seems to be wrong).
-(void) applyOrientation { CGSize s = winSizeInPixels_; float w = s.width / 2; float h = s.height / 2; // XXX it's using hardcoded values. // What if the the screen size changes in the future? switch ( deviceOrientation_ ) { case CCDeviceOrientationPortrait: // nothing break; case CCDeviceOrientationPortraitUpsideDown: // upside down glTranslatef(w,h,0); glRotatef(180,0,0,1); glTranslatef(-w,-h,0); break; case CCDeviceOrientationLandscapeRight: glTranslatef(w,h,0); glRotatef(90,0,0,1); glTranslatef(-h,-w,0); break; case CCDeviceOrientationLandscapeLeft: /* glTranslatef(w,h,0); glRotatef(-90,0,0,1); glTranslatef(-h,-w,0); */ glTranslatef(w,h-960,0); glRotatef(-90,0,0,1); glTranslatef(-h,-w,0); break; } }Posted 1 year ago #
Reply »
You must log in to post.