Cocos2d API解析之RotateWorldTest

本文介绍如何使用Cocos2d-x实现旋转动画效果,通过创建不同颜色的ColorLayer并应用旋转动作,展示了基本的节点操作及动画设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

该函数演示的是:旋转功能

 

@implementation MainLayer
-(id) init
{
    if( ! [super init] )
        return nil;
    float x,y;
   
    CGSize size = [[Director sharedDirector] winSize];
    x = size.width;
    y = size.height;
   
   //ColorLayer是实现CocosNodeRGBA的子层,他除了有Layer的所有功能之外,

   //并且有以下特征:opacity(不透明) RGB颜色
    CocosNode* blue =  [ColorLayer layerWithColor:ccc4(0,0,255,255)];
    CocosNode* red =   [ColorLayer layerWithColor:ccc4(255,0,0,255)];
    CocosNode* green = [ColorLayer layerWithColor:ccc4(0,255,0,255)];
    CocosNode* white = [ColorLayer layerWithColor:ccc4(255,255,255,255)];

    [blue setScale: 0.5f];
    //注意:x= size.width,-x -y:表示在左下角
    [blue setPosition: ccp(-x/4,-y/4)];


    //增加SpriteLayer场在blue中
    [blue addChild: [SpriteLayer node]];
    //x -y(右下角)
    [red setScale: 0.5f];
    [red setPosition: ccp(x/4,-y/4)];
    //-x y(左上角)
    [green setScale: 0.5f];
    [green setPosition: ccp(-x/4,y/4)];
    [green addChild: [TextLayer node]];

    //x y(右上角)
    [white setScale: 0.5f];
    [white setPosition: ccp(x/4,y/4)];

    [self addChild: blue z:-1];
    [self addChild: white];
    [self addChild: green];
    [self addChild: red];
   //定义旋转方法:角度为:720  时间为8秒
    Action * rot = [RotateBy actionWithDuration:8 angle:720];
   
    [blue runAction: rot];
    [red runAction: [[rot copy] autorelease]];   //完成后自动release
    [green runAction: [[rot copy] autorelease]];
    [white runAction: [[rot copy] autorelease]];
   
    return self;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值