C++混编OC 交互编译

news/2024/7/5 19:20:46 标签: c++混编OC
首先需要将C++类中的CPP后缀名改为.mm
然后在导入oc类的头文件之前需要判断是否为IOS平台,若是则导入
对OC窗体的添加首先要获得glview 导演类的单例对象调用getOpenGLView()函数在调用getEAGLView()获得GLview窗口
之后创建一个窗体(按照oc的方法)

glview相当于根视图,将创建的窗体添加上去

话不多说,直接撸代码:

void HSpriteCPP::addView(){

    // 首先获取GLview窗口

    auto view = cocos2d::Director::getInstance()->getOpenGLView();

    auto eageview = (CCEAGLView*) view->getEAGLView();

    

    float screenWidth = Director::getInstance()->getWinSize().width;

    float screenHeight = Director::getInstance()->getWinSize().height;

    

    CGRect frame;

    frame.origin.x = 0;

    frame.origin.y = 0;

    frame.size.width = screenWidth;

    frame.size.height = screenHeight;

    

    UIView * tview = [[UIView alloc]initWithFrame:frame];

    [tview setUserInteractionEnabled:NO];

    [eageview addSubview:tview];

    

    UILabel *  label = [[UILabel alloc]init];

    label.frame = CGRectMake(0,200, 320,50);

    label.backgroundColor = [UIColor blackColor];

    label.textColor = [UIColor whiteColor];

    label.textAlignment = NSTextAlignmentCenter;

    label.textAlignment = NSTextAlignmentCenter;

    label.text = @"这是一个Label";

    [eageview addSubview:label];

      

}



http://www.niftyadmin.cn/n/1785722.html

相关文章

cocos studio 初体验 版本3.10

新建项目—>添加控件 cocos项目中需要添加头文件 #include "cocostudio/CocoStudio.h" using namespace cocostudio; #include "ui/cocosGUI.h" // 播放帧序列动画时需要使用该命名空间 using namespace cocostudio::timeline; // 通过csb文件获取…

Lua 开发环境搭建 基本语法

一、配置lua引擎包lua引擎包安装配置,首先下载lua的引擎包,这里采用的是5.3.3版本,mac环境,然后解压缩到存放的地方,尽量不要中文路径,然后运行终端,cd进入该文件src目录,输入 make …

Lua table表函数库

一部分的table函数只对其数组部分产生影响, 而另一部分则对整个table均产生影响. 下面会分开说明. table.concat(table, sep, start, end) concat是concatenate(连锁, 连接)的缩写. table.concat()函数列出参数中指定table的数组部分从start位置到end位置的所有元素, 元素间以…

lua实现ipairs、pairs的功能

ipairs只能遍历以数字为下标的,而pairs则可以遍历各种下标(包括字符串) 其中的实现都仰仗闭合函数 function dieDaiQi(t)--实现ipairs的功能 local i 0return function ()i i1if i>#t then // 检测是否超出范围return nilendretu…

cocos2d-x 屏幕适配 策略

资源分辨率:表示我们的图片的分辨率。设计分辨率:表示我们设计的分辨率。可以这么认为,如果将我们的程序放到这个分辨率的设备上,那么我们的程序将完美显示。屏幕分辨率:实际屏幕的分辨率。getVisibleSize:…

Lua 初学者需要注意的地方

实现不定参数: ...需要用一个表来接收不定参数 table表可以通过下标运算符来获取值,但是下标从1开始lua文件实现读入数据: lua文件需要有 io.read() 在控制台到文件的路径下使用lua命令 lua 文件名 即可执行此文件封装:三个权限 继承…

lua 面向对象的实现及原理

--[[function func( ... ) -- 对于不定参数的使用local args {...}for k,v in ipairs(args) doprint(v)endendfunc(1,2,"ssa",6)]]---- 面向对象实现TSprite {x 0,y 0}-- 使用点操作符,需要显示的传参数selffunction TSprite.setPosition(self,x,y)se…