Learning Cocos2d-x for WP8(3)——文字篇
2013-03-15 10:01
369 查看
C#兄弟篇Learning Cocos2d-x for XNA(3)——文字篇
文字,是人类文明的象征。
文字显示,可用字符串或文字图片显示。
添加图片到Assets文件夹中
在Classes文件夹中添加用于测试的头文件(.h)和源文件*(.cpp)
ShowTextTest.h
在头文件中include “cocos2d.h”头文件,using 命名空间(namespace)cocos2d。
在其中声明继承Scene(场景)类和Layer(层)类
ShowTextTestScene继承CCScene,实现构造方法、虚构造方法和继承CCNode中的虚函数onEnter()。
ShowTextTestLayer继承CCLayer,实现构造方法和虚构造方法。
源码
[b]ShowTextTest.cpp[/b]
include头文件"pch.h"和"Classes\ShowTextTest.h"
ShowTextTestScene::onEnter()
在ShowTextTestScene::onEnter()方法实现将ShowTextTestLayer(Layer)实例化,并将对象添加到Scene(场景)中。
ShowTextTestLayer::ShowTextTestLayer()
在ShowTextTestLayer::ShowTextTestLayer()方法中Layer层的Label和Sprite的显示,其中Label以字符串显示Sprite通过图片显示文字。
源码
修改起始页面
打开AppDelegate.cpp,在头部include " Classes\ShowTextTest.h"。
并修改起始Scene场景,用于显示ShowTextTestScene场景。
运行显示效果
著作权声明:本文由http://www.cnblogs.com/suguoqiang 原创,欢迎转载分享。请尊重作者劳动,转载时保留该声明和作者博客链接,谢谢!
文字,是人类文明的象征。
文字显示,可用字符串或文字图片显示。
添加图片到Assets文件夹中
在Classes文件夹中添加用于测试的头文件(.h)和源文件*(.cpp)
ShowTextTest.h
在头文件中include “cocos2d.h”头文件,using 命名空间(namespace)cocos2d。
在其中声明继承Scene(场景)类和Layer(层)类
ShowTextTestScene继承CCScene,实现构造方法、虚构造方法和继承CCNode中的虚函数onEnter()。
ShowTextTestLayer继承CCLayer,实现构造方法和虚构造方法。
源码
#ifndef _SHOW_TEXT_TEST #define _SHOW_TEXT_TEST #include "cocos2d.h" using namespace cocos2d; class ShowTextTestScene:public CCScene { public: ShowTextTestScene(); ~ShowTextTestScene(); virtual void onEnter(); }; class ShowTextTestLayer:public CCLayer { public: ShowTextTestLayer(); ~ShowTextTestLayer(); }; #endif
[b]ShowTextTest.cpp[/b]
include头文件"pch.h"和"Classes\ShowTextTest.h"
ShowTextTestScene::onEnter()
在ShowTextTestScene::onEnter()方法实现将ShowTextTestLayer(Layer)实例化,并将对象添加到Scene(场景)中。
ShowTextTestLayer::ShowTextTestLayer()
在ShowTextTestLayer::ShowTextTestLayer()方法中Layer层的Label和Sprite的显示,其中Label以字符串显示Sprite通过图片显示文字。
源码
#include "pch.h" #include "Classes\ShowTextTest.h" //------------------------------------------------------------------ // // ShowTextTestLayer // //------------------------------------------------------------------ ShowTextTestLayer::ShowTextTestLayer() { //字符串显示 CCLabelTTF* label=CCLabelTTF::labelWithString("ShowTextTest","Arial",24); CCSize s=CCDirector::sharedDirector()->getWinSize(); label->setPosition(ccp(s.width/2,s.height/1.5f)); this->addChild(label); //图片显示 CCSprite* imgSGQ=CCSprite::spriteWithFile("imgSGQ.png"); imgSGQ->setPosition(ccp(s.width/2,s.height/3)); this->addChild(imgSGQ); } ShowTextTestLayer::~ShowTextTestLayer() {} //------------------------------------------------------------------ // // ShowTextTestScene // //------------------------------------------------------------------ ShowTextTestScene::ShowTextTestScene() {} ShowTextTestScene::~ShowTextTestScene() {} void ShowTextTestScene::onEnter() { CCScene::onEnter(); CCLayer* pLayer=new ShowTextTestLayer(); this->addChild(pLayer); pLayer->release(); }
修改起始页面
打开AppDelegate.cpp,在头部include " Classes\ShowTextTest.h"。
并修改起始Scene场景,用于显示ShowTextTestScene场景。
运行显示效果
著作权声明:本文由http://www.cnblogs.com/suguoqiang 原创,欢迎转载分享。请尊重作者劳动,转载时保留该声明和作者博客链接,谢谢!
相关文章推荐
- Learning Cocos2d-x for WP8(6)——场景切换和场景过渡效果
- Learning Cocos2d-x for WP8(2)——深入刨析Hello World
- Learning Cocos2d-x for WP8(9)——Sprite到哪,我做主
- Learning Cocos2d-x for WP8(2)——深入刨析Hello World
- Learning Cocos2d-x for WP8(4)——中文显示
- Learning Cocos2d-x for WP8(7)——让Sprite动起来
- [Cocos2d-x For WP8]Layer 层
- cocos2d-x for wp8 设置横竖屏
- [Cocos2d-x For WP8]Scene场景
- [Cocos2D-x For WP8]Sprite精灵
- 【Cocos2d-x for WP8 学习整理】(1)创建一个新项目
- 【Cocos2d-x for WP8 学习整理】(4)CCTableView 实现《天天爱消除》中的得分榜
- 【Cocos2d-x for WP8 学习整理】(2)Cocos2d-Html5 游戏 《Fruit Attack》 WP8移植版 开源
- [Cocos2D-x For WP8]ParallaxNode视差
- [转] cocos2d-x for WP8 v2.0 preview
- 【Cocos2d-x for WP8 学习整理】(2)Cocos2d-Html5 游戏 《Fruit Attack》 WP8移植版 开源
- [Cocos2d-x For WP8]MotionStreak拖尾效果
- 【Cocos2d-x for WP8 学习整理】(3)CCScrollView 实现捕鱼达人一样的场景选择界面
- [Cocos2D-x For WP8]Tile Map创建地图
- cocos2d-x for wp8 设置横竖屏