/android/Android(LGame-0.3.2&LAE-1.1)/LGame-0.3.2(OpenGLES)/src/core/org/loon/framework/android/game/action/sprite/effect/ScrollEffect.java

http://loon-simple.googlecode.com/ · Java · 232 lines · 170 code · 36 blank · 26 comment · 19 complexity · 9c1aeb79fba6c302b06e422c3b42905b MD5 · raw file

  1. package org.loon.framework.android.game.action.sprite.effect;
  2. import org.loon.framework.android.game.action.map.Config;
  3. import org.loon.framework.android.game.action.sprite.ISprite;
  4. import org.loon.framework.android.game.core.LObject;
  5. import org.loon.framework.android.game.core.LSystem;
  6. import org.loon.framework.android.game.core.geom.RectBox;
  7. import org.loon.framework.android.game.core.graphics.opengl.GLEx;
  8. import org.loon.framework.android.game.core.graphics.opengl.LTexture;
  9. import org.loon.framework.android.game.core.timer.LTimer;
  10. /**
  11. * Copyright 2008 - 2011
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  14. * use this file except in compliance with the License. You may obtain a copy of
  15. * the License at
  16. *
  17. * http://www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  21. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  22. * License for the specific language governing permissions and limitations under
  23. * the License.
  24. *
  25. * @project loonframework
  26. * @author chenpeng
  27. * @email?ceponline@yahoo.com.cn
  28. * @version 0.1
  29. */
  30. /**
  31. * 0.3.2??????????????????(????)
  32. */
  33. public class ScrollEffect extends LObject implements ISprite {
  34. /**
  35. *
  36. */
  37. private static final long serialVersionUID = 1L;
  38. private int backgroundLoop;
  39. private int count;
  40. private int width, height;
  41. private float alpha;
  42. private LTexture texture;
  43. private boolean visible, stop;
  44. private LTimer timer;
  45. private int code;
  46. public ScrollEffect(String fileName) {
  47. this(new LTexture(fileName));
  48. }
  49. public ScrollEffect(LTexture tex2d) {
  50. this(Config.DOWN, tex2d, LSystem.screenRect);
  51. }
  52. public ScrollEffect(int d, String fileName) {
  53. this(d, new LTexture(fileName));
  54. }
  55. public ScrollEffect(int d, LTexture tex2d) {
  56. this(d, tex2d, LSystem.screenRect);
  57. }
  58. public ScrollEffect(int d, String fileName, RectBox limit) {
  59. this(d, new LTexture(fileName), limit);
  60. }
  61. public ScrollEffect(int d, LTexture tex2d, RectBox limit) {
  62. this(d, tex2d, limit.x, limit.y, limit.width, limit.height);
  63. }
  64. public ScrollEffect(int d, LTexture tex2d, float x, float y, int w, int h) {
  65. this.setLocation(x, y);
  66. this.texture = tex2d;
  67. this.width = w;
  68. this.height = h;
  69. this.count = 1;
  70. this.timer = new LTimer(10);
  71. this.visible = true;
  72. this.code = d;
  73. }
  74. public void setDelay(long delay) {
  75. timer.setDelay(delay);
  76. }
  77. public long getDelay() {
  78. return timer.getDelay();
  79. }
  80. public int getHeight() {
  81. return height;
  82. }
  83. public int getWidth() {
  84. return width;
  85. }
  86. public void update(long elapsedTime) {
  87. if (stop) {
  88. return;
  89. }
  90. if (timer.action(elapsedTime)) {
  91. switch (code) {
  92. case Config.DOWN:
  93. case Config.TDOWN:
  94. case Config.UP:
  95. case Config.TUP:
  96. this.backgroundLoop = ((backgroundLoop + count) % height);
  97. break;
  98. case Config.LEFT:
  99. case Config.RIGHT:
  100. case Config.TLEFT:
  101. case Config.TRIGHT:
  102. this.backgroundLoop = ((backgroundLoop + count) % width);
  103. break;
  104. }
  105. }
  106. }
  107. public void createUI(GLEx g) {
  108. if (!visible) {
  109. return;
  110. }
  111. if (alpha > 0 && alpha < 1) {
  112. g.setAlpha(alpha);
  113. }
  114. texture.glBegin();
  115. switch (code) {
  116. case Config.DOWN:
  117. case Config.TDOWN:
  118. for (int i = -1; i < 1; i++) {
  119. for (int j = 0; j < 1; j++) {
  120. texture.draw(x() + (j * width), y()
  121. + (i * height + backgroundLoop), width, height, 0,
  122. 0, width, height);
  123. }
  124. }
  125. break;
  126. case Config.RIGHT:
  127. case Config.TRIGHT:
  128. for (int j = -1; j < 1; j++) {
  129. for (int i = 0; i < 1; i++) {
  130. texture.draw(x() + (j * width + backgroundLoop), y()
  131. + (i * height), width, height, 0, 0, width, height);
  132. }
  133. }
  134. break;
  135. case Config.UP:
  136. case Config.TUP:
  137. for (int i = -1; i < 1; i++) {
  138. for (int j = 0; j < 1; j++) {
  139. texture.draw(x() + (j * width), y()
  140. - (i * height + backgroundLoop), width, height, 0,
  141. 0, width, height);
  142. }
  143. }
  144. break;
  145. case Config.LEFT:
  146. case Config.TLEFT:
  147. for (int j = -1; j < 1; j++) {
  148. for (int i = 0; i < 1; i++) {
  149. texture.draw(x() - (j * width + backgroundLoop), y()
  150. + (i * height), width, height, 0, 0, width, height);
  151. }
  152. }
  153. break;
  154. }
  155. texture.glEnd();
  156. if (alpha > 0 && alpha < 1) {
  157. g.setAlpha(1f);
  158. }
  159. }
  160. public int getCount() {
  161. return count;
  162. }
  163. public void setCount(int count) {
  164. this.count = count;
  165. }
  166. public void setAlpha(float alpha) {
  167. this.alpha = alpha;
  168. }
  169. public float getAlpha() {
  170. return alpha;
  171. }
  172. public LTexture getBitmap() {
  173. return texture;
  174. }
  175. public boolean isStop() {
  176. return stop;
  177. }
  178. public void setStop(boolean stop) {
  179. this.stop = stop;
  180. }
  181. public RectBox getCollisionBox() {
  182. return getRect(x(), y(), width, height);
  183. }
  184. public boolean isVisible() {
  185. return visible;
  186. }
  187. public void setVisible(boolean visible) {
  188. this.visible = visible;
  189. }
  190. public void dispose() {
  191. if (texture != null) {
  192. texture.destroy();
  193. texture = null;
  194. }
  195. }
  196. }