OSDN Git Service

Add PathTest
authorXoppa <contact@xoppa.nl>
Tue, 12 Feb 2013 17:01:02 +0000 (18:01 +0100)
committerXoppa <contact@xoppa.nl>
Tue, 12 Feb 2013 17:01:02 +0000 (18:01 +0100)
tests/gdx-tests/src/com/badlogic/gdx/tests/PathTest.java [new file with mode: 0644]
tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTests.java

diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/PathTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/PathTest.java
new file mode 100644 (file)
index 0000000..b52007d
--- /dev/null
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright 2011 See AUTHORS file.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+package com.badlogic.gdx.tests;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.InputProcessor;
+import com.badlogic.gdx.graphics.GL10;
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g2d.Sprite;
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
+import com.badlogic.gdx.math.Bezier;
+import com.badlogic.gdx.math.Path;
+import com.badlogic.gdx.math.Vector2;
+import com.badlogic.gdx.tests.utils.GdxTest;
+import com.badlogic.gdx.utils.Array;
+
+/** @author Xoppa */
+public class PathTest extends GdxTest {
+       SpriteBatch spriteBatch;
+       Sprite obj;
+       Array<Path<Vector2>> paths = new Array<Path<Vector2>>();
+       int currentPath = 0;
+       float t;
+       float speed = 0.3f;
+       float wait = 0f;
+
+       @Override
+       public boolean needsGL20 () {
+               return false;
+       }
+       
+       @Override
+       public void create () {
+               spriteBatch = new SpriteBatch();
+               obj = new Sprite(new Texture(Gdx.files.internal("data/badlogicsmall.jpg")));
+               
+               float w = Gdx.graphics.getWidth() - obj.getWidth();
+               float h = Gdx.graphics.getHeight() - obj.getHeight();
+               
+               paths.add(new Bezier<Vector2>(new Vector2(0,0), new Vector2(w, h)));
+               paths.add(new Bezier<Vector2>(new Vector2(0,0), new Vector2(0, h), new Vector2(w, h)));
+               paths.add(new Bezier<Vector2>(new Vector2(0,0), new Vector2(w, 0), new Vector2(0, h), new Vector2(w, h)));
+               
+               Gdx.input.setInputProcessor(this);
+       }
+       
+       final Vector2 tmpV = new Vector2();
+       @Override
+       public void render () {
+               GL10 gl = Gdx.graphics.getGL10();
+               gl.glClearColor(0.7f, 0.7f, 0.7f, 1);
+               gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
+               
+               if (wait > 0)
+                       wait -= Gdx.graphics.getDeltaTime();
+               else {
+                       t += speed * Gdx.graphics.getDeltaTime();
+                       while (t >= 1f) {
+                               currentPath = (currentPath + 1) % paths.size;
+                               t -= 1f;
+                       }
+                       
+                       paths.get(currentPath).valueAt(tmpV, t);
+                       obj.setPosition(tmpV.x, tmpV.y);
+               }
+               
+               spriteBatch.begin();
+               obj.draw(spriteBatch);
+               spriteBatch.end();
+       }
+       
+       @Override
+       public boolean touchUp (int screenX, int screenY, int pointer, int button) {
+               t = paths.get(currentPath).approximate(tmpV.set(screenX, Gdx.graphics.getHeight()-screenY));
+               paths.get(currentPath).valueAt(tmpV, t);
+               obj.setPosition(tmpV.x, tmpV.y);
+               wait = 2f;
+               return super.touchUp(screenX, screenY, pointer, button);
+       }
+}
index 2f3ff94..ffb9cd2 100644 (file)
@@ -73,7 +73,7 @@ public class GdxTests {
                // SoundTouchTest.class, Mpg123Test.class, WavTest.class, FreeTypeTest.class,\r
                // InternationalFontsTest.class, VorbisTest.class\r
                TextButtonTest.class, TextButtonTestGL2.class, TextureBindTest.class, SortedSpriteTest.class,\r
-               ExternalMusicTest.class, SoftKeyboardTest.class, DirtyRenderingTest.class, YDownTest.class,\r
+               ExternalMusicTest.class, SoftKeyboardTest.class, DirtyRenderingTest.class, YDownTest.class, PathTest.class,\r
                ScreenCaptureTest.class, BitmapFontTest.class, LabelScaleTest.class, GLEEDTest.class, GamepadTest.class));\r
        \r
        public static List<String> getNames () {\r