Note that there are some explanatory texts on larger screens.

plurals
  1. POCocos2d CCLayer.scale
    text
    copied!<p>I am in process of making a small game, where the main Gameplay Layer is being zoomed in and out based on a number of parameters. This is done by setting the .scale attribute to a fraction of 1. Works well.</p> <p>I have a problem, however, that when calling <code>[[CCDirector sharedDirector] winSize];</code> from any of the child nodes, I get a scaled window size, which kinda sucks :) Is there any way around this apart from multiplying all my off-screen checks by the scale fraction plus one?</p> <p><strong>Here is an example</strong></p> <p>I am creating a CCLayer and placing Sprites on it. All the sprites have a static variable with the screen size during initialization, basically</p> <pre><code>static CGRect screenRect; //stored as a static variable for performance reasons ... -(id)init{ ... // make sure to initialize the screen rect only once if (CGRectIsEmpty(screenRect)){ CGSize screenSize = [[CCDirector sharedDirector] winSize]; screenRect = CGRectMake(0, 0, screenSize.width, screenSize.height); CCLOG(@"Screen Size during init: %f, %f", screenSize.width, screenSize.height); } } </code></pre> <p>I then have a check when the sprite is moving around whether it is off the screen, and if so, I take it automatically to the opposite side:</p> <pre><code>if(newPosition.x &gt; screenRect.size.width){ newPosition.x = 0; }else if(newPosition.x &lt; 0){ newPosition.x = screenRect.size.width; } if(newPosition.y &gt; screenRect.size.height){ newPosition.y = 0; }else if(newPosition.y &lt; 0){ newPosition.y = screenRect.size.height; } </code></pre> <p>All works very well and as expected. However, if I change the <code>scale</code> property of the parent CCLayer then offscreen positioning "scales" together with the layer, which is kinda weird. So if I set the <code>CCLayer.scale = 0.5f;</code> then it appears as though the off-screen boundaries have moved "inside" the phone screen as well. I want to avoid this. How?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload