1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
//GameScene.h
#include"cocos2d.h"
class
GameScene:
public
cocos2d::Layer
{
:
static
cocos2d::Scene*createScene();
virtual
bool
init();
void
menuCallback(cocos2d::Ref*pSender);
CREATE_FUNC(GameScene);
};
|
//GameScene.cpp
#include"GameScene.h"
USING_NS_CC;
cocos2d::Scene*GameScene::createScene()
{
auto
scene=Scene::create();
//创建一个场景
layer=GameScene::create();
//创建一个图层
scene->addChild(layer);
return
scene;
}
//初始化当前的图层
GameScene::init()
{
return
false
;
//获取屏幕大小
SizevisibleSize=Director::getInstance()->getVisibleSize();
//创建精灵的六种方法
//方法一
sprite1=Sprite::create(
"Flag_1.png"
);
sprite1->setPosition(Vec2(visibleSize.width*0.2,visibleSize.height*0.7));
this
->addChild(sprite1);
//方法二
sprite2=Sprite::create(
,Rect(0,48,36));
sprite2->setPosition(Vec2(visibleSize.width*0.4,visibleSize.height*0.7));
->addChild(sprite2);
//创建2D纹理
texture1=Director::getInstance()->getTextureCache()->addImage(
);
//autotexture1=TextureCache::sharedTextureCache()->addImage("Flag_1.png");//cocos2d-x3.0已移除该方法
//方法三
sprite3=Sprite::createWithTexture(texture1);
sprite3->setPosition(Vec2(visibleSize.width*0.6,visibleSize.height*0.7));
->addChild(sprite3);
//方法四
sprite4=Sprite::createWithTexture(texture1,36));
sprite4->setPosition(Vec2(visibleSize.width*0.8,visibleSize.height*0.7));
->addChild(sprite4);
//创建精灵帧
frame=SpriteFrame::create(
//方法五
sprite5=Sprite::createWithSpriteFrame(frame);
sprite5->setPosition(Vec2(visibleSize.width*0.3,visibleSize.height*0.3));
->addChild(sprite5);
////方法六
//SpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("img.plist");
//
//autosprite6=Sprite::createWithSpriteFrameName("HelloWorld.png");
//sprite6->setPosition(Vec2(visibleSize.width*0.7,visibleSize.height*0.3));
//this->addChild(sprite6);
//**************************//
//精灵常用处理操作
//设置缩放
sprite1->setScale(1.5f,1.5f);
//sprite1->setScaleX(1.5f);
//sprite1->setScaleY(1.5f);
//设置旋转,大于零顺时针旋转
sprite2->setRotation(60.0f);
//sprite2->setRotationX(60.0f);
//sprite2->setRotationY(60.0f);
//设置倾斜
sprite3->setSkewX(30.0f);
//sprite3->setSkewY(30.0f);
//设置是否可见
sprite4->setVisible(
true
);
//设置颜色
sprite1->setColor(Color3B(0,255));
//设置透明度
sprite2->setOpacity(100);
//更改图片
;
}
|
FROM:http://my.oschina.net/Jacedy/blog/301242