Bin
Bin

Reputation: 43

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.

Upvotes: 0

Views: 441

Answers (1)

eBehbahani
eBehbahani

Reputation: 1564

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.

Upvotes: 1

Related Questions