标签: cocos2d-iphone

从PList读取字典时的错误顺序

我有一个plist,我试图按顺序访问它的动画(在PList中定义),但是当我将它存储在NSDictionary中然后尝试逐个播放动画时它不是按顺序播放它们.例如,

int index = 0;
[self playAnimation:[animTypes objectAtIndex:index++]];
[self playAnimation:[animTypes objectAtIndex:index++]];
Run Code Online (Sandbox Code Playgroud)

这是我的Plist的代码:

<plist version="1.0">
<dict>
<key>Boy</key>
    <dict>
    <key>Enter</key>
    <dict>
        <key>disabled</key>
        <false/>
        <key>halfCycle</key>
        <true/>
        <key>fps</key>
        <integer>1</integer>
        <key>defaultFrame</key>
        <integer>0</integer>
        <key>useZwoptex</key>
        <true/>
        <key>frames</key>
        <array>
            <string>boy-000.png</string>
        </array>
    </dict>
    <key>Jump</key>
    <dict>
        <key>disabled</key>
        <false/>
        <key>halfCycle</key>
        <true/>
        <key>fps</key>
        <integer>13</integer>
        <key>defaultFrame</key>
        <integer>0</integer>
        <key>useZwoptex</key>
        <true/>
        <key>frames</key>
        <array>
            <string>boyjump-000.png</string>
            <string>boyjump-001.png</string>
            <string>boyjump-002.png</string>
        </array>
    </dict>
    <key>Turnaround</key>
    <dict>
        <key>disabled</key>
        <false/>
        <key>halfCycle</key>
        <true/>
        <key>fps</key>
        <integer>21</integer>
        <key>defaultFrame</key>
        <integer>0</integer>
        <key>useZwoptex</key>
        <true/>
        <key>frames</key>
        <array>
            <string>boyturnaround-000.png</string>
            <string>boyturnaround-001.png</string>
            <string>boyturnaround-002.png</string>
        </array>
    </dict>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)

Plz指导我如何按顺序加载动画?

iphone nsdictionary plist cocos2d-iphone

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

Cocos2D中的OpenFeint

是否有任何完整的教程,包含示例代码,使用OpenFeint和Cocos2D?

iphone cocos2d-iphone openfeint

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

Cocos2d - 设置设备/屏幕方向

我是cocos2d API的新手,并注意到有几种方法可以在模板中设置屏幕方向.我无法弄清楚将方向设置为LandscapeRight的正确方法,并在整个游戏中保持这种方式.如何更改方向以保持LandscapeRight?任何帮助表示赞赏.谢谢!

iphone cocos2d-iphone

1
推荐指数
2
解决办法
6755
查看次数

Cocos2d-iPhone或Sparrow首次进行2D iOS游戏开发?

我刚刚得到了基本的UIKit.我已经制作了几个个人应用程序等等,但现在我已经准备好与其他一些开发人员一起开始游戏了.这两个框架看起来都很强大,并且有很多花里胡哨的东西.

有人有偏好吗?相互比较时有利有弊吗?他们似乎都有类似的语法和性能.

iphone objective-c cocos2d-iphone sparrow-framework

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

SetAsEdge问题Cocos 2D

我正在尝试用Cocos 2D和Box 2D制作游戏

但是当我试图放一个"setAsEdge"时,它只是说我的功能不存在

我的代码:

// Define the ground body.
    b2BodyDef groundBodyDef;
    groundBodyDef.position.Set(0, 0); // bottom-left corner

    // Call the body factory which allocates memory for the ground body
    // from a pool and creates the ground box shape (also from a pool).
    // The body is also added to the world.
    groundBody = world->CreateBody(&groundBodyDef);

    // Define the ground box shape.
    b2PolygonShape groundBox;       

    // bottom
    groundBox.SetAsEdge(b2Vec2(0,FLOOR_HEIGTH/PTM_RATIO), b2Vec2(screenSize.width*2.0f/PTM_RATIO,FLOOR_HEIGTH/PTM_RATIO));
    groundBody->CreateFixture(&groundBox,0);

    // top
    groundBox.SetAsEdge(b2Vec2(0,screenSize.height/PTM_RATIO), b2Vec2(screenSize.width*2.0f/PTM_RATIO,screenSize.height/PTM_RATIO));
    groundBody->CreateFixture(&groundBox,0);

    // left
    groundBox.SetAsEdge(b2Vec2(0,screenSize.height/PTM_RATIO), b2Vec2(0,0));
    groundBody->CreateFixture(&groundBox,0);

    // right …
Run Code Online (Sandbox Code Playgroud)

iphone cocos2d-iphone

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

iPad视网膜显示器上的黑屏

我在iPad上运行一个小游戏应用程序时遇到了问题.当我在带有iPad视网膜显示屏的iOS 5.1模拟器中吃午餐时,应用程序以我的默认图像@ x2开始,然后显示图像进入黑屏.在普通iPad iOS 5.1模拟器上运行良好.Xcode只告诉我这个:

2012-04-25 14:24:26.978 AppName[83696:10a03] cocos2d: Frame interval: 1
2012-04-25 14:24:26.980 AppName[83696:10a03] cocos2d: surface size: 1536x2048
Run Code Online (Sandbox Code Playgroud)

