iOS - SpriteKit and image dimessions - sprite-kit

I just started using SpriteKit and I am trying to put a background on my scene. I want to support iPhone 5,5S,6,6+. So I created background with dimensions(using image casset: #1x at 320x480 , #2x at 750x1334 and #3x 1242x2208.
Then I am creating a Sprite:
SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:#"Backgroun.png"];
background.position=CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
[self addChild:background];
but the background is not covering the whole screen. What I am doing wrong here?
I found a workaround:
background.size = self.frame.size;
but this is not right! I want to know what dimessions the background has to be for each device.
Thanks in advance.

Related

CCAnimation shownig as black rectangle on iPod 4G

I create an animation like this:
//xxx animation cache
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:#"mainmenu_xxx.plist"];
//xxx blink
CCAnimation *animXxx1Anim = [CCAnimation animationWithSpriteSequence:#"char_xxx_loops%##2x.png" frameSequence:#"02,03,04" delay:1/24.0];
[animXxx1Anim setRestoreOriginalFrame:NO];
[[CCAnimationCache sharedAnimationCache] addAnimation:animXxx1Anim name:#"xxxBlink"];
and then run it like this:
//blink animation
[animatedXxxSprite runAction:[CCAnimate actionWithAnimation:[[CCAnimationCache sharedAnimationCache] animationByName:#"xxxBlink"]]];
It shows as it should on simulator, iPhone 3GS, iPhone 4S, but it shows as a black rectangle on iPod 4G. Any idea what could be causing it?
The problem was with the texture size. It is recomended that the texture size is lower than 1024x1024 pixels.
Also, sometimes, textures are shown with a very small (1-2 px) position error if it is not in POT format.

How to scale a game designed for iPad to iPhone?

I made a game using cocos2d for iPad.. Now I have to scale it for iPhone. I tried using scaleX and ScaleY parameters for my GameScene. It scaled the sprites, but I have a lot of hard coded boundaries for my objects which don't get scaled. How can I do the complete scaling of my game??
you have to do something like following
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
[yourview setFrame:CGRectMake(400, 208, viewrect.size.width, viewrect.size.height)];
else
[yourview setFrame:CGRectMake(190, 96, viewrect.size.width, viewrect.size.height)];
you already done for iPad, so now you need to change else portion
set your view's frame there according to device orientation.

cocos2d background image dimmensions

I'm trying to get started with cocos2d by creating an app with a background image. It's not a texture, just a straight image.
I add the background using:
CCSprite* background = [CCSprite spriteWithFile:#"paris.png"];
background.tag = 1;
background.anchorPoint = CGPointMake(0, 0);
[self addChild:background z:0];
The image is 960x640 but when I run it in the iPhone 5 simulator I only see a small part of the image. It's like it's too large for the screen. I was under the impression I would need 960x640. Is this not accurate? What resolution should my image be?
I've tried with and without the anchorPoint being set. Without the anchor I see a smushed image on 1/2 the screen.
Learn about retina display in cocos2d: http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:how_to_develop_retinadisplay_games_in_cocos2d
Make an image with 480x320 with name paris.png...
Rename your current image as paris-hd.png...
Enable Retina Display in app delegate.. And you are done.. Hope this helps.. :)

Transparent layer used in Tiny wings

please can anyone show me how to implement using cocos2d, a half transparent layer that is tapped for game start like that obtained in the game called Tiny wings.
Thanks.
Add a CCSprite to the scene then set the opacity to something less than 255 to make it translucent.
Here is some psuedo-code:
CCSprite* myTranslucentImage = [CCSprite spriteWithFile:#"touchMe.png"];
myTranslucentImage.opacity = 128;
[scene addChild: myTranslucentImage];
I've never played Tiny Wings but I do know how to make a CCSprite transparent.
CCSprite *example = [CCSprite spriteWithImage:#"HelloWorld.png"];
[example setOpacity:160];
If you must use a CCLayer you should look at the Cocos2d documentation.

PNG Transparency in cocos2d iphone issue

I've just begun cocos2d development on the iphone. An issue I'm having is that when I add a CCSprite to my scene, instead of it being transparent around the edges of the .png file, its showing up as white.
So for example, I define the CCSprite in my header file -
CCSprite *foo;
Then when I initialise my scene -
foo = [CCSprite spriteWithFile:#"foo.png"];
[self addChild:player z:0 tag:1];
Is there anything wrong with this code?
Thanks for any help.
P.S. I have double checked my .png file in Photoshop and its correctly showing up as transparent where it should be.
Check the bottom portion of this page:
http://www.cocos2d-iphone.org/wiki/doku.php/faq#my_png_doesn_t_look_like_in_photoshop