简体   繁体   中英

How to detect Screen Boundary using AndEngine gles1?

I tried small game code using AndEngine gles1 in which i move sprite along screen. I used AnalogOnScreenControl for moving my sprite along the screen. 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.

so, help me that how can i detect screen boundary so that sprite doesn't go beyond screen boundary. 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() . 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.

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