标签: cocos2d-iphone

如何使用cocos2d为sprite设置动画?

我有一个精灵,它将向右,向左和向右移动.我需要将动作添加到动画精灵,即动画精灵应跳,左右转.任何人都可以告诉我如何使用示例代码.

iphone cocos2d-iphone

0
推荐指数
1
解决办法
3068
查看次数

0
推荐指数
2
解决办法
1159
查看次数

NSTextField,难以添加吗?我认为

我在Xcode 4.2中制作了小游戏.

在我玩完所有游戏关卡后,将出现高分输入窗口.我想在这里添加NSTextField,因此玩家可以通过键盘输入他的名字.

我添加NSTextField到OpenGlView,但我无法在屏幕上看到它.这有什么关系?我也尝试添加子视图和添加NSTextField,但我得到相同的结果.

Xcode4.2,模拟器是My Mac - 32bit.

    NSView *view = [[NSView alloc] initWithFrame:NSRectFromCGRect(CGRectMake(0, 0, 480, 320))];

    [[[CCDirector sharedDirector] openGLView] addSubview:view];

    [[view layer] setZPosition:1];
//        
    NSTextField *textField = [[NSTextField alloc] initWithFrame:NSRectFromCGRect(CGRectMake(0, 0, 100, 40))];
    [view addSubview:textField];
Run Code Online (Sandbox Code Playgroud)

xcode objective-c nstextfield cocos2d-iphone xcode4.2

0
推荐指数
1
解决办法
482
查看次数

给定两个点计算给定角度的第三点?

我有一个数组最后两个CGPoints,其中包含用户绘制线条.我需要以相同的角度将线延伸到固定的距离.所以我首先在下面的代码的帮助下计算最后两点之间的角度

