#include "HelloWorldScene.h"
#include "MyLayer.h"
using
namespace
cocos2d;
CCScene* HelloWorld::scene()
{
CCScene * scene = NULL;
do
{
// 'scene' is an autorelease object
scene = CCScene::create();
CC_BREAK_IF(! scene);
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();
CC_BREAK_IF(! layer);
// add layer as a child to scene
scene->addChild(layer);
}
while
(0);
// return the scene
return
scene;
}
// on "init" you need to initialize your instance
bool
HelloWorld::init()
{
bool
bRet =
false
;
do
{
//
// super init first
//
CC_BREAK_IF(! CCLayer::init());
CCSize isize = CCDirector::sharedDirector()->getVisibleSize();
//定义缩小精灵
CCSprite *pSprite = CCSprite::create(
"grossinis_sister1.png"
);
pSprite->setPosition(ccp(50,isize.height / 2));
pSprite->setScale(2);
this
->addChild(pSprite);
//定义放大精灵
CCSprite *pSpriteBig = CCSprite::create(
"grossinis_sister1.png"
);
pSpriteBig->setPosition(ccp(400,isize.height / 2));
pSpriteBig ->setScale(2);
this
->addChild(pSpriteBig);
//精灵缩小动作
CCScaleTo *pScaleTo = CCScaleTo::create(3,1,1);
//精灵放大动作
CCScaleBy *pScaleBy = CCScaleBy::create(3,2,1);
pSprite->runAction(pScaleTo);
pSpriteBig->runAction(pScaleBy);
// this->addChild(nineGile);
bRet =
true
;
}
while
(0);
return
bRet;
}
void
HelloWorld::touchDown(CCObject*pObject,CCControlEvent event)
{
CCLOG(
"Touch Down"
);
}
void
HelloWorld::menuCloseCallback(CCObject* pSender)
{
// "close" menu item clicked
// CCDirector::sharedDirector()->end();
CCDirector::sharedDirector()->replaceScene(CCTransitionSlideInT::create(3.0,CMyLayer::scence()));
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#include
"HelloWorldScene.h"
#include "MyLayer.h"
using
namespace
cocos2d;
CCScene* HelloWorld::scene()
{
CCScene * scene = NULL;
do
{
// 'scene' is an autorelease object
scene = CCScene::create();
CC_BREAK_IF(! scene);
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();
CC_BREAK_IF(! layer);
// add layer as a child to scene
scene->addChild(layer);
}
while
(0);
// return the scene
return
scene;
}
// on "init" you need to initialize your instance
bool
HelloWorld::init()
{
bool
bRet =
false
;
do
{
//
// super init first
//
CC_BREAK_IF(! CCLayer::init());
CCSize isize = CCDirector::sharedDirector()->getVisibleSize();
//定义精灵
CCSprite *pSprite = CCSprite::create(
"grossinis_sister1.png"
);
pSprite->setPosition(ccp(100,isize.height / 2));
// pSprite->setScale(2);
this
->addChild(pSprite);
//定义抛物线结构体
ccBezierConfig bezier;
bezier.controlPoint_1 = ccp(50,0);
bezier.controlPoint_2 = ccp(400,250);
bezier.endPosition = ccp(3000,50);
//创建移动行为
CCBezierBy *pMoveTo = CCBezierBy::create(4,bezier);
pSprite->runAction(pMoveTo);
this
->scheduleUpdate();
bRet =
true
;
}
while
(0);
return
bRet;
}
void
HelloWorld::touchDown(CCObject*pObject,CCControlEvent event)
{
CCLOG(
"Touch Down"
);
}
void
HelloWorld::menuCloseCallback(CCObject* pSender)
{
// "close" menu item clicked
// CCDirector::sharedDirector()->end();
CCDirector::sharedDirector()->replaceScene(CCTransitionSlideInT::create(3.0,CMyLayer::scence()));
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
// on "init" you need to initialize your instance
bool
HelloWorld::init()
{
bool
bRet =
false
;
do
{
//
// super init first
//
CC_BREAK_IF(! CCLayer::init());
CCSize isize = CCDirector::sharedDirector()->getVisibleSize();
CCSprite *pSprite = CCSprite::create(
"grossinis_sister1.png"
);
pSprite->setPosition(ccp(100,isize.height / 2));
// pSprite->setScale(2);
this
->addChild(pSprite);
//定义跳跃事件
CCJumpBy *pJump = CCJumpBy::create(4,ccp(50,1),100,1);
//重复执行跳跃
CCRepeatForever *pForever = CCRepeatForever::create(pJump);
pSprite->runAction(pForever);
bRet =
true
;
}
while
(0);
return
bRet;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
// on "init" you need to initialize your instance
bool
HelloWorld::init()
{
bool
bRet =
false
;
do
{
//
// super init first
//
CC_BREAK_IF(! CCLayer::init());
CCSize isize = CCDirector::sharedDirector()->getVisibleSize();
CCSprite *pSprite = CCSprite::create(
"grossinis_sister1.png"
);
pSprite->setPosition(ccp(100,isize.height / 2));
// pSprite->setScale(2);
this
->addChild(pSprite);
//跳跃运动
CCJumpBy *pJump = CCJumpBy::create(4,ccp(50,1),100,1);
//跑运动
CCMoveBy *pMove = CCMoveBy::create(5,ccp(220,110));
//将动作组合,以NULL结束
CCAction *pAction = CCSequence::create(pJump,pMove,NULL);
//执行组合动作
pSprite->runAction(pAction);
bRet =
true
;
}
while
(0);
return
bRet;
}
|