偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

解析Cocos2D中坐標系問題

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

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

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

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

  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];  

然后我用第五步生成的精靈加到場景中,發(fā)現(xiàn)圖是上下倒立的。因為我在第三步中我是采用的是openglES的坐標系,如果我用Quarze2D坐標系的方式去繪制,結(jié)果就是正確的。

還有一種解決辦法,就是

  1. renderSprite.flipY = YES

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

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

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

2011-07-27 14:48:21

iPhone Cocos2D 坐標

2011-08-08 15:40:47

Cocos2d

2013-05-22 14:38:44

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

2011-07-27 13:44:08

2012-06-01 10:27:44

Cocos2d觸摸分發(fā)原理

2011-07-08 14:33:02

Cocos2d iphone

2011-08-11 17:52:01

Cocos2d游戲對象

2011-08-11 14:22:47

iPhone游戲Cocos2D

2011-08-08 11:40:42

Cocos2d CCLayer Touch

2011-08-09 16:08:58

IOS游戲Cocos2d

2011-08-22 10:49:42

Cocos2d 開發(fā)CCLayerTouch事件

2011-08-11 14:32:04

iPhone游戲Cocos2dActions

2013-05-22 15:49:46

2011-07-27 10:13:23

Cocos2D iPhone

2011-08-11 18:00:18

Cocos2d動作Action

2011-07-29 18:02:06

2011-08-09 16:25:16

Cocos2d視圖坐標

2011-08-17 15:04:48

Cocos2DUIAccelerom加速計

2012-02-19 20:10:23

Cocos2d-x fCocos2dWindows Pho

2011-07-20 14:04:46

Cocos2d iPhone 游戲
點贊
收藏

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