-(CGFloat)angleBetweenFirstPoint:(CGPoint)firstPoint ToSecondPoint:(CGPoint)secondPoint
{

CGPoint diff = ccpSub(secondPoint, firstPoint);

NSLog(@"difference point %f , %f",diff.x,diff.y);

CGFloat res = atan2(diff.y, diff.x);

/*if ( res < 0 ) 
{
    res = (0.5 * M_PI) + res;
}

if ( dx<0  && dy>0 ) {      // 2nd quadrant
    res += 0.5 * M_PI;
} else if ( dx<0 && dy<0 ) {        // 3rd quadrant
    res += M_PI;
} else if ( dx>0 && …
Run Code Online (Sandbox Code Playgroud)

math cocos2d-iphone ios

0
推荐指数
1
解决办法
2619
查看次数

Cocos2d:如何找到CCSprite的中心点?

如何找到CCSprite的中心点?

我的伪代码是:

A get sprite bounding box
B compute center point of the sprite
C move center point relative to sprite position and anchor point (this will be the center point of the sprite)
Run Code Online (Sandbox Code Playgroud)

而我的伪分辨率到目前为止是这样的:

A [sprite boundingbox] B 如何找到矩形的中心坐标? CI不知道:)

有什么建议吗?

math sprite cocos2d-iphone ios

0
推荐指数
1
解决办法
3312
查看次数

将对象设置为NSMutableDictionary且没有崩溃日志时,应用程序崩溃

我尝试为我的游戏制作一个简单的分数系统,我正在使用字典并使用NSUserDefaults保存它来存储玩家的分数.但是,当我尝试将新分数设置为现有键/值时,应用程序崩溃,没有任何控制台日志消息,并且xcode切换到不可读的汇编程序代码.我知道崩溃的地方,因为我设置了异常,它显示了它被调用的行.如果改变了什么,我也会使用cocos2d.

这是代码:

//creates key for the right level     
NSString *currentLevelString = [NSString stringWithFormat:@"Level%i",numberOfCurentLevel];


 //checking if dictionary is empty, if empty then it means the game is played for the first time
 NSMutableDictionary *dictionary = [[[NSMutableDictionary alloc]init]autorelease];
//ud is the UserDefaults

 dictionary = [ud objectForKey:@"dictionaryWithScores"];

 if ([dictionary objectForKey:@"Level5"] == nil) {
     //assigning first values for empty dictionary
     dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"ScoreList" ofType:@"plist"]];
     NSLog(@"dictionary was empty");
 }
 //NSLog(@"now dictionary shoud not be empty %@",dictionary);
 //calculating current score for this level
 double …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c nsdictionary cocos2d-iphone nsmutabledictionary

0
推荐指数
1
解决办法
1278
查看次数

为什么iPhone5上的表面尺寸错误?

我正在使用cocos2d v2.0.0和模拟器6.1.

当我在xcode中的iPhone5模拟器中编译项目时,表面大小是

cocos2d:表面尺寸:1136x640

该应用程序正常工作,适合屏幕边框1136x640,但当我在iPhone5设备上运行应用程序,我得到

cocos2d:表面尺寸:960x640

图像不再覆盖整个屏幕.

问题是什么?

screen cocos2d-iphone ios retina-display

0
推荐指数
1
解决办法
1300
查看次数

风景中的Nextpeer只有iphone游戏

我在肖像游戏中使用了Nextpeer并且工作正常.在横向游戏中使用相同的代码,但Nextpeer仪表板仍处于纵向模式.如何将Nextpeer仪表板方向更改为横向?

这是我的Nextpeer初始化代码:

-(void)initializeNextpeer:(NSDictionary *)launchOptions
{
    if([self internetConnected])
    {
        BOOL isRetina = (IS_IPAD) ? FALSE : TRUE ;

        NSDictionary* settings = [NSDictionary dictionaryWithObjectsAndKeys:

                                  // This game has no retina support - therefore we have to let the platform know
                                  [NSNumber numberWithBool:isRetina], NextpeerSettingGameSupportsRetina,
                                  // Support orientation change for the dashboard notifications
                                  [NSNumber numberWithBool:TRUE], NextpeerSettingSupportsDashboardRotation,
                                  // Support orientation change for the in game notifications
                                  [NSNumber numberWithBool:TRUE], NextpeerSettingObserveNotificationOrientationChange,
                                  //  Place the in game notifications on the bottom screen (so the current score …
Run Code Online (Sandbox Code Playgroud)

iphone landscape cocos2d-iphone nextpeer

0
推荐指数
1
解决办法
344
查看次数

游戏循环更新方法中使用的时间增量或时间戳是多少?

例如在cocos2D中:

- (void)update:(ccTime)delta
Run Code Online (Sandbox Code Playgroud)

谁能解释这些时间增量或时间戳用于什么?它们如何与游戏世界的更新相关?是因为我们不能可靠地知道fps而不应该只依赖于基于-update调用的增量属性更新?

opengl-es game-engine cocos2d-iphone runloop ios

0
推荐指数
1
解决办法
367
查看次数

使用自定义对象创建NSMutableArray的副本

我一直在寻找解决方案很长一段时间,其他线程都没有帮助.基本上,我想要完成的是创建一个自定义对象数组作为单例,将它们加载到我的级别,然后创建它们的副本,因为将操纵分配给这些对象的变量.但是当级别完成(或失败)时,我希望这些对象保持不变,以便我可以重新加载它们.

以下是我尝试过的一些事情.

- (void)spawnStartTiles {
    //where _puzzleGridTilesArray and curLevel.gridTiles are NSMutableArrays
    [_puzzleGridTilesArray removeAllObjects];
    _puzzleGridTilesArray = [curLevel.gridTiles mutableCopy];
    CCLOG(@"tile in curlevel %@", curLevel.gridTiles[0]); //want these to log DIFFERENT objects
    CCLOG(@"tile in puzzle array %@", _puzzleGridTilesArray[0]);//want these to log DIFFERENT objects
}
Run Code Online (Sandbox Code Playgroud)

以上记录了相同的对象ID.

- (void)spawnStartTiles {
    //where _puzzleGridTilesArray and curLevel.gridTiles are NSMutableArrays
    _puzzleGridTilesArray = [self cloneArray:curLevel.gridTiles];
    CCLOG(@"tile in curlevel %@", curLevel.gridTiles[0]); //want these to log DIFFERENT objects
    CCLOG(@"tile in puzzle array %@", _puzzleGridTilesArray[0]);//want these to log DIFFERENT objects
}

-(NSMutableArray*)cloneArray:(NSMutableArray *)myArray { …
Run Code Online (Sandbox Code Playgroud)

objective-c cocos2d-iphone

0
推荐指数
1
解决办法
74
查看次数