pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

libgdx 中的多個(gè)攝像頭(在其他框架中可能類似)

Multiple cameras in libgdx ( probably similar in other frameworks )(libgdx 中的多個(gè)攝像頭(在其他框架中可能類似))
本文介紹了libgdx 中的多個(gè)攝像頭(在其他框架中可能類似)的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我已經(jīng)嘗試解決這個(gè)問題兩天了,我已經(jīng)放棄嘗試找到現(xiàn)有的解決方案.

I have been trying to solve this problem for two days and I have given up trying to find an existing solution.

我已經(jīng)開始學(xué)習(xí) libgdx 并完成了一些教程.現(xiàn)在我已經(jīng)嘗試使用我所學(xué)到的一切,創(chuàng)建一個(gè)簡(jiǎn)單的橫向滾動(dòng)游戲.現(xiàn)在,我知道有這方面的 libgdx 示例,但我還沒有找到將 Box2d 與 scene2d 和演員以及平鋪地圖相結(jié)合的示例.

I have started learning libgdx and finished a couple of tutorials. And now I have tried to use all that I have learned and create a simple side scrolling game. Now, I know that there are libgdx examples of this, but I haven't found a one that incorporates Box2d with scene2d and actors as well as tiled maps.

我的主要問題是相機(jī).

您需要一個(gè)用于舞臺(tái)的相機(jī)(據(jù)我所知,它用于 SpriteBatch 的投影矩陣傳遞給演員的 draw() 方法,如果這是錯(cuò)誤的,請(qǐng)糾正我)并且您需要一個(gè)相機(jī)用于調(diào)用 render() 方法的 TileMapRender.此外,在某些教程中,GameScreen 中有一個(gè) OrthographicCamera,可在需要時(shí)使用.

You need a camera for the Stage (which as far as I know is used for the projection matrix of the SpriteBatch passed to the method draw() at actors, if this is wrong please correct me) and you need a camera for the TileMapRender for calling the render() method. Also, in some of the tutorials there is a OrthographicCamera in the GameScreen, which is used where needed.

我嘗試將 OrthographicCamera 對(duì)象傳遞給方法,我嘗試在任何地方使用舞臺(tái)中的相機(jī)和 TileMapRenderer 中的相機(jī).前任.

I have tried to pass a OrthographicCamera object to methods, I have tried to use the camera from the Stage and the camera from the TileMapRenderer everywhere. Ex.

OrthographicCamera ocam  = new OrthographicCamera(FRUSTUM_WIDTH, FRUSTUM_HEIGHT);
stage.setCamera(ocam); // In the other cases i replace ocam with stage.getCamera() or the one i use for the tileMap Render
tileMapRenderer.render(ocam);
stage.getSpriteBatch().setProjectionMatrix(ocam.combined); // I am not sure if this is needed

我也嘗試過在各處使用不同的相機(jī).

I have also tried to use different cameras everywhere.

在嘗試了所有這些之后,我沒有注意到確切的時(shí)間發(fā)生了什么,但我會(huì)列出發(fā)生了什么:

After trying all of this I haven't noted what happens exactly when but I will list what happens :

  • 屏幕上什么都沒有(可能相機(jī)遠(yuǎn)離繪制的東西)
  • 我可以從 debugRenderer 中看到平鋪地圖和輪廓(我也使用 debugRender,但我不認(rèn)為它會(huì)干擾相機(jī)),但演員的精靈不可見(可能在屏幕外)
  • 我可以看到我應(yīng)該看到的所有內(nèi)容,但是當(dāng)我嘗試移動(dòng)應(yīng)該跟隨他的 Actor 和相機(jī)時(shí),精靈的移動(dòng)速度比身體快(綠色調(diào)試方塊).

所以我的主要問題是:

  • 我不明白當(dāng)您擁有多個(gè)攝像頭時(shí)會(huì)發(fā)生什么.通過"您在屏幕上實(shí)際看到的是哪一個(gè)?
  • 我應(yīng)該使用多臺(tái)相機(jī)嗎?如何使用?

另外,我認(rèn)為我應(yīng)該提到我正在使用 OpenGL ES 2.0.

