---
title: "UIView 中加入的cocos2d，背景透明"
author: "374016526"
date: "2015-05-11T11:54:10Z"
tags: ["cocos2d"]
categories: ["移动开发"]
slug: "uiview-cocos2d"
draft: false
lastmod: "2015-05-11T11:54:10Z"
id: 2210136
url: "https://374016526.iteye.com/blog/2210136"
---

要点是首先pixelFormat:kEAGLColorFormatRGBA8，必须有alpha层才能透明。  
然后view设置为透明  
glView.opaque = NO;  
\[director setOpenGLView:glView];  
\[self.viewController.view setBackgroundColor:\[UIColor clearColor]];  
\[self.viewController.view addSubview:glView];

在3.3 版本下，我是在项目内搜索glClearColor，把CCDirector.cpp里的默认背景色设置，改为透明。不同版本处理略有差异

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);