Cocos2d-3.x_重力加速的使用

Cocos2d-3.x_重力加速的使用,第1张

概述#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"USING_NS_CC;class HelloWorld : public cocos2d::Layer{public: static cocos2d::Scene* createScene(); vi
#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"USING_NS_CC;class HelloWorld : public cocos2d::Layer{public:    static cocos2d::Scene* createScene();    virtual bool init();    CREATE_FUNC(HelloWorld);private:	LabelTTF *pLabel;};#endif // __HELLOWORLD_SCENE_H__
#include "HelloWorldScene.h"Scene* HelloWorld::createScene(){    auto scene = Scene::create();    auto layer = HelloWorld::create();    scene->addChild(layer);    return scene;}bool HelloWorld::init(){    if ( !Layer::init() )    {        return false;    }        Size visibleSize = Director::getInstance()->getVisibleSize();    Vec2 origin = Director::getInstance()->getVisibleOrigin();	pLabel = LabelTTF::create("HelloWorld","Fonts/Arial.ttf",30);	pLabel->setposition(visibleSize.wIDth / 2.0,visibleSize.height / 2.0);	this->addChild(pLabel);	// 在Cocos2d-3.x中,大量的回调函数封装成C++11中的闭包函数进行回调,在3.x中,重力加速的回调也是如此	auto Listener = EventListeneracceleration::create([](acceleration *a,Event *)	{		log("x:%f,y:%f,z:%f",a->x,a->y,a->z);	});	Director::getInstance()->getEventdispatcher()->addEventListenerWithSceneGraPHPriority(Listener,this);    return true;}
总结

以上是内存溢出为你收集整理的Cocos2d-3.x_重力加速的使用全部内容,希望文章能够帮你解决Cocos2d-3.x_重力加速的使用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1054185.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存