Also, I thought that I should mention that I am using OpenGL ES 2.0.

很抱歉這個(gè)問題太長(zhǎng)了,但我想我應(yīng)該詳細(xì)描述一下,因?yàn)檫@對(duì)我來說有點(diǎn)復(fù)雜.

I am sorry for the long question, but I thought that I should describe in detail, since it's a bit complicated for me.

推薦答案

你實(shí)際上同時(shí)看透了所有這些.雖然他們可能會(huì)看到一個(gè)完全不同的世界,但他們都將他們的觀點(diǎn)呈現(xiàn)在屏幕上.您可以使用多臺(tái)相機(jī),也可以只使用一臺(tái).如果您只使用一個(gè),則需要確保在繪制 TiledMap、使用 Actors 的舞臺(tái)以及可能用于可選的 Box2DDebugRenderer 之間正確更新投影矩陣.

You actually see through all of them at the same time. They might look at a completely different world though, but all of them render their point of view to the screen. You can use several cameras, or just one. If you use only one you need to make sure that you update the projection matrix correctly, between drawing the TiledMap, your Stage with Actors and maybe for the optional Box2DDebugRenderer.

我會(huì)為 Box2DDebugRenderer 使用額外的攝像頭,因?yàn)槟院罂梢暂p松地將其丟棄.我假設(shè)您使用轉(zhuǎn)換因子將米轉(zhuǎn)換為像素,反之亦然.1:1的比例不會(huì)很好.我總是使用介于 1m=16px 和 1m=128px 之間的東西.

I'd use an extra Camera for the Box2DDebugRenderer, because you can easily throw it away later. I assume you use a conversion factor to convert meters to pixels and the other way around. Having a 1:1 ratio wouldnt be very good. I always used something between 1m=16px and 1m=128px.

所以你以這種方式初始化它,并將它用于調(diào)試渲染器:

So you initialize it this way, and use that one for your debugging renderer:

OrthographicCamera physicsDebugCam = new OrthographicCamera(Gdx.graphics.getWidth() / Constants.PIXEL_PER_METER, Gdx.graphics.getHeight() / Constants.PIXEL_PER_METER);

對(duì)于您的 TiledMapRenderer,您也可以使用額外的攝像頭,但該攝像頭僅適用于屏幕坐標(biāo),因此無需轉(zhuǎn)換:

For your TiledMapRenderer you may use an extra camera as well, but that one will work in screen-coordinates only, so no conversion:

OrthographicCamera tiledMapCam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

TiledMap 將始終在 (0, 0) 處呈現(xiàn).所以你需要使用相機(jī)在地圖上四處走動(dòng).它可能會(huì)跟隨一個(gè)主體,因此您可以通過以下方式對(duì)其進(jìn)行更新:

The TiledMap will always be rendered at (0, 0). So you need to use the camera to move around on the map. It will probably follow a body, so you can update it via:

tiledMapCam.position.set(body.getPosition().x * Constants.PIXELS_PER_METER, body.getPosition().y * Constants.PIXELS_PER_METER)

或者如果它跟隨一個(gè)演員:

Or in case it follows an Actor:

tiledMapCam.position.set(actor.getX(), actor.getY())

我實(shí)際上還沒有將scene2d 與Box2D 一起使用,因?yàn)槲也恍枰c我的游戲?qū)ο筮M(jìn)行太多交互.您需要在這里實(shí)現(xiàn)一個(gè)自定義的 PhysicsActor,它擴(kuò)展了 Actor 并通過將 body 作為屬性來構(gòu)建從 scene2d 到 Box2D 的橋梁.它必須在每個(gè)更新步驟中基于 Body 設(shè)置 Actor 的位置、旋轉(zhuǎn)等.但在這里你有幾個(gè)選擇.您可以重復(fù)使用 tiledMapCam 并在屏幕坐標(biāo)中工作.在這種情況下,您需要始終記住在更新 actor 時(shí)與 Constants.PIXELS_PER_METER 相乘.或者您將使用具有相同視口的另一個(gè)攝像頭,例如physicsDebugCam.在這種情況下,不需要轉(zhuǎn)換,但我不確定這是否會(huì)干擾某些特定于場(chǎng)景的東西.

