如何渲染 2d 横向卷轴游戏 [英] How to render a 2d side-scroller game
问题描述
我不太明白我想渲染侧卷轴的方式?当我的角色移动时,我怎么知道要渲染什么?我应该为角色使用什么样的定位?我希望我的问题很清楚
I do not really understand the way I'm suppose to render a side-scroller? How do I know what to render when my character move? What kind of positionning should I use for the characters? I hope my question is clear
推荐答案
我发现的最简单的方法是有一个 characterX 和 characterY 变量 [整数或浮点数,无论你想要什么] 然后有一个 cameraX 和 cameraY 变量.场景中的每个对象都在ObjectX-cameraX、ObjectY-cameraY...
The easiest way i've found to do it is have a characterX and characterY variable [integer or float, whatever you want] Then have a cameraX and cameraY variable. Every object in the scene is drawn at theObjectX-cameraX, theObjectY-cameraY...
CameraX/CameraY 由一个类似于中点的公式补间,因此最终它们将达到 playerx/playery[Cx = (Cx*99+Px)/100]
... 是的
CameraX/CameraY are tweened by a similar-to-midpoint formula so eventually they'll reach playerx/playery[Cx = (Cx*99+Px)/100]
... yeah
通过这样做,每个对象都会在舞台空间中移动,并且仅在渲染时进行转换[让您免于头痛]
By doing this, every object moves in the stage's space, and is transformed only on render [saving you from headaches]
这篇关于如何渲染 2d 横向卷轴游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!