- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个cocos2d 2视图作为UISplitViewController中的详细信息视图。由于某种原因,无论是在最初还是在旋转屏幕时,它都将视图的大小调整为好像整个屏幕一样。这里是一些虚构的背景:
这是我在模拟器中运行它时的样子:
以下是所有相关文件:
Game1ViewController.h
#import
#import“cocos2d / cocos2d.h”
@class Game1Scene;
@interface Game1ViewController:UIViewController {
// Game1Scene * _scene;
}
@property(非原子,保留)Game1Scene * scene;
@结束
Game1ViewController.m
#import“cocos2d / cocos2d.h”
#import“Game1Scene.h”
#import“Game1ViewController.h”
#import“CCSpriteExtensions.h”
@implementation Game1ViewController
@synthesize scene = _scene;
-(CGRect)getRotatedBounds:(UIInterfaceOrientation)toInterfaceOrientation {
CGRect screenRect = [self.view界限];
// NSLog(@“%f,%f \ n”,[UIScreen mainScreen] .bounds.size.width,self.view.frame.size.height-88);
CGRect rect = CGRectZero;
if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
rect = screenRect;
} else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight){
rect.size = CGSizeMake(screenRect.size.height,screenRect.size.width);
}
返回矩形
}
-(void)startCocos2D {
CCDirector *导演= [CCDirector sharedDirector];
CGSize screenSize = [[CCDirector sharedDirector] winSize];
NSLog(@“\ n ========== Size =%f,%f \ n \ n”,screenSize.height,screenSize.width);
//在iPhone 4上启用高分辨率模式(Retina显示屏),并在所有其他设备上保持低分辨率
if(![director enableRetinaDisplay:YES])
CCLOG(@“不支持视网膜显示”);
NSLog(@“self.view bounds width,height:%f%f”,[self.view bounds] .size.width,[self.view bounds] .size.height);
CGRect rotationBounds = [self getRotatedBounds:[UIApplication sharedApplication] .statusBarOrientation];
CCGLView * glview = [CCGLView viewWithFrame:rotatedBounds
pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
depthFormat:0 // GL_DEPTH_COMPONENT16_OES
];
[self.view addSubview:glview];
[director setView:glview];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
self.scene = [Game1Scene nodeWithBounds:rotatedBounds];
CCScene * scene = [CCScene节点];
[场景addChild:self.scene];
[导演runWithScene:scene];
}
//加载视图后,通常通过笔尖实现viewDidLoad进行其他设置。
-(void)viewDidLoad {
self.title = @“玩Game1”;
// self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
// self.view.autoresizingMask = 1;
[super viewDidLoad];
[self startCocos2D];
}
-(BOOL)应该AutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//返回YES;
返回(interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation持续时间:(NSTimeInterval)duration
{
CGRect rotationBounds = [self getRotatedBounds:toInterfaceOrientation];
CCDirector *导演= [CCDirector sharedDirector];
CCGLView * glView = [导演视图];
float contentScaleFactor = [director contentScaleFactor];
if(contentScaleFactor!= 1){
rotationBounds.size.width * = contentScaleFactor;
rotationBounds.size.height * = contentScaleFactor;
}
glView.frame = rotationBounds;
[self.scene setBounds:rotatedBounds];
}
-(void)stopCocos2D {
CCDirector *导演= [CCDirector sharedDirector];
CCGLView * view = [导演视图];
[view removeFromSuperview];
// [导演分离];
[director stopAnimation];
[导演暂停];
// [director setOpenGLView:nil];
//杀死导演
[导演端];
}
-(void)viewDidDisappear:(BOOL)动画{
[self stopCocos2D];
[super viewDidDisappear:animated];
}
@结束
Game1Scene.h
#import
#import“cocos2d / cocos2d.h”
@interface Game1Scene:CCLayer {
CGRect bounds_;
}
+(id)nodeWithBounds:(CGRect)bounds;
-(void)setBounds:(CGRect)bounds;
@结束
Game1Scene.m
#import“Game1Scene.h”
#import“CCSpriteExtensions.h”
#import“cocos2d / CCMenuItem.h”
@interface Game1Scene( private )
-(void)startGame;
-(void)createUI;
-(id)initWithBounds:(CGRect)bounds;
@结束
@implementation Game1Scene
+(id)nodeWithBounds:(CGRect)bounds {
返回[[self alloc] initWithBounds:bounds];
}
-(void)setBounds:(CGRect)bounds {
NSLog(@“bounds.width,bounds.height:%f,%f”,bounds.size.width,bounds.size.height);
bounds_ =界限;
[self createUI];
}
-(id)initWithBounds:(CGRect)bounds {
if((self = [super init])){
srand(time(NULL));
bounds_ =界限;
[self startGame];
}
返回自我
}
-(void)createUI {
[self removeAllChildrenWithCleanup:TRUE];
//纯深紫色背景
CCSprite * background = [CCSprite spriteWithFile:@“game1-background.png”];
background.position = ccp(0,0);
background.anchorPoint = ccp(0,0);
NSLog(@“\ n === bounds =%f,%f \ n”,bounds_.size.width,bounds_.size.height);
[background resizeTo:CGSizeMake(bounds_.size.width,bounds_.size.height)];
[self addChild:background];
}
-(void)startGame {
[self createUI];
}
@结束
CCSpriteExtensions.h
/ *
CCSpriteExtensions.h
http://www.learn-cocos2d.com/tag/ccspriteextensions/
* /
#import“cocos2d / cocos2d.h”
@interface CCSprite(Xtensions)
//通过正确设置比例因子将其调整为指定的大小。
-(void)resizeTo:(CGSize)theSize;
@结束
CCSpriteExtension.m
/ *
CCSpriteExtensions.m
资料来源:http://www.learn-cocos2d.com/tag/ccspriteextensions/
* /
#import“CCSpriteExtensions.h”
@implementation CCSprite(Xtensions)
-(void)resizeTo:(CGSize)theSize
{
CGFloat newWidth = theSize.width;
CGFloat newHeight = theSize.height;
float startWidth = self.contentSize.width;
float startHeight = self.contentSize.height;
浮点数newScaleX = newWidth / startWidth;
float newScaleY = newHeight / startHeight;
self.scaleX = newScaleX;
self.scaleY = newScaleY;
}
@结束
我采用了这个问题所解释的想法:
UISplitViewController on iPad with Storyboards通过在DetailViews中创建几个Cocos2D场景。
[更新]
我更新到2.0。我的问题听起来像这样:
http://www.cocos2d-iphone.org/forum/topic/30797
最佳答案
您是否尝试过使用一些标准的UIView进行比较?
实现相同的getRotatedBounds,但不包含所有Cocos2D东西。这样,您可以确定错误是在SplitViewController / Storyboards还是在Cocos2D处理中?
这是有关Splitviewcontrollers with Storyboards.的教程
关于ios - Cocos2d View 在UISplitViewController中大小不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11024624/
我们在 RedHat 中使用 Postgres 9.2。我们有一个类似于以下的表: CREATE TABLE BULK_WI ( BULK_ID INTEGER NOT NULL, U
根据我的计算,将浮点值转换为计算机存储的二进制值(符号、指数、尾数格式),在 32 位中,1 位用于符号,8 位用于指数。 所以只剩下 23 位来表示数字。 所以我认为具有正确行为的浮点值范围仅为 0
我有一个像这样的临时表: CREATE TABLE `staging` ( `created_here_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTA
下面是我的 HTML: Fact Sheet Facilities and Administrative (F&A) Cost Agreem
我想知道为什么 .add(i, E) 是 O(n) 而 .get(i) 是 O(1)?是不是因为 n 元素在插入后必须向右移动? 最佳答案 记住大 O 表示法显示问题的数量级而不是最佳情况解决方案..
我在装有 GCC 4.8.2 的 Windows 8.1、Intel i7-3517U 64 位笔记本电脑上测试这个简单的 C++ 代码。 #include using namespace std;
我是一名优秀的程序员,十分优秀!