自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

解析Cocos2D中坐標(biāo)系問(wèn)題

移動(dòng)開發(fā) iOS 游戲開發(fā)
初學(xué)OpenglES紋理的時(shí)候,用Quarze2D讀取的圖片在貼在OpenglES坐標(biāo)系里圖片是上下顛倒的,原因就是坐標(biāo)系的不同造成的。

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

最近在學(xué)習(xí)Cocos2D的時(shí)候,用它的API進(jìn)行渲染到紋理的時(shí)候也出現(xiàn)了上下顛倒的情況。

具體是這樣發(fā)生的。首先我進(jìn)行渲染到紋理的功能,偽代碼如下:

  1. // 1: Create new CCRenderTexture     
  2.    CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:textureSize height:textureSize];    
  3.        
  4.    // 2: Call CCRenderTexture:begin     
  5.    [rt beginWithClear:bgColor.r g:bgColor.g b:bgColor.b a:bgColor.a];    
  6.    // 3: Draw all you want here with OpenglES     
  7.    // 4: Call CCRenderTexture:end     
  8.    [rt end];    
  9.        
  10.    // 5: Create a new Sprite from the texture     
  11.    CCSprite *renderSprite [CCSprite spriteWithTexture:rt.sprite.texture];    
  12.  // 1: Create new CCRenderTexture  
  13.     CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:textureSize height:textureSize];  
  14.       
  15.     // 2: Call CCRenderTexture:begin  
  16.     [rt beginWithClear:bgColor.r g:bgColor.g b:bgColor.b a:bgColor.a];  
  17.     // 3: Draw all you want here with OpenglES  
  18.     // 4: Call CCRenderTexture:end  
  19.     [rt end];  
  20.       
  21.     // 5: Create a new Sprite from the texture  
  22.     CCSprite *renderSprite [CCSprite spriteWithTexture:rt.sprite.texture];  

然后我用第五步生成的精靈加到場(chǎng)景中,發(fā)現(xiàn)圖是上下倒立的。因?yàn)槲以诘谌街形沂遣捎玫氖?strong>openglES的坐標(biāo)系,如果我用Quarze2D坐標(biāo)系的方式去繪制,結(jié)果就是正確的。

還有一種解決辦法,就是

  1. renderSprite.flipY = YES

發(fā)生這種問(wèn)題的具體原因不太清楚,只有看看cocos2d具體實(shí)現(xiàn)了。

小結(jié):解析Cocos2D坐標(biāo)系問(wèn)題的內(nèi)容介紹完了,希望通過(guò)本文的學(xué)習(xí),能對(duì)你有所幫助!

責(zé)任編輯:zhaolei 來(lái)源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-07-27 14:48:21

iPhone Cocos2D 坐標(biāo)

2011-08-08 15:40:47

Cocos2d

2013-05-22 14:38:44

iOS開發(fā)Cocos2d-x坐標(biāo)系統(tǒng)

2012-06-01 10:27:44

Cocos2d觸摸分發(fā)原理

2011-07-27 13:44:08

2011-07-08 14:33:02

Cocos2d iphone

2011-08-11 17:52:01

Cocos2d游戲對(duì)象

2011-08-08 11:40:42

Cocos2d CCLayer Touch

2011-08-09 16:08:58

IOS游戲Cocos2d

2011-08-11 14:32:04

iPhone游戲Cocos2dActions

2011-08-22 10:49:42

Cocos2d 開發(fā)CCLayerTouch事件

2011-08-11 14:22:47

iPhone游戲Cocos2D

2011-07-29 18:02:06

2013-05-22 15:49:46

2011-08-11 18:00:18

Cocos2d動(dòng)作Action

2011-07-27 10:13:23

Cocos2D iPhone

2011-08-09 16:25:16

Cocos2d視圖坐標(biāo)

2012-02-19 20:10:23

Cocos2d-x fCocos2dWindows Pho

2011-08-17 15:04:48

Cocos2DUIAccelerom加速計(jì)

2011-08-08 11:26:39

Cocos2d 游戲 Class類
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)