简体   繁体   English

如何使用AndEngine gles1检测屏幕边界?

[英]How to detect Screen Boundary using AndEngine gles1?

I tried small game code using AndEngine gles1 in which i move sprite along screen. 我使用AndEngine gles1尝试了一些小游戏代码,其中我在屏幕上移动了精灵。 I used AnalogOnScreenControl for moving my sprite along the screen. 我使用AnalogOnScreenControl在屏幕上移动了精灵。 when i test it then sprite also move along the screen boundary means it goes top,left,right,down though the screen complete.Then i put top line as image and check collision between sprite and line but then sprite stick to that top line it doesn't move anywhere, so then i tried onAccelerometerChanged() method but it also doesn't work. 当我测试它时,精灵也会沿着屏幕边界移动,这意味着它会在屏幕完成的同时向上,向左,向右,向下移动。然后我将顶部线条作为图像并检查精灵与线条之间的碰撞,但是精灵会坚持到该顶部线条不会在任何地方移动,因此我尝试了onAccelerometerChanged()方法,但它也无法正常工作。

so, help me that how can i detect screen boundary so that sprite doesn't go beyond screen boundary. 因此,请帮助我如何检测屏幕边界,以使Sprite不会超出屏幕边界。 Is any tutorial on this then please give me link. 有关于此的任何教程,请给我链接。

Thanks in advanced. 提前致谢。

If it is anything like the Digital control then you should be overriding the method onControlChange() . 如果它类似于Digital控件,那么您应该重写onControlChange()方法。 In that method you would just need to set up something like 在那种方法中,您只需要设置类似

//As long as the sprite is in the bounds, then move the sprite
if(mSprite.getX() > 0 && mSprite.getX() + mSprite.getWidth() < CAMERA_WIDTH && 
      mSprite.getY() > 0 && mSprite.getY() + mSprite.getHeight() < CAMERA_HEIGHT){
     //Move the sprite here
 }

In essence, you want to use want to make sure that the sprite is within the bounds of the scene, which is determined by the camera you set. 本质上,您要使用想要确保子画面在场景的边界内,该场景由您设置的摄像机确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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