This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
cn:orx:tutorials:scrolling [2010/07/07 21:36 (15 years ago)] – jtianling | cn:orx:tutorials:scrolling [2020/08/19 20:17 (5 years ago)] (current) – Old content sausage | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== 视差滚动(scrolling)教程 ====== | ||
- | |||
- | ===== 综述 ===== | ||
- | |||
- | 参看前面的教程[[cn: | ||
- | 此教程说明了如何去展示一个[[wp> | ||
- | |||
- | 正如你可以看到的,视角切换本身没有用到特别的代码。\\ | ||
- | 事实上,orx的默认2D 渲染插件将根据你在配置文件中怎么设置对象的属性来帮你设置好视差滚动。\\ | ||
- | |||
- | 默认情况下,在这个教程里,配置'' | ||
- | 这意味着当摄像机移动的时候视差滚动将在X, | ||
- | 你可以尝试设置这个值为x, | ||
- | |||
- | 除了'' | ||
- | 这个属性将用来依据对象离摄像机的距离自动的调整对象的缩放。\\ | ||
- | 摄像机视锥体越小,自动缩放将会应用的越快。\\ | ||
- | 你可以尝试将对象定位到摄像机的远& | ||
- | 你可以通过配置文件来改变视差滚动的速度(注释:摄像机移动的速度)。就像平时一样,你可以实时修改它的值并且重新读取配置。\\ | ||
- | |||
- | 正如你所能看到的,我们的update代码需要简单地移动3D空间里的摄像机就行了。\\ | ||
- | 按下方向键能把摄像机视角按照X轴和Y轴移动,按下control和alt键会让视角按照Z轴移动。\\ | ||
- | 正如前面说的,所有的视差滚动效果将会正常发生,因为所有的对象都已近被合适地处理了。((译者注:包括缩放和位置))\\ | ||
- | |||
- | 在场景里移动摄像机只需要很少的代码,而且不用去关心任何的滚动效果。((译者注:即这些效果已经自动的实现了)) | ||
- | 你对你想要有多少个滚动平面,以及哪些对象应该被滚动所影响有完全的控制。\\ | ||
- | |||
- | 最后一点与天空的显示有关。\\ | ||
- | 正如[[frame|框架教程(frame tutorial)]]里我们所看到的,我们把天空对象的frame设置为摄像机视角的一个子frame。\\ | ||
- | |||
- | 这意味着在配置文件里对天空对象位置的设置将总是相对与摄像机位置的相对值。\\ | ||
- | 换句话说,天空将总是跟随着摄像机视角。\\ | ||
- | 当我们把它的深度值设置为默认值1000时,(注释:与视锥矩形的远剪裁平面的值相同)它将会停留在背景中。\\ | ||
- | |||
- | |||
- | ===== 详细说明 ===== | ||
- | |||
- | As usual, we begin by loading our config file, creating a clock and registering our '' | ||
- | Lastly, we create our '' | ||
- | Please refer to the [[main# | ||
- | |||
- | Now let's see our '' | ||
- | |||
- | <code c> | ||
- | |||
- | orxConfig_SelectSection(" | ||
- | |||
- | orxConfig_GetVector(" | ||
- | orxVector_Mulf(& | ||
- | </ | ||
- | |||
- | Nothing really new so far.\\ | ||
- | We now need to update our camera move vector depending on the active inputs. | ||
- | |||
- | <code c> | ||
- | { | ||
- | vMove.fX += vScrollSpeed.fX; | ||
- | } | ||
- | if(orxInput_IsActive(" | ||
- | { | ||
- | vMove.fX -= vScrollSpeed.fX; | ||
- | } | ||
- | if(orxInput_IsActive(" | ||
- | { | ||
- | vMove.fY += vScrollSpeed.fY; | ||
- | } | ||
- | if(orxInput_IsActive(" | ||
- | { | ||
- | vMove.fY -= vScrollSpeed.fY; | ||
- | } | ||
- | if(orxInput_IsActive(" | ||
- | { | ||
- | vMove.fZ += vScrollSpeed.fZ; | ||
- | } | ||
- | if(orxInput_IsActive(" | ||
- | { | ||
- | vMove.fZ -= vScrollSpeed.fZ; | ||
- | }</ | ||
- | |||
- | Lastly we apply this movement to our camera. | ||
- | |||
- | <code c> | ||
- | |||
- | As stated before, there' | ||
- | Everything will be done on the config side. We simply move our camera in our '' | ||
- | |||
- | Let's have a look at the config data. First our '' | ||
- | |||
- | <code ini> | ||
- | CloudNumber = 1000 | ||
- | ScrollSpeed = (300.0, 300.0, 400.0)</ | ||
- | |||
- | As you can see, we have our '' | ||
- | The '' | ||
- | |||
- | Let's now see our cloud object. | ||
- | |||
- | <code ini> | ||
- | Texture = ../ | ||
- | Pivot = center | ||
- | |||
- | [Cloud] | ||
- | Graphic | ||
- | Position | ||
- | AutoScroll | ||
- | DepthScale | ||
- | Color = (180, 180, 180) ~ (220, 220, 220) | ||
- | Alpha = 0.0 | ||
- | Scale = 1.0 ~ 1.5 | ||
- | FXList | ||
- | |||
- | The two important attributes here are '' | ||
- | |||
- | First, the '' | ||
- | This tells on which axis the [[wp> | ||
- | The [[wp> | ||
- | The closest the object is to the camera on the Z axis, the faster it will scroll. '' | ||
- | |||
- | The '' | ||
- | The closest the object is to the camera on the Z axis, the largest it will be displayed. '' | ||
- | |||
- | Let's now have a look at our sky object. | ||
- | |||
- | <code ini> | ||
- | Texture = ../ | ||
- | Pivot = center | ||
- | |||
- | [Sky] | ||
- | Graphic | ||
- | Scale = (0.5, 0.004167, 1.0) | ||
- | Position | ||
- | ParentCamera | ||
- | |||
- | As you can see, we set a '' | ||
- | We set it's position to '' | ||
- | When having a '' | ||
- | Hence our ' | ||
- | As our '' | ||
- | In the same way, as it is 240 pixel long on Y axis, we need a scale on Y of 1/240 = 0.004167. =) | ||
- | |||
- | ===== Resources ===== | ||
- | |||
- | Source code: [[https:// | ||
- | |||
- | Config file: [[https:// | ||