简体   繁体   中英

Detect the screen boundary and prevent the sprite from going beyond it in AndEngine

Currently, I am doing this

@Override
public EngineOptions onCreateEngineOptions() {
mCamera = new BoundCamera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED,
new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
mCamera.setBoundsEnabled(true);
return engineOptions;
}

But Still,in Landscape mode it went beyond screen from right side. How can restrict a sprite to leave screen?

A really shitty way of doing it is to add an invisible physics bidy so it cannot pass. Or in the sprite and override onManaged update that will allow you to check collisions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM