新聞中心
Cocos2D是以OpenglES為底層圖形庫, 所以它采用的是OpenglES的坐標(biāo)系統(tǒng),即x軸向右,y軸向上。 而蘋果的Quarze2D則使用的是不同的坐標(biāo)系統(tǒng),x軸向右,y軸向下。在初學(xué)OpenglES紋理的時(shí)候,用Quarze2D讀取的圖片在貼在OpenglES坐標(biāo)系里圖片是上下顛倒的,原因就是坐標(biāo)系的不同造成的。

成都創(chuàng)新互聯(lián)專注于企業(yè)成都全網(wǎng)營銷、網(wǎng)站重做改版、榆社網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5開發(fā)、商城網(wǎng)站定制開發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)公司、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為榆社等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
最近在學(xué)習(xí)Cocos2D的時(shí)候,用它的API進(jìn)行渲染到紋理的時(shí)候也出現(xiàn)了上下顛倒的情況。
具體是這樣發(fā)生的。首先我進(jìn)行渲染到紋理的功能,偽代碼如下:
- // 1: Create new CCRenderTexture
- CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:textureSize height:textureSize];
- // 2: Call CCRenderTexture:begin
- [rt beginWithClear:bgColor.r g:bgColor.g b:bgColor.b a:bgColor.a];
- // 3: Draw all you want here with OpenglES
- // 4: Call CCRenderTexture:end
- [rt end];
- // 5: Create a new Sprite from the texture
- CCSprite *renderSprite [CCSprite spriteWithTexture:rt.sprite.texture];
- // 1: Create new CCRenderTexture
- CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:textureSize height:textureSize];
- // 2: Call CCRenderTexture:begin
- [rt beginWithClear:bgColor.r g:bgColor.g b:bgColor.b a:bgColor.a];
- // 3: Draw all you want here with OpenglES
- // 4: Call CCRenderTexture:end
- [rt end];
- // 5: Create a new Sprite from the texture
- CCSprite *renderSprite [CCSprite spriteWithTexture:rt.sprite.texture];
然后我用第五步生成的精靈加到場景中,發(fā)現(xiàn)圖是上下倒立的。因?yàn)槲以诘谌街形沂遣捎玫氖?strong>openglES的坐標(biāo)系,如果我用Quarze2D坐標(biāo)系的方式去繪制,結(jié)果就是正確的。
還有一種解決辦法,就是
- renderSprite.flipY = YES;
發(fā)生這種問題的具體原因不太清楚,只有看看cocos2d具體實(shí)現(xiàn)了。
小結(jié):解析Cocos2D中坐標(biāo)系問題的內(nèi)容介紹完了,希望通過本文的學(xué)習(xí),能對你有所幫助!
新聞名稱:解析Cocos2D中坐標(biāo)系問題
網(wǎng)頁URL:http://fisionsoft.com.cn/article/cohhpsp.html


咨詢
建站咨詢