I actually haven't used scene2d together with Box2D yet, because I didn't need to interact very much with my game objects. You need to implement a custom PhysicsActor here, which extends Actor and builds the bridge from scene2d to Box2D by having a body as a property. It will have to set the Actors position, rotation etc based on the Body at every update-step. But here you have several options. You may re-use the tiledMapCam and work in screen-coordinates. In this case you need to always remember to multiply with Constants.PIXELS_PER_METER when you update your actor. Or you will use another cam with the same viewport like the physicsDebugCam. In this case no conversion is needed, but I'm not sure if this might interfere with some scene2d-specific things.

對(duì)于 ParallaxBackground,您也可以使用另一個(gè)攝像頭,對(duì)于 UI,您可以再次使用另一個(gè)舞臺(tái)和另一個(gè)攝像頭...或者通過正確重置它們來重復(fù)使用其他攝像頭.這是您的選擇,但我認(rèn)為幾個(gè)相機(jī)不會(huì)對(duì)性能產(chǎn)生太大影響.更少的重置和轉(zhuǎn)換甚至可能會(huì)改善它.

For a ParallaxBackground you may use another camera as well, for UI you can use another stage and another camera again... or reuse others by resetting them correctly. It's your choice but I think several cameras do not influence performance much. Less resetting and conversions might even improve it.

設(shè)置完所有內(nèi)容后,您只需渲染所有內(nèi)容,使用正確的相機(jī)并將每個(gè)層"/視圖"渲染在彼此之上.首先是 ParallaxBackground,然后是 Tiledmap,然后是 Entity-Stage,然后是 Box2DDebugging 視圖,然后是 UI-stage.

After everything is setup, you just need to render everything, using the correct cameras and render every "layer"/"view" on top of each other. First a ParallaxBackground, then your Tiledmap, then your Entity-Stage, then your Box2DDebugging view, then your UI-stage.

一般記得在更改相機(jī)的任何內(nèi)容后調(diào)用 spriteBatch.setProjectionMatrix(cam.combined); 并使用 cam.update().

In general remember to call spriteBatch.setProjectionMatrix(cam.combined); and using cam.update() after you changed anything of your camera.

