[Cocos2d-x]Cocos2d-x 3.2 学习笔记
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了[Cocos2d-x]Cocos2d-x 3.2 学习笔记,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2441字,纯文字阅读大概需要4分钟。
内容图文
获取屏幕大小(Visible)
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
打印调试(CCLOG)
CCLOG("Characters: %c%c", ‘a‘, 65);
CCLOG("Decimals: %d%ld", 1977, 650000L);
CCLOG("Preceding with blanks: %10d", 1977);
CCLOG("Preceding with zeros: %010d", 1977);
CCLOG("Some different radixes: %d%x%o%#x%#o", 100, 100, 100, 100, 100);
CCLOG("Floats: %4.2f %.0e %E", 3.1416, 3.1416, 3.1416);
CCLOG("%s","A string");
创建菜单(Menu Item)
// 创建菜单
auto menuItem = MenuItemImage::create( "MenuNormal.png",
"MenuSelected.png",
CC_CALLBACK_1(HelloWorld::menuCallback, this) );
// 设置坐标
menuItem->setPosition( Vec2(x,y) );
// 创建菜单auto menu = Menu::create(menuItem, NULL);
menu->setPosition(Vec2::ZERO);
this->addChild(menu, 1);
创建标签(Label)
auto label = LabelTTF::create("Hello World", "Arial", 24);
label->setPosition(Vec2(x,y));
this->addChild(label, 1);
添加精灵(Sprite)
auto sprite = Sprite::create("Me.jpg");
sprite->setPosition(Vec2(visibleSize.width / 2 , visibleSize.height / 2));
sprite->setAnchorPoint(Vec2(0.5,0.5));
this->addChild(sprite, 0);
精灵动画(Action)
auto actionBy = MoveBy::create(1, Point(100,100));
auto easeAction = EaseIn::create(actionBy, 2.5f);
sprite->runAction(Repeat::create(easeAction, 5));
添加监听(Listener)
auto listener1 = EventListenerTouchOneByOne::create();
listener1->onTouchBegan = [](Touch* touch, Event* event){
auto target = static_cast<Sprite*>(event->getCurrentTarget());
Point locationInNode = target->convertToNodeSpace(touch->getLocation());
Size s = target->getContentSize();
Rect rect = Rect(0, 0, s.width, s.height);
if (rect.containsPoint(locationInNode))
{
log("sprite began... x = %f, y = %f", locationInNode.x, locationInNode.y);
target->setOpacity(180);
returntrue;
}
returnfalse;
};
listener1->onTouchMoved = [](Touch* touch, Event* event){
auto target = static_cast<Sprite*>(event->getCurrentTarget());
target->setPosition(target->getPosition() + touch->getDelta());
};
listener1->onTouchEnded = [=](Touch* touch, Event* event){
auto target = static_cast<Sprite*>(event->getCurrentTarget());
if (target == sprite)
{
log("Click on the sprite");
}
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, sprite);
原文:http://blog.csdn.net/pleasecallmewhy/article/details/34931021
内容总结
以上是互联网集市为您收集整理的[Cocos2d-x]Cocos2d-x 3.2 学习笔记全部内容,希望文章能够帮你解决[Cocos2d-x]Cocos2d-x 3.2 学习笔记所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。