任何的想法?谢谢


@Smamim Hossain:同样的错误我把我的Appdelegate.m

#import "cocos2d.h"

#import "AppDelegate.h"
#import "GameConfig.h"
#import "Intro.h"
#import "RootViewController.h"

@implementation AppDelegate

@synthesize window;

- (void) removeStartupFlicker
{

//#if GAME_AUTOROTATION == kGameAutorotationUIViewController


//#endif // GAME_AUTOROTATION == kGameAutorotationUIViewController  
}
- (void) applicationDidFinishLaunching:(UIApplication*)application

[director setProjection:kCCDirectorProjection2D]
{


    // Init the window
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


    if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
        [CCDirector setDirectorType:kCCDirectorTypeDefault];

    [director setProjection:kCCDirectorProjection2D]
    CCDirector *director = [CCDirector …
Run Code Online (Sandbox Code Playgroud)

cocos2d-iphone ios

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

CCAnimate和CCAnimation有什么不同?

我用cocos2d创建了一个新项目,然后创建了一个图层和一个精灵.我正在尝试将动画应用到我的精灵中,我发现了一些关于它的示例.但我不明白之间的差别CCAnimationCCAnimate,所以我还没有应用任何动画,我还没有精灵.

这两者有什么区别,它们的真正含义是什么?怎么用?

任何人都可以解释一下吗?请帮我.

iphone cocos2d-iphone ios

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

预期标识符或'('

我似乎无法压制这个错误!

我正在开发一个小项目,试图为我的应用添加背景音频.在这个错误出现之前我做得很好.

.m文件第52行出错:

//
//  UDMenuScene.m
//  iLabyrinth
//
//  Created by Rolandas Razma on 5/12/10.
//  Copyright 2010 UD7. All rights reserved.
//

#import "UDMenuScene.h"
#import "UDPickMapScene.h"
#import "SimpleAudioEngine.h"
#import "UDHelpScene.h"
#import "iLabyrinth.h"
#import "CCDirector.h"

@implementation UDMenuScene
#pragma mark -
#pragma mark NSObject

- (id)init 
{
    if( (self = [super init]) )
    {
         [self addChild:[UDMenuLayer node]];
    }
    return self;
}

@end

@implementation UDMenuLayer
#pragma mark -
#pragma mark NSObject

- (id)init {

    if( (self = [super init]) )
    { …
Run Code Online (Sandbox Code Playgroud)

objective-c identifier cocos2d-iphone ios

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

OpenGL错误0x0506在 - [CCSprite draw] 530中运行cocos2d中的divice项目?

我在模拟器上运行我的cocos2d程序.它工作正常,但当我在设备上运行时,它会抛出错误OpenGL错误0x0506 - [CCSprite draw] 530和[CCGLView swapBuffers] 283.在我的程序中我想将一个场景推送到另一个场景.那时它显示错误和下一个场景的黑屏.请帮我解决一下.我也尝试谷歌.

注意:我的应用程序不会崩溃,但绘制精灵有问题.

我的代码如下:

首先加载LoadingLayer如下.

-(void) directorDidReshapeProjection:(CCDirector*)director
{

        if ([[director runningScene] isRunning])
        {

            [[CCDirector sharedDirector] replaceScene:[HelloWorldLayer scene]];
        }
        else
        {
            [[CCDirector sharedDirector] runWithScene:[LoadingLayer scene]];
        }

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    // Create the main window
    window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


    [self.window setBackgroundColor:[UIColor whiteColor]];


    glView = [CCGLView viewWithFrame:[window_ bounds]
                                   pixelFormat:kEAGLColorFormatRGB565
                                   depthFormat:0
                            preserveBackbuffer:NO
                                    sharegroup:nil
                                 multiSampling:NO
                               numberOfSamples:0];

    director_ = (CCDirectorIOS*) [CCDirector sharedDirector];

    director_.wantsFullScreenLayout = YES;

    // Display FSP and SPF
    [director_ setDisplayStats:NO];

    // set …
Run Code Online (Sandbox Code Playgroud)

cocos2d-iphone ios

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

如何使用动态物理体以恒定速度移动精灵

直到最近我才在每次更新时更改我的精灵的x坐标,我很高兴.但是昨天当我处于debugDraw模式时,我发现在某些速度之后,物理体不会与精灵正确对齐,如下所示: 在此输入图像描述 后来我被告知,(通过cocos2d论坛中的Birkemose)将物理体从A移动到B的首选方法是对它施加冲动.但我不知道如何以这种方式实现恒速.这是我用来移动它而不应用任何冲动的代码:

-(void)update:(CCTime)delta{
    rollingHero.position=ccp(rollingHero.position.x+scrollSpeed*delta,    
                         rollingHero.position.y);
    physicsNode.position=ccp(physicsNode.position.x-scrollSpeed*delta,
                         physicsNode.position.y);
}
Run Code Online (Sandbox Code Playgroud)

因此,为了创造一种移动的感觉,我以相同的滚动速度滚动物理节点和英雄在相反的方向.我尝试了许多应用冲动的不同变体,但我从未让它以恒定速度移动.速度加快,英雄脱离屏幕.如果有人发布示例代码,我将非常感激.

physics position cocos2d-iphone spritebuilder

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