Skip to content

Commit 351709b

Browse files
committed
ScrollingBackground改名SpriteBackground
增加了一些功能,然后写了一个Demo,应该是蛮细致的...
1 parent fd78c2b commit 351709b

26 files changed

+1004
-191
lines changed

ScrollingBackground/code/ScrollingBackground.h

Lines changed: 0 additions & 127 deletions
This file was deleted.

ScrollingBackground/help.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "AppDelegate.h"
2+
#include "HelloWorldScene.h"
3+
4+
USING_NS_CC;
5+
6+
AppDelegate::AppDelegate() {
7+
8+
}
9+
10+
AppDelegate::~AppDelegate()
11+
{
12+
}
13+
14+
bool AppDelegate::applicationDidFinishLaunching() {
15+
// initialize director
16+
CCDirector* pDirector = CCDirector::sharedDirector();
17+
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
18+
19+
pDirector->setOpenGLView(pEGLView);
20+
21+
// turn on display FPS
22+
pDirector->setDisplayStats(false);
23+
24+
// set FPS. the default value is 1.0/60 if you don't call this
25+
pDirector->setAnimationInterval(1.0 / 60);
26+
27+
// create a scene. it's an autorelease object
28+
CCScene *pScene = HelloWorld::scene();
29+
30+
// run
31+
pDirector->runWithScene(pScene);
32+
33+
return true;
34+
}
35+
36+
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
37+
void AppDelegate::applicationDidEnterBackground() {
38+
CCDirector::sharedDirector()->stopAnimation();
39+
40+
// if you use SimpleAudioEngine, it must be pause
41+
// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
42+
}
43+
44+
// this function will be called when the app is active again
45+
void AppDelegate::applicationWillEnterForeground() {
46+
CCDirector::sharedDirector()->startAnimation();
47+
48+
// if you use SimpleAudioEngine, it must resume here
49+
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
50+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef _APP_DELEGATE_H_
2+
#define _APP_DELEGATE_H_
3+
4+
#include "cocos2d.h"
5+
6+
/**
7+
@brief The cocos2d Application.
8+
9+
The reason for implement as private inheritance is to hide some interface call by CCDirector.
10+
*/
11+
class AppDelegate : private cocos2d::CCApplication
12+
{
13+
public:
14+
AppDelegate();
15+
virtual ~AppDelegate();
16+
17+
/**
18+
@brief Implement CCDirector and CCScene init code here.
19+
@return true Initialize success, app continue.
20+
@return false Initialize failed, app terminate.
21+
*/
22+
virtual bool applicationDidFinishLaunching();
23+
24+
/**
25+
@brief The function be called when the application enter background
26+
@param the pointer of the application
27+
*/
28+
virtual void applicationDidEnterBackground();
29+
30+
/**
31+
@brief The function be called when the application enter foreground
32+
@param the pointer of the application
33+
*/
34+
virtual void applicationWillEnterForeground();
35+
};
36+
37+
#endif // _APP_DELEGATE_H_
38+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#ifndef __APPMACROS_H__
2+
#define __APPMACROS_H__
3+
4+
#include "cocos2d.h"
5+
6+
/* For demonstrating using one design resolution to match different resources,
7+
or one resource to match different design resolutions.
8+
9+
[Situation 1] Using one design resolution to match different resources.
10+
Please look into Appdelegate::applicationDidFinishLaunching.
11+
We check current device frame size to decide which resource need to be selected.
12+
So if you want to test this situation which said in title '[Situation 1]',
13+
you should change ios simulator to different device(e.g. iphone, iphone-retina3.5, iphone-retina4.0, ipad, ipad-retina),
14+
or change the window size in "proj.XXX/main.cpp" by "CCEGLView::setFrameSize" if you are using win32 or linux plaform
15+
and modify "proj.mac/AppController.mm" by changing the window rectangle.
16+
17+
[Situation 2] Using one resource to match different design resolutions.
18+
The coordinates in your codes is based on your current design resolution rather than resource size.
19+
Therefore, your design resolution could be very large and your resource size could be small.
20+
To test this, just define the marco 'TARGET_DESIGN_RESOLUTION_SIZE' to 'DESIGN_RESOLUTION_2048X1536'
21+
and open iphone simulator or create a window of 480x320 size.
22+
23+
[Note] Normally, developer just need to define one design resolution(e.g. 960x640) with one or more resources.
24+
*/
25+
26+
#define DESIGN_RESOLUTION_480X320 0
27+
#define DESIGN_RESOLUTION_1024X768 1
28+
#define DESIGN_RESOLUTION_2048X1536 2
29+
30+
/* If you want to switch design resolution, change next line */
31+
#define TARGET_DESIGN_RESOLUTION_SIZE DESIGN_RESOLUTION_480X320
32+
33+
typedef struct tagResource
34+
{
35+
cocos2d::CCSize size;
36+
char directory[100];
37+
}Resource;
38+
39+
static Resource smallResource = { cocos2d::CCSizeMake(480, 320), "iphone" };
40+
static Resource mediumResource = { cocos2d::CCSizeMake(1024, 768), "ipad" };
41+
static Resource largeResource = { cocos2d::CCSizeMake(2048, 1536), "ipadhd" };
42+
43+
#if (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_480X320)
44+
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(480, 320);
45+
#elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_1024X768)
46+
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(1024, 768);
47+
#elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_2048X1536)
48+
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(2048, 1536);
49+
#else
50+
#error unknown target design resolution!
51+
#endif
52+
53+
// The font size 24 is designed for small resolution, so we should change it to fit for current design resolution
54+
#define TITLE_FONT_SIZE (cocos2d::CCEGLView::sharedOpenGLView()->getDesignResolutionSize().width / smallResource.size.width * 24)
55+
56+
#endif /* __APPMACROS_H__ */

0 commit comments

Comments
 (0)