這篇關(guān)于libgdx 中的多個(gè)攝像頭(在其他框架中可能類似)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Why does the android emulator camera stop unexpectedly?(為什么android模擬器相機(jī)會(huì)意外停止?)
Android camera , onPictureTaken(byte[] imgData, Camera camera) method amp; PictureCallback never called(Android camera , onPictureTaken(byte[] imgData, Camera camera) 方法 amp;PictureCallback 從未調(diào)用過) - IT屋-程序員軟件開發(fā)技
Understanding the libGDX Projection Matrix(了解 libGDX 投影矩陣)
QR code reading with camera - Android(使用相機(jī)讀取二維碼 - Android)
IP camera with OpenCv in Java(Java中帶有OpenCv的IP攝像頭)
Android mock Camera(Android 模擬相機(jī))
主站蜘蛛池模板: 煤棒机_增碳剂颗粒机_活性炭颗粒机_木炭粉成型机-巩义市老城振华机械厂 | 污水提升器,污水提升泵,地下室排水,增压泵,雨水泵,智能供排水控制器-上海智流泵业有限公司 | 吲哚菁绿衍生物-酶底物法大肠菌群检测试剂-北京和信同通科技发展有限公司 | 袋式过滤器,自清洗过滤器,保安过滤器,篮式过滤器,气体过滤器,全自动过滤器,反冲洗过滤器,管道过滤器,无锡驰业环保科技有限公司 | 环讯传媒,永康网络公司,永康网站建设,永康小程序开发制作,永康网站制作,武义网页设计,金华地区网站SEO优化推广 - 永康市环讯电子商务有限公司 | 成都APP开发-成都App定制-成都app开发公司-【未来久】 | 广州各区危化证办理_危险化学品经营许可证代办 | 针焰试验仪,灼热丝试验仪,漏电起痕试验仪,水平垂直燃烧试验仪 - 苏州亚诺天下仪器有限公司 | 截齿|煤截齿|采煤机截齿|掘进机截齿|旋挖截齿-山东卓力截齿厂家报价 | 开平机_纵剪机厂家_开平机生产厂家|诚信互赢-泰安瑞烨精工机械制造有限公司 | 接地电阻测试仪[厂家直销]_电缆故障测试仪[精准定位]_耐压测试仪-武汉南电至诚电力设备 | 合肥网络推广_合肥SEO网站优化-安徽沃龙First | 博客-悦享汽车品质生活| 大型冰雕-景区冰雕展制作公司,3D创意设计源头厂家-[赛北冰雕] | 河南档案架,档案密集架,手动密集架,河南密集架批发/报价 | 河北中仪伟创试验仪器有限公司是专业生产沥青,土工,水泥,混凝土等试验仪器的厂家,咨询电话:13373070969 | 玻璃钢罐_玻璃钢储罐_盐酸罐厂家-河北华盛节能设备有限公司 | 七维官网-水性工业漆_轨道交通涂料_钢结构漆 | 低粘度纤维素|混凝土灌浆料|有机硅憎水粉|聚羧酸减水剂-南京斯泰宝 | 营养师网,营养师考试时间,报名入口—网站首页 | 冷凝水循环试验箱-冷凝水试验箱-可编程高低温试验箱厂家-上海巨为(www.juweigroup.com) | 睿婕轻钢别墅_钢结构别墅_厂家设计施工报价 | 广州冷却塔维修厂家_冷却塔修理_凉水塔风机电机填料抢修-广东康明节能空调有限公司 | 语料库-提供经典范文,文案句子,常用文书,您的写作得力助手 | 聚氨酯催化剂K15,延迟催化剂SA-1,叔胺延迟催化剂,DBU,二甲基哌嗪,催化剂TMR-2,-聚氨酯催化剂生产厂家 | 玉米深加工机械,玉米加工设备,玉米加工机械等玉米深加工设备制造商-河南成立粮油机械有限公司 | 深圳激光打标机_激光打标机_激光焊接机_激光切割机_同体激光打标机-深圳市创想激光科技有限公司 深圳快餐店设计-餐饮设计公司-餐饮空间品牌全案设计-深圳市勤蜂装饰工程 | 磁棒电感生产厂家-电感器厂家-电感定制-贴片功率电感供应商-棒形电感生产厂家-苏州谷景电子有限公司 | 铝板冲孔网,不锈钢冲孔网,圆孔冲孔网板,鳄鱼嘴-鱼眼防滑板,盾构走道板-江拓数控冲孔网厂-河北江拓丝网有限公司 | 淄博不锈钢,淄博不锈钢管,淄博不锈钢板-山东振远合金科技有限公司 | 除尘器布袋骨架,除尘器滤袋,除尘器骨架,电磁脉冲阀膜片,卸灰阀,螺旋输送机-泊头市天润环保机械设备有限公司 | 郑州水质检测中心_井水检测_河南废气检测_河南中环嘉创检测 | 海南在线 海南一家| 青州开防盗门锁-配汽车芯片钥匙-保险箱钥匙-吉祥修锁店 | 变位机,焊接变位机,焊接变位器,小型变位机,小型焊接变位机-济南上弘机电设备有限公司 | 上海电子秤厂家,电子秤厂家价格,上海吊秤厂家,吊秤供应价格-上海佳宜电子科技有限公司 | 济南ISO9000认证咨询代理公司,ISO9001认证,CMA实验室认证,ISO/TS16949认证,服务体系认证,资产管理体系认证,SC食品生产许可证- 济南创远企业管理咨询有限公司 郑州电线电缆厂家-防火|低压|低烟无卤电缆-河南明星电缆 | 铝合金重力铸造_铝合金翻砂铸造_铝铸件厂家-东莞市铝得旺五金制品有限公司 | 铝扣板-铝方通-铝格栅-铝条扣板-铝单板幕墙-佳得利吊顶天花厂家 elisa试剂盒价格-酶联免疫试剂盒-猪elisa试剂盒-上海恒远生物科技有限公司 | 铝合金电阻-无源谐波滤波器-上海稳达电讯设备厂 | 厂房出租_厂房出售_产业园区招商_工业地产 - 中工招商网 |