码迷,mamicode.com
首页 > 其他好文 > 详细

一些常用代码

时间:2014-06-25 11:45:25      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   color   get   

1.地图大于屏幕大小,对camera进行控制,并不是简单地让player一直限制在屏幕中心,而是将player限制在屏幕中间的一个矩形区域内.

 1             float rectangleWidth=GameVariables.WIDTH/3;
 2             float rectangleHeight=GameVariables.HEIGHT/3;
 3             float cameraX=stage.getCamera().position.x;
 4             float cameraY=stage.getCamera().position.y;
 5             if (cameraX > player.getCenterX()+ rectangleWidth/2) {
 6                 cameraX = player.getCenterX()+ rectangleWidth/2;
 7             }else if (cameraX < player.getCenterX()- rectangleWidth/2) {
 8                 cameraX= player.getCenterX()- rectangleWidth/2;
 9             }
10             if (cameraX-GameVariables.WIDTH/2 <0 ) {
11                 cameraX=GameVariables.WIDTH/2;
12             }else if (cameraX+GameVariables.WIDTH/2 > getMapWidth()) {
13                 cameraX= getMapWidth()- GameVariables.WIDTH/2;
14             }
15             
16             if (cameraY > player.getCenterY() +rectangleHeight/2) {
17                 cameraY = player.getCenterY() +rectangleHeight/2;
18             }else if (cameraY < player.getCenterY() - rectangleHeight/2) {
19                 cameraY = player.getCenterY() - rectangleHeight/2;
20             }
21             if (cameraY-GameVariables.HEIGHT/2<0) {
22                 cameraY=GameVariables.HEIGHT/2;
23             }
24             if (cameraY+GameVariables.HEIGHT/2>getMapHeight()) {
25                 cameraY=getMapHeight()-GameVariables.HEIGHT/2;
26             }
27             stage.getCamera().position.set(cameraX, cameraY, 0);

2.

一些常用代码,布布扣,bubuko.com

一些常用代码

标签:style   class   blog   code   color   get   

原文地址:http://www.cnblogs.com/simon5678/p/3807199.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!