0
제목은 모두 말한다. 현재는 캐릭터가 수직으로 움직이는 게임을 만들고 ParallaxBackground 엔티티가 동일한 작업을 수행하도록하고 싶습니다. 어떻게이 작업을 수행 할 수 있습니까?ParallaxBackground에서 엔티티를 AndEngine에서 세로로 움직이게하려면 어떻게해야합니까?
제목은 모두 말한다. 현재는 캐릭터가 수직으로 움직이는 게임을 만들고 ParallaxBackground 엔티티가 동일한 작업을 수행하도록하고 싶습니다. 어떻게이 작업을 수행 할 수 있습니까?ParallaxBackground에서 엔티티를 AndEngine에서 세로로 움직이게하려면 어떻게해야합니까?
이렇게하는 한 가지 방법은 ParallaxBackground 클래스에 포함 된 ParallaxEntity를 확장하고 수직으로 이동하는 것입니다. 여기에 어떻게 수행했는지 보여주는 몇 가지 코드가 있습니다. 기본적으로 x 좌표의 변경 사항을 y 좌표로 바꿉니다. 나는 AndEngine의 현재 버전에 그것을 적용했다. 이전 버전을 목표로했던 코드의 원래 버전은 here이다.
import org.andengine.engine.camera.Camera;
import org.andengine.entity.IEntity;
import org.andengine.entity.scene.background.ParallaxBackground.ParallaxEntity;
import org.andengine.opengl.util.GLState;
public class VerticalParallaxEntity extends ParallaxEntity
{
final float mParallaxFactor;
final IEntity mEntity;
public VerticalParallaxEntity(final float pParallaxFactor, final IEntity pEntity)
{
super(pParallaxFactor, pEntity);
this.mParallaxFactor = pParallaxFactor;
this.mEntity = pEntity;
}
public void onDraw(final GLState pGLState, final Camera pCamera, final float pParallaxValue)
{
pGLState.pushModelViewGLMatrix();
{
final float cameraHeight = pCamera.getHeight();
final float entityHeightScaled = this.mEntity.getHeight() * this.mEntity.getScaleY();
float baseOffset = (pParallaxValue * this.mParallaxFactor) % entityHeightScaled;
while(baseOffset > 0) {
baseOffset -= entityHeightScaled;
}
pGLState.translateModelViewGLMatrixf(0, baseOffset, 0);
float currentMaxY = baseOffset;
do
{
this.mEntity.onDraw(pGLState, pCamera);
pGLState.translateModelViewGLMatrixf(0, entityHeightScaled, 0);
currentMaxY += entityHeightScaled;
} while(currentMaxY < cameraHeight);
}
pGLState.popModelViewGLMatrix();
}
}