diff --git a/.classpath b/.classpath
index 6aed2ebfb..d57ec0251 100644
--- a/.classpath
+++ b/.classpath
@@ -1,8 +1,9 @@
-
-
+
+
+
diff --git a/.gitignore b/.gitignore
index 193211df4..04b103fc1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,13 +1,33 @@
+# System:
+Thumbs.db
+.DS_Store
+*.swp
+*~
+Desktop.ini
+
+# Version Control Systems:
+.svn
+CVS
+.hg
+.bzr
+
+# Android:
+local.properties
+proguard/**
target/**
bin/**
+obj/**
doc/**
gen/**
-.DS_Store
-Thumbs.db
gdb.setup
gdbserver
-.svn
-.hg
-local.properties
+
+# Eclipse:
.settings
-AndEngine.iml
\ No newline at end of file
+
+# IntelliJ / Android Studio:
+idea/workspace.xml
+idea/tasks.xml
+
+# Crashlytics
+res/values/com_crashlytics_export_strings.xml
\ No newline at end of file
diff --git a/AUTHORS.md b/AUTHORS.md
index 04786c3a5..391264692 100644
--- a/AUTHORS.md
+++ b/AUTHORS.md
@@ -45,6 +45,8 @@
* Daniel Epstein
* Added possibility to define scaleX/scaleY instead of just scale.
* Fixed horizontal/vertical flipping of BaseTextureRegionBuffer.
+* Arturo GutiƩrrez
+ * Added TextureMemoryLogger.
## Suggestions / Issue-Reports:
* Leandro De Brasi
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index f206a68bf..c6cad6ff4 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -4,7 +4,7 @@
android:versionCode="1"
android:versionName="1.0">
-
+
-
+
\ No newline at end of file
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 000000000..35cfa48aa
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,176 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
\ No newline at end of file
diff --git a/README.md b/README.md
index 128c9ef57..f886e7e46 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,29 @@
# AndEngine
+## Donations
+While developing AndEngine was a lot of fun, it also also consumed many(!) months of my life. It actually continues to cost me a significant amount of money to host the AndEngine forums.
+
+If you made profit using your game and can afford to spare a fraction of it to the developer of the game engine you used, I would be very grateful! =)
+
+### Bitcoin
+The easiest way of donating is via Bitcoin to the AndEngine funds wallet address:
+
+
+Bitcoin Wallet Address: ``1run6zViD16j2rP9evpayu8FqQ6mcRDqi`` 
+
+### Tip4Commit (Bitcoin)
+Tip the author (not the project itself) of the next commit to AndEngine:
+
+[](http://tip4commit.com/projects/192)
+
+### PayPal
+Donation Email: donate@andengine.org
+
+
+Thank you!
+
+/Nicolas Gramlich
+
## Building
### Eclipse
@@ -47,7 +71,7 @@ public final class BuildConfig {
* [`AndEngineScriptingExtension`][URI_AndEngineScriptingExtension]
* [`AndEngineScriptingExtensionGenerator`][URI_AndEngineScriptingExtensionGenerator]
* [`AndEngineSVGTextureRegionExtension`][URI_AndEngineSVGTextureRegionExtension]
- * [`AndEngineTexturePackerExtension`][URI_AndEngineTexturePackerExtension]
+ * [`AndEngineTexturePackerExtension`][URI_AndEngineTexturePackerExtension] (Merged into the 'GLES2-AnchorCenter' branch.)
* [`AndEngineTMXTiledMapExtension`][URI_AndEngineTMXTiledMapExtension] (Merged into the 'GLES1' branch.)
@@ -66,4 +90,4 @@ public final class BuildConfig {
[URI_AndEngineScriptingExtensionGenerator]: https://github.com/nicolasgramlich/AndEngineScriptingExtensionGenerator
[URI_AndEngineSVGTextureRegionExtension]: https://github.com/nicolasgramlich/AndEngineSVGTextureRegionExtension
[URI_AndEngineTexturePackerExtension]: https://github.com/nicolasgramlich/AndEngineTexturePackerExtension
-[URI_AndEngineTMXTiledMapExtension]: https://github.com/nicolasgramlich/AndEngineTMXTiledMapExtension
\ No newline at end of file
+[URI_AndEngineTMXTiledMapExtension]: https://github.com/nicolasgramlich/AndEngineTMXTiledMapExtension
diff --git a/build.xml b/build.xml
index e30400456..d5f276687 100644
--- a/build.xml
+++ b/build.xml
@@ -1,85 +1,76 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- /* This is typically used for code obfuscation.
- Compiled code location: ${out.classes.absolute.dir}
- If this is not done in place, override ${out.dex.input.absolute.dir} */
-
+
+
+
+
+
--->
-
-
-
+
+
+
+
+
diff --git a/checkstyle.xml b/checkstyle.xml
new file mode 100644
index 000000000..11f50a92b
--- /dev/null
+++ b/checkstyle.xml
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ext/img/badge_xlarge.png b/ext/img/badge_xlarge.png
new file mode 100644
index 000000000..733dd573a
Binary files /dev/null and b/ext/img/badge_xlarge.png differ
diff --git a/ext/libs/ant-contrib-1.0b3.jar b/ext/libs/ant-contrib-1.0b3.jar
new file mode 100644
index 000000000..062537661
Binary files /dev/null and b/ext/libs/ant-contrib-1.0b3.jar differ
diff --git a/git-rank-contributors.rb b/git-rank-contributors.rb
new file mode 100755
index 000000000..de1b612e6
--- /dev/null
+++ b/git-rank-contributors.rb
@@ -0,0 +1,60 @@
+#!/usr/bin/env ruby
+
+## git-rank-contributors: a simple script to trace through the logs and
+## rank contributors by the total size of the diffs they're responsible for.
+## A change counts twice as much as a plain addition or deletion.
+##
+## Output may or may not be suitable for inclusion in a CREDITS file.
+## Probably not without some editing, because people often commit from more
+## than one address.
+##
+## git-rank-contributors Copyright 2008 William Morgan .
+## This program is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or (at
+## your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You can find the GNU General Public License at:
+## http://www.gnu.org/licenses/
+
+class String
+ def obfuscate; gsub(/@/, " at the ").gsub(/\.(\w+)(>|$)/, ' dot \1s\2') end
+ def htmlize; gsub("&", "&").gsub("<", "<").gsub(">", ">") end
+end
+
+lines = {}
+verbose = ARGV.delete("-v")
+obfuscate = ARGV.delete("-o")
+htmlize = ARGV.delete("-h")
+
+author = nil
+state = :pre_author
+`git log -M -C -C -p --no-color`.each do |l|
+ case
+ when (state == :pre_author || state == :post_author) && l =~ /Author: (.*)$/
+ author = $1
+ state = :post_author
+ lines[author] ||= 0
+ when state == :post_author && l =~ /^\+\+\+/
+ state = :in_diff
+ when state == :in_diff && l =~ /^[\+\-]/
+ lines[author] += 1
+ when state == :in_diff && l =~ /^commit /
+ state = :pre_author
+ end
+end
+
+lines.sort_by { |a, c| -c }.each do |a, c|
+ a = a.obfuscate if obfuscate
+ a = a.htmlize if htmlize
+ if verbose
+ puts "#{a}: #{c} lines of diff"
+ else
+ puts a
+ end
+end
\ No newline at end of file
diff --git a/jni/Application.mk b/jni/Application.mk
index f47b6ee8a..1716886f7 100644
--- a/jni/Application.mk
+++ b/jni/Application.mk
@@ -1,3 +1,3 @@
-# Build both ARMv5TE and ARMv7-A and x86 machine code.
-APP_ABI := armeabi armeabi-v7a x86
-APP_STL := gnustl_shared
\ No newline at end of file
+# Build ARMv5TE, ARMv7-A, x86 and MIPS machine code.
+APP_ABI := armeabi armeabi-v7a x86 mips
+# APP_STL := gnustl_shared
\ No newline at end of file
diff --git a/jni/build.sh b/jni/build.sh
index 91790b1ba..f371ec5f2 100755
--- a/jni/build.sh
+++ b/jni/build.sh
@@ -1,15 +1,18 @@
#!/bin/bash
-NDK_DIRECTORY="/Users/ngramlich/SDKs/Android/ndk/r7b/"
-PROJECT_DIRECTORY="/Users/ngramlich/Workspace/gdk/graphic_engines/AndEngine/AndEngine/"
+NDK_DIRECTORY="/Users/ngramlich/Applications/android/ndk/r8e/"
+
+SCRIPT_DIR="$( cd "$( dirname "${0}" )" && pwd )"
+
+PROJECT_DIRECTORY=${SCRIPT_DIR}/../
# Run build:
-pushd ${PROJECT_DIRECTORY}
-${NDK_DIRECTORY}ndk-build
+pushd ${PROJECT_DIRECTORY} > /dev/null
+${NDK_DIRECTORY}ndk-build -j8
# Clean temporary files:
-# rm -rf ${PROJECT_DIRECTORY}obj
-# find . -name gdbserver -print0 | xargs -0 rm -rf
-# find . -name gdb.setup -print0 | xargs -0 rm -rf
+rm -rf ${PROJECT_DIRECTORY}obj
+find . -name gdbserver -print0 | xargs -0 rm -rf
+find . -name gdb.setup -print0 | xargs -0 rm -rf
-popd
\ No newline at end of file
+popd > /dev/null
\ No newline at end of file
diff --git a/libs/armeabi-v7a/libandengine.so b/libs/armeabi-v7a/libandengine.so
index 558d8aa29..a49438c17 100755
Binary files a/libs/armeabi-v7a/libandengine.so and b/libs/armeabi-v7a/libandengine.so differ
diff --git a/libs/armeabi/libandengine.so b/libs/armeabi/libandengine.so
index 983f54970..0892d3bfb 100755
Binary files a/libs/armeabi/libandengine.so and b/libs/armeabi/libandengine.so differ
diff --git a/libs/mips/libandengine.so b/libs/mips/libandengine.so
new file mode 100755
index 000000000..958b2c826
Binary files /dev/null and b/libs/mips/libandengine.so differ
diff --git a/libs/x86/libandengine.so b/libs/x86/libandengine.so
index fc23d6226..ae62dc351 100755
Binary files a/libs/x86/libandengine.so and b/libs/x86/libandengine.so differ
diff --git a/proguard-project.txt b/proguard-project.txt
new file mode 100644
index 000000000..f2fe1559a
--- /dev/null
+++ b/proguard-project.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
diff --git a/proguard.cfg b/proguard.cfg
deleted file mode 100644
index b1cdf17b5..000000000
--- a/proguard.cfg
+++ /dev/null
@@ -1,40 +0,0 @@
--optimizationpasses 5
--dontusemixedcaseclassnames
--dontskipnonpubliclibraryclasses
--dontpreverify
--verbose
--optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-
--keep public class * extends android.app.Activity
--keep public class * extends android.app.Application
--keep public class * extends android.app.Service
--keep public class * extends android.content.BroadcastReceiver
--keep public class * extends android.content.ContentProvider
--keep public class * extends android.app.backup.BackupAgentHelper
--keep public class * extends android.preference.Preference
--keep public class com.android.vending.licensing.ILicensingService
-
--keepclasseswithmembernames class * {
- native ;
-}
-
--keepclasseswithmembers class * {
- public (android.content.Context, android.util.AttributeSet);
-}
-
--keepclasseswithmembers class * {
- public (android.content.Context, android.util.AttributeSet, int);
-}
-
--keepclassmembers class * extends android.app.Activity {
- public void *(android.view.View);
-}
-
--keepclassmembers enum * {
- public static **[] values();
- public static ** valueOf(java.lang.String);
-}
-
--keep class * implements android.os.Parcelable {
- public static final android.os.Parcelable$Creator *;
-}
diff --git a/project.properties b/project.properties
index b3dbf357e..8624e6ba8 100644
--- a/project.properties
+++ b/project.properties
@@ -11,4 +11,4 @@ android.library=true
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
-target=android-15
+target=android-17
diff --git a/src/org/andengine/AndEngine.java b/src/org/andengine/AndEngine.java
index ca986a39f..487a28dea 100644
--- a/src/org/andengine/AndEngine.java
+++ b/src/org/andengine/AndEngine.java
@@ -4,20 +4,24 @@
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
+import org.andengine.engine.options.ConfigChooserOptions;
import org.andengine.opengl.view.ConfigChooser;
import org.andengine.util.exception.DeviceNotSupportedException;
import org.andengine.util.exception.DeviceNotSupportedException.DeviceNotSupportedCause;
import org.andengine.util.system.SystemUtils;
+import android.app.ActivityManager;
+import android.content.Context;
+import android.content.pm.ConfigurationInfo;
import android.os.Build;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 14:03:59 - 19.03.2012
*/
-public class AndEngine {
+public final class AndEngine {
// ===========================================================
// Constants
// ===========================================================
@@ -30,6 +34,10 @@ public class AndEngine {
// Constructors
// ===========================================================
+ private AndEngine() {
+
+ }
+
// ===========================================================
// Getter & Setter
// ===========================================================
@@ -42,23 +50,23 @@ public class AndEngine {
// Methods
// ===========================================================
- public static boolean isDeviceSupported() {
+ public static boolean isDeviceSupported(final Context pContext) {
try {
- AndEngine.checkDeviceSupported();
+ AndEngine.checkDeviceSupported(pContext);
return true;
} catch (final DeviceNotSupportedException e) {
return false;
}
}
- public static void checkDeviceSupported() throws DeviceNotSupportedException {
+ public static void checkDeviceSupported(final Context pContext) throws DeviceNotSupportedException {
AndEngine.checkCodePathSupport();
- AndEngine.checkOpenGLSupport();
+ AndEngine.checkOpenGLSupport(pContext);
}
private static void checkCodePathSupport() throws DeviceNotSupportedException {
- if(SystemUtils.isAndroidVersionOrLower(Build.VERSION_CODES.FROYO)) {
+ if (SystemUtils.isAndroidVersionOrLower(Build.VERSION_CODES.FROYO)) {
try {
System.loadLibrary("andengine");
} catch (final UnsatisfiedLinkError e) {
@@ -67,10 +75,21 @@ private static void checkCodePathSupport() throws DeviceNotSupportedException {
}
}
- private static void checkOpenGLSupport() throws DeviceNotSupportedException {
+ private static void checkOpenGLSupport(final Context pContext) throws DeviceNotSupportedException {
+ AndEngine.checkGLES20Support(pContext);
AndEngine.checkEGLConfigChooserSupport();
}
+ private static void checkGLES20Support(final Context pContext) throws DeviceNotSupportedException {
+ final ActivityManager activityManager = (ActivityManager) pContext.getSystemService(Context.ACTIVITY_SERVICE);
+
+ final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
+
+ if (configurationInfo.reqGlEsVersion < 0x20000) {
+ throw new DeviceNotSupportedException(DeviceNotSupportedCause.GLES2_UNSUPPORTED);
+ }
+ }
+
private static void checkEGLConfigChooserSupport() throws DeviceNotSupportedException {
/* Get an EGL instance. */
final EGL10 egl = (EGL10) EGLContext.getEGL();
@@ -82,7 +101,7 @@ private static void checkEGLConfigChooserSupport() throws DeviceNotSupportedExce
final int[] version = new int[2];
egl.eglInitialize(eglDisplay, version);
- final ConfigChooser configChooser = new ConfigChooser(false); // TODO Doesn't correlate to possible multisampling request in EngineOptions...
+ final ConfigChooser configChooser = new ConfigChooser(new ConfigChooserOptions());
try {
configChooser.chooseConfig(egl, eglDisplay);
diff --git a/src/org/andengine/audio/BaseAudioEntity.java b/src/org/andengine/audio/BaseAudioEntity.java
index 7fad4f864..894973b00 100644
--- a/src/org/andengine/audio/BaseAudioEntity.java
+++ b/src/org/andengine/audio/BaseAudioEntity.java
@@ -5,7 +5,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 16:35:37 - 13.06.2010
*/
@@ -69,7 +69,7 @@ protected float getMasterVolume() throws AudioException {
// Methods for/from SuperClass/Interfaces
// ===========================================================
- protected abstract void throwOnReleased() throws AudioException ;
+ protected abstract void throwOnReleased() throws AudioException;
@Override
public float getVolume() throws AudioException {
@@ -149,7 +149,7 @@ public void release() throws AudioException {
// ===========================================================
protected void assertNotReleased() throws AudioException {
- if(this.mReleased) {
+ if (this.mReleased) {
this.throwOnReleased();
}
}
diff --git a/src/org/andengine/audio/BaseAudioManager.java b/src/org/andengine/audio/BaseAudioManager.java
index 40d3d52bf..64bc0c6e3 100644
--- a/src/org/andengine/audio/BaseAudioManager.java
+++ b/src/org/andengine/audio/BaseAudioManager.java
@@ -3,9 +3,9 @@
import java.util.ArrayList;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 18:07:02 - 13.06.2010
*/
@@ -44,7 +44,7 @@ public void setMasterVolume(final float pMasterVolume) {
this.mMasterVolume = pMasterVolume;
final ArrayList audioEntities = this.mAudioEntities;
- for(int i = audioEntities.size() - 1; i >= 0; i--) {
+ for (int i = audioEntities.size() - 1; i >= 0; i--) {
final T audioEntity = audioEntities.get(i);
audioEntity.onMasterVolumeChanged(pMasterVolume);
@@ -64,7 +64,7 @@ public boolean remove(final T pAudioEntity) {
@Override
public void releaseAll() {
final ArrayList audioEntities = this.mAudioEntities;
- for(int i = audioEntities.size() - 1; i >= 0; i--) {
+ for (int i = audioEntities.size() - 1; i >= 0; i--) {
final T audioEntity = audioEntities.get(i);
audioEntity.stop();
diff --git a/src/org/andengine/audio/IAudioEntity.java b/src/org/andengine/audio/IAudioEntity.java
index c235465df..d029522ac 100644
--- a/src/org/andengine/audio/IAudioEntity.java
+++ b/src/org/andengine/audio/IAudioEntity.java
@@ -1,9 +1,9 @@
package org.andengine.audio;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 14:53:29 - 13.06.2010
*/
diff --git a/src/org/andengine/audio/IAudioManager.java b/src/org/andengine/audio/IAudioManager.java
index c290bdc3a..0183ae0db 100644
--- a/src/org/andengine/audio/IAudioManager.java
+++ b/src/org/andengine/audio/IAudioManager.java
@@ -1,9 +1,9 @@
package org.andengine.audio;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:02:06 - 13.06.2010
*/
diff --git a/src/org/andengine/audio/exception/AudioException.java b/src/org/andengine/audio/exception/AudioException.java
index 563295d8f..d7b6b0697 100644
--- a/src/org/andengine/audio/exception/AudioException.java
+++ b/src/org/andengine/audio/exception/AudioException.java
@@ -3,7 +3,7 @@
import org.andengine.util.exception.AndEngineRuntimeException;
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 20:44:53 - 09.11.2011
diff --git a/src/org/andengine/audio/music/Music.java b/src/org/andengine/audio/music/Music.java
index 921dd5d26..fe52892a6 100644
--- a/src/org/andengine/audio/music/Music.java
+++ b/src/org/andengine/audio/music/Music.java
@@ -9,7 +9,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 14:53:12 - 13.06.2010
*/
@@ -56,7 +56,7 @@ public MediaPlayer getMediaPlayer() throws MusicReleasedException {
@Override
protected MusicManager getAudioManager() throws MusicReleasedException {
- return (MusicManager)super.getAudioManager();
+ return (MusicManager) super.getAudioManager();
}
@Override
diff --git a/src/org/andengine/audio/music/MusicFactory.java b/src/org/andengine/audio/music/MusicFactory.java
index e8feb3f15..19d419d94 100644
--- a/src/org/andengine/audio/music/MusicFactory.java
+++ b/src/org/andengine/audio/music/MusicFactory.java
@@ -1,21 +1,24 @@
package org.andengine.audio.music;
import java.io.File;
+import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
+import org.andengine.util.StreamUtils;
+
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.media.MediaPlayer;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:05:49 - 13.06.2010
*/
-public class MusicFactory {
+public final class MusicFactory {
// ===========================================================
// Constants
// ===========================================================
@@ -30,6 +33,10 @@ public class MusicFactory {
// Constructors
// ===========================================================
+ private MusicFactory() {
+
+ }
+
// ===========================================================
// Getter & Setter
// ===========================================================
@@ -38,13 +45,17 @@ public class MusicFactory {
* @param pAssetBasePath must end with '/' or have .length() == 0.
*/
public static void setAssetBasePath(final String pAssetBasePath) {
- if(pAssetBasePath.endsWith("/") || pAssetBasePath.length() == 0) {
+ if (pAssetBasePath.endsWith("/") || pAssetBasePath.length() == 0) {
MusicFactory.sAssetBasePath = pAssetBasePath;
} else {
- throw new IllegalStateException("pAssetBasePath must end with '/' or be lenght zero.");
+ throw new IllegalStateException("pAssetBasePath must end with '/' or be length zero.");
}
}
+ public static String getAssetBasePath() {
+ return MusicFactory.sAssetBasePath;
+ }
+
public static void onCreate() {
MusicFactory.setAssetBasePath("");
}
@@ -60,7 +71,10 @@ public static void onCreate() {
public static Music createMusicFromFile(final MusicManager pMusicManager, final File pFile) throws IOException {
final MediaPlayer mediaPlayer = new MediaPlayer();
- mediaPlayer.setDataSource(new FileInputStream(pFile).getFD());
+ final FileInputStream fileInputStream = new FileInputStream(pFile);
+ final FileDescriptor fileDescriptor = fileInputStream.getFD();
+ StreamUtils.close(fileInputStream);
+ mediaPlayer.setDataSource(fileDescriptor);
mediaPlayer.prepare();
final Music music = new Music(pMusicManager, mediaPlayer);
diff --git a/src/org/andengine/audio/music/MusicLibrary.java b/src/org/andengine/audio/music/MusicLibrary.java
index 1fa730dd9..b4cb17ee4 100644
--- a/src/org/andengine/audio/music/MusicLibrary.java
+++ b/src/org/andengine/audio/music/MusicLibrary.java
@@ -3,7 +3,7 @@
import org.andengine.util.adt.map.Library;
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 20:30:34 - 09.11.2011
diff --git a/src/org/andengine/audio/music/MusicManager.java b/src/org/andengine/audio/music/MusicManager.java
index 639b5338a..9d23d32fc 100644
--- a/src/org/andengine/audio/music/MusicManager.java
+++ b/src/org/andengine/audio/music/MusicManager.java
@@ -3,9 +3,9 @@
import org.andengine.audio.BaseAudioManager;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:01:23 - 13.06.2010
*/
diff --git a/src/org/andengine/audio/music/exception/MusicException.java b/src/org/andengine/audio/music/exception/MusicException.java
index ffe2617c7..751bb8fd6 100644
--- a/src/org/andengine/audio/music/exception/MusicException.java
+++ b/src/org/andengine/audio/music/exception/MusicException.java
@@ -3,7 +3,7 @@
import org.andengine.util.exception.AndEngineRuntimeException;
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 20:37:53 - 09.11.2011
diff --git a/src/org/andengine/audio/music/exception/MusicReleasedException.java b/src/org/andengine/audio/music/exception/MusicReleasedException.java
index 5ab6b2443..9ddb3f773 100644
--- a/src/org/andengine/audio/music/exception/MusicReleasedException.java
+++ b/src/org/andengine/audio/music/exception/MusicReleasedException.java
@@ -1,7 +1,7 @@
package org.andengine.audio.music.exception;
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 20:44:27 - 09.11.2011
diff --git a/src/org/andengine/audio/sound/Sound.java b/src/org/andengine/audio/sound/Sound.java
index a38cce903..1abeedbcd 100644
--- a/src/org/andengine/audio/sound/Sound.java
+++ b/src/org/andengine/audio/sound/Sound.java
@@ -8,7 +8,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 13:22:15 - 11.03.2010
*/
@@ -28,6 +28,7 @@ public class Sound extends BaseAudioEntity {
private int mLoopCount;
private float mRate = 1.0f;
+ private int mPriority = 1;
// ===========================================================
// Constructors
@@ -63,7 +64,7 @@ public void setLoopCount(final int pLoopCount) throws SoundReleasedException {
this.assertNotReleased();
this.mLoopCount = pLoopCount;
- if(this.mStreamID != 0) {
+ if (this.mStreamID != 0) {
this.getSoundPool().setLoop(this.mStreamID, pLoopCount);
}
}
@@ -76,11 +77,24 @@ public void setRate(final float pRate) throws SoundReleasedException {
this.assertNotReleased();
this.mRate = pRate;
- if(this.mStreamID != 0) {
+ if (this.mStreamID != 0) {
this.getSoundPool().setRate(this.mStreamID, pRate);
}
}
+ public int getPriority() {
+ return this.mPriority;
+ }
+
+ public void setPriority(final int pPriority) throws SoundReleasedException {
+ this.assertNotReleased();
+
+ this.mPriority = pPriority;
+ if(this.mStreamID != 0) {
+ this.getSoundPool().setPriority(this.mStreamID, pPriority);
+ }
+ }
+
private SoundPool getSoundPool() throws SoundReleasedException {
return this.getAudioManager().getSoundPool();
}
@@ -91,7 +105,7 @@ private SoundPool getSoundPool() throws SoundReleasedException {
@Override
protected SoundManager getAudioManager() throws SoundReleasedException {
- return (SoundManager)super.getAudioManager();
+ return (SoundManager) super.getAudioManager();
}
@Override
@@ -107,14 +121,14 @@ public void play() throws SoundReleasedException {
final float leftVolume = this.mLeftVolume * masterVolume;
final float rightVolume = this.mRightVolume * masterVolume;
- this.mStreamID = this.getSoundPool().play(this.mSoundID, leftVolume, rightVolume, 1, this.mLoopCount, this.mRate);
+ this.mStreamID = this.getSoundPool().play(this.mSoundID, leftVolume, rightVolume, this.mPriority, this.mLoopCount, this.mRate);
}
@Override
public void stop() throws SoundReleasedException {
super.stop();
- if(this.mStreamID != 0) {
+ if (this.mStreamID != 0) {
this.getSoundPool().stop(this.mStreamID);
}
}
@@ -123,7 +137,7 @@ public void stop() throws SoundReleasedException {
public void resume() throws SoundReleasedException {
super.resume();
- if(this.mStreamID != 0) {
+ if (this.mStreamID != 0) {
this.getSoundPool().resume(this.mStreamID);
}
}
@@ -132,7 +146,7 @@ public void resume() throws SoundReleasedException {
public void pause() throws SoundReleasedException {
super.pause();
- if(this.mStreamID != 0) {
+ if (this.mStreamID != 0) {
this.getSoundPool().pause(this.mStreamID);
}
}
@@ -161,7 +175,7 @@ public void setLooping(final boolean pLooping) throws SoundReleasedException {
public void setVolume(final float pLeftVolume, final float pRightVolume) throws SoundReleasedException {
super.setVolume(pLeftVolume, pRightVolume);
- if(this.mStreamID != 0){
+ if (this.mStreamID != 0) {
final float masterVolume = this.getMasterVolume();
final float leftVolume = this.mLeftVolume * masterVolume;
final float rightVolume = this.mRightVolume * masterVolume;
diff --git a/src/org/andengine/audio/sound/SoundFactory.java b/src/org/andengine/audio/sound/SoundFactory.java
index 0c61df51d..2943813e2 100644
--- a/src/org/andengine/audio/sound/SoundFactory.java
+++ b/src/org/andengine/audio/sound/SoundFactory.java
@@ -8,13 +8,13 @@
import android.content.res.AssetFileDescriptor;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 14:23:03 - 11.03.2010
*/
-public class SoundFactory {
+public final class SoundFactory {
// ===========================================================
// Constants
// ===========================================================
@@ -29,6 +29,10 @@ public class SoundFactory {
// Constructors
// ===========================================================
+ private SoundFactory() {
+
+ }
+
// ===========================================================
// Getter & Setter
// ===========================================================
@@ -37,13 +41,17 @@ public class SoundFactory {
* @param pAssetBasePath must end with '/' or have .length() == 0.
*/
public static void setAssetBasePath(final String pAssetBasePath) {
- if(pAssetBasePath.endsWith("/") || pAssetBasePath.length() == 0) {
+ if (pAssetBasePath.endsWith("/") || pAssetBasePath.length() == 0) {
SoundFactory.sAssetBasePath = pAssetBasePath;
} else {
- throw new IllegalStateException("pAssetBasePath must end with '/' or be lenght zero.");
+ throw new IllegalStateException("pAssetBasePath must end with '/' or be length zero.");
}
}
+ public static String getAssetBasePath() {
+ return SoundFactory.sAssetBasePath;
+ }
+
public static void onCreate() {
SoundFactory.setAssetBasePath("");
}
@@ -57,7 +65,7 @@ public static void onCreate() {
// ===========================================================
public static Sound createSoundFromPath(final SoundManager pSoundManager, final String pPath) throws IOException {
- synchronized(pSoundManager) {
+ synchronized (pSoundManager) {
final int soundID = pSoundManager.getSoundPool().load(pPath, 1);
final Sound sound = new Sound(pSoundManager, soundID);
pSoundManager.add(sound);
@@ -66,7 +74,7 @@ public static Sound createSoundFromPath(final SoundManager pSoundManager, final
}
public static Sound createSoundFromAsset(final SoundManager pSoundManager, final Context pContext, final String pAssetPath) throws IOException {
- synchronized(pSoundManager) {
+ synchronized (pSoundManager) {
final int soundID = pSoundManager.getSoundPool().load(pContext.getAssets().openFd(SoundFactory.sAssetBasePath + pAssetPath), 1);
final Sound sound = new Sound(pSoundManager, soundID);
pSoundManager.add(sound);
@@ -75,7 +83,7 @@ public static Sound createSoundFromAsset(final SoundManager pSoundManager, final
}
public static Sound createSoundFromResource(final SoundManager pSoundManager, final Context pContext, final int pSoundResID) {
- synchronized(pSoundManager) {
+ synchronized (pSoundManager) {
final int soundID = pSoundManager.getSoundPool().load(pContext, pSoundResID, 1);
final Sound sound = new Sound(pSoundManager, soundID);
pSoundManager.add(sound);
@@ -88,7 +96,7 @@ public static Sound createSoundFromFile(final SoundManager pSoundManager, final
}
public static Sound createSoundFromAssetFileDescriptor(final SoundManager pSoundManager, final AssetFileDescriptor pAssetFileDescriptor) {
- synchronized(pSoundManager) {
+ synchronized (pSoundManager) {
final int soundID = pSoundManager.getSoundPool().load(pAssetFileDescriptor, 1);
final Sound sound = new Sound(pSoundManager, soundID);
pSoundManager.add(sound);
@@ -97,7 +105,7 @@ public static Sound createSoundFromAssetFileDescriptor(final SoundManager pSound
}
public static Sound createSoundFromFileDescriptor(final SoundManager pSoundManager, final FileDescriptor pFileDescriptor, final long pOffset, final long pLength) throws IOException {
- synchronized(pSoundManager) {
+ synchronized (pSoundManager) {
final int soundID = pSoundManager.getSoundPool().load(pFileDescriptor, pOffset, pLength, 1);
final Sound sound = new Sound(pSoundManager, soundID);
pSoundManager.add(sound);
diff --git a/src/org/andengine/audio/sound/SoundLibrary.java b/src/org/andengine/audio/sound/SoundLibrary.java
index c617891bb..8c92e9e93 100644
--- a/src/org/andengine/audio/sound/SoundLibrary.java
+++ b/src/org/andengine/audio/sound/SoundLibrary.java
@@ -3,9 +3,9 @@
import org.andengine.util.adt.map.Library;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 20:41:56 - 20.08.2010
*/
diff --git a/src/org/andengine/audio/sound/SoundManager.java b/src/org/andengine/audio/sound/SoundManager.java
index 98028f710..357084447 100644
--- a/src/org/andengine/audio/sound/SoundManager.java
+++ b/src/org/andengine/audio/sound/SoundManager.java
@@ -9,9 +9,9 @@
import android.util.SparseArray;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 13:22:59 - 11.03.2010
*/
@@ -66,25 +66,25 @@ public void add(final Sound pSound) {
@Override
public boolean remove(final Sound pSound) {
final boolean removed = super.remove(pSound);
- if(removed) {
+ if (removed) {
this.mSoundMap.remove(pSound.getSoundID());
}
return removed;
}
-
+
@Override
public void releaseAll() {
super.releaseAll();
this.mSoundPool.release();
}
-
+
@Override
public synchronized void onLoadComplete(final SoundPool pSoundPool, final int pSoundID, final int pStatus) {
- if(pStatus == SoundManager.SOUND_STATUS_OK) {
+ if (pStatus == SoundManager.SOUND_STATUS_OK) {
final Sound sound = this.mSoundMap.get(pSoundID);
- if(sound == null) {
+ if (sound == null) {
throw new SoundException("Unexpected soundID: '" + pSoundID + "'.");
} else {
sound.setLoaded(true);
@@ -96,6 +96,14 @@ public synchronized void onLoadComplete(final SoundPool pSoundPool, final int pS
// Methods
// ===========================================================
+ public void onPause() {
+ this.mSoundPool.autoPause();
+ }
+
+ public void onResume() {
+ this.mSoundPool.autoResume();
+ }
+
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
diff --git a/src/org/andengine/audio/sound/exception/SoundException.java b/src/org/andengine/audio/sound/exception/SoundException.java
index a2c7c5f29..e1158ba7a 100644
--- a/src/org/andengine/audio/sound/exception/SoundException.java
+++ b/src/org/andengine/audio/sound/exception/SoundException.java
@@ -3,7 +3,7 @@
import org.andengine.util.exception.AndEngineRuntimeException;
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 20:37:53 - 09.11.2011
diff --git a/src/org/andengine/audio/sound/exception/SoundReleasedException.java b/src/org/andengine/audio/sound/exception/SoundReleasedException.java
index 4e35dc579..26fb7be9f 100644
--- a/src/org/andengine/audio/sound/exception/SoundReleasedException.java
+++ b/src/org/andengine/audio/sound/exception/SoundReleasedException.java
@@ -1,7 +1,7 @@
package org.andengine.audio.sound.exception;
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 20:44:27 - 09.11.2011
diff --git a/src/org/andengine/engine/Engine.java b/src/org/andengine/engine/Engine.java
index 3aafa8df5..6b3f385bf 100644
--- a/src/org/andengine/engine/Engine.java
+++ b/src/org/andengine/engine/Engine.java
@@ -9,6 +9,7 @@
import org.andengine.audio.music.MusicManager;
import org.andengine.audio.sound.SoundFactory;
import org.andengine.audio.sound.SoundManager;
+import org.andengine.audio.sound.exception.SoundException;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.handler.DrawHandlerList;
import org.andengine.engine.handler.IDrawHandler;
@@ -62,7 +63,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 12:21:31 - 08.03.2010
*/
@@ -107,6 +108,8 @@ public class Engine implements SensorEventListener, OnTouchListener, ITouchEvent
private Vibrator mVibrator;
+ private Display mDefaultDisplay;
+
private ILocationListener mLocationListener;
private Location mLocation;
@@ -139,7 +142,7 @@ public Engine(final EngineOptions pEngineOptions) {
/* Apply EngineOptions. */
this.mEngineOptions = pEngineOptions;
- if(this.mEngineOptions.hasEngineLock()) {
+ if (this.mEngineOptions.hasEngineLock()) {
this.mEngineLock = pEngineOptions.getEngineLock();
} else {
this.mEngineLock = new EngineLock(false);
@@ -147,31 +150,34 @@ public Engine(final EngineOptions pEngineOptions) {
this.mCamera = pEngineOptions.getCamera();
/* Touch. */
- if(this.mEngineOptions.getTouchOptions().needsMultiTouch()) {
+ if (this.mEngineOptions.getTouchOptions().needsMultiTouch()) {
this.setTouchController(new MultiTouchController());
} else {
this.setTouchController(new SingleTouchController());
}
/* Audio. */
- if(this.mEngineOptions.getAudioOptions().needsSound()) {
+ if (this.mEngineOptions.getAudioOptions().needsSound()) {
this.mSoundManager = new SoundManager(this.mEngineOptions.getAudioOptions().getSoundOptions().getMaxSimultaneousStreams());
} else {
this.mSoundManager = null;
}
- if(this.mEngineOptions.getAudioOptions().needsMusic()) {
+ if (this.mEngineOptions.getAudioOptions().needsMusic()) {
this.mMusicManager = new MusicManager();
} else {
this.mMusicManager = null;
}
/* Start the UpdateThread. */
- if(this.mEngineOptions.hasUpdateThread()) {
+ if (this.mEngineOptions.hasUpdateThread()) {
this.mUpdateThread = this.mEngineOptions.getUpdateThread();
} else {
this.mUpdateThread = new UpdateThread();
}
this.mUpdateThread.setEngine(this);
+ }
+
+ public void startUpdateThread() throws IllegalThreadStateException {
this.mUpdateThread.start();
}
@@ -184,14 +190,20 @@ public synchronized boolean isRunning() {
}
public synchronized void start() {
- if(!this.mRunning) {
+ if (!this.mRunning) {
this.mLastTick = System.nanoTime();
+ if (this.mSoundManager != null) {
+ this.mSoundManager.onResume();
+ }
this.mRunning = true;
}
}
public synchronized void stop() {
- if(this.mRunning) {
+ if (this.mRunning) {
+ if (this.mSoundManager != null) {
+ this.mSoundManager.onPause();
+ }
this.mRunning = false;
}
}
@@ -277,7 +289,7 @@ public ShaderProgramManager getShaderProgramManager() {
}
public SoundManager getSoundManager() throws IllegalStateException {
- if(this.mSoundManager != null) {
+ if (this.mSoundManager != null) {
return this.mSoundManager;
} else {
throw new IllegalStateException("To enable the SoundManager, check the EngineOptions!");
@@ -285,7 +297,7 @@ public SoundManager getSoundManager() throws IllegalStateException {
}
public MusicManager getMusicManager() throws IllegalStateException {
- if(this.mMusicManager != null) {
+ if (this.mMusicManager != null) {
return this.mMusicManager;
} else {
throw new IllegalStateException("To enable the MusicManager, check the EngineOptions!");
@@ -322,13 +334,14 @@ public void clearDrawHandlers() {
@Override
public void onAccuracyChanged(final Sensor pSensor, final int pAccuracy) {
- if(this.mRunning) {
- switch(pSensor.getType()) {
+ if (this.mRunning) {
+ final int sensorType = pSensor.getType();
+ switch (sensorType) {
case Sensor.TYPE_ACCELEROMETER:
- if(this.mAccelerationData != null) {
+ if (this.mAccelerationData != null) {
this.mAccelerationData.setAccuracy(pAccuracy);
this.mAccelerationListener.onAccelerationAccuracyChanged(this.mAccelerationData);
- } else if(this.mOrientationData != null) {
+ } else if (this.mOrientationData != null) {
this.mOrientationData.setAccelerationAccuracy(pAccuracy);
this.mOrientationListener.onOrientationAccuracyChanged(this.mOrientationData);
}
@@ -337,37 +350,46 @@ public void onAccuracyChanged(final Sensor pSensor, final int pAccuracy) {
this.mOrientationData.setMagneticFieldAccuracy(pAccuracy);
this.mOrientationListener.onOrientationAccuracyChanged(this.mOrientationData);
break;
+ default:
+ throw new IllegalArgumentException("Unexpected " + Sensor.class.getSimpleName() + " of Type: '" + sensorType + "'.");
}
}
}
@Override
public void onSensorChanged(final SensorEvent pEvent) {
- if(this.mRunning) {
- switch(pEvent.sensor.getType()) {
+ if (this.mRunning) {
+ final Sensor sensor = pEvent.sensor;
+ final int sensorType = sensor.getType();
+ switch (sensorType) {
case Sensor.TYPE_ACCELEROMETER:
- if(this.mAccelerationData != null) {
+ if (this.mAccelerationData != null) {
+ this.mAccelerationData.setDisplayRotation(this.getDisplayOrientation());
this.mAccelerationData.setValues(pEvent.values);
this.mAccelerationListener.onAccelerationChanged(this.mAccelerationData);
- } else if(this.mOrientationData != null) {
+ } else if (this.mOrientationData != null) {
+ this.mOrientationData.setDisplayRotation(this.getDisplayOrientation());
this.mOrientationData.setAccelerationValues(pEvent.values);
this.mOrientationListener.onOrientationChanged(this.mOrientationData);
}
break;
case Sensor.TYPE_MAGNETIC_FIELD:
+ this.mOrientationData.setDisplayRotation(this.getDisplayOrientation());
this.mOrientationData.setMagneticFieldValues(pEvent.values);
this.mOrientationListener.onOrientationChanged(this.mOrientationData);
break;
+ default:
+ throw new IllegalArgumentException("Unexpected " + Sensor.class.getSimpleName() + " of Type: '" + sensorType + "'.");
}
}
}
@Override
public void onLocationChanged(final Location pLocation) {
- if(this.mLocation == null) {
+ if (this.mLocation == null) {
this.mLocation = pLocation;
} else {
- if(pLocation == null) {
+ if (pLocation == null) {
this.mLocationListener.onLocationLost();
} else {
this.mLocation = pLocation;
@@ -388,7 +410,7 @@ public void onProviderEnabled(final String pProvider) {
@Override
public void onStatusChanged(final String pProvider, final int pStatus, final Bundle pExtras) {
- switch(pStatus) {
+ switch (pStatus) {
case LocationProvider.AVAILABLE:
this.mLocationListener.onLocationProviderStatusChanged(LocationProviderStatus.AVAILABLE, pExtras);
break;
@@ -398,12 +420,14 @@ public void onStatusChanged(final String pProvider, final int pStatus, final Bun
case LocationProvider.TEMPORARILY_UNAVAILABLE:
this.mLocationListener.onLocationProviderStatusChanged(LocationProviderStatus.TEMPORARILY_UNAVAILABLE, pExtras);
break;
+ default:
+ throw new IllegalArgumentException("Unexpected " + LocationProvider.class.getSimpleName() + ": '" + pStatus + "'.");
}
}
@Override
public boolean onTouch(final View pView, final MotionEvent pSurfaceMotionEvent) {
- if(this.mRunning) {
+ if (this.mRunning) {
this.mTouchController.onHandleMotionEvent(pSurfaceMotionEvent);
try {
/* Because a human cannot interact 1000x per second, we pause the UI-Thread for a little. */
@@ -419,16 +443,13 @@ public boolean onTouch(final View pView, final MotionEvent pSurfaceMotionEvent)
@Override
public boolean onTouchEvent(final TouchEvent pSurfaceTouchEvent) {
- /*
- * Let the engine determine which scene and camera this event should be
- * handled by.
- */
+ /* Let the engine determine which scene and camera this event should be handled by. */
final Scene scene = this.getSceneFromSurfaceTouchEvent(pSurfaceTouchEvent);
final Camera camera = this.getCameraFromSurfaceTouchEvent(pSurfaceTouchEvent);
- this.convertSurfaceToSceneTouchEvent(camera, pSurfaceTouchEvent);
+ this.convertSurfaceTouchEventToSceneTouchEvent(camera, pSurfaceTouchEvent);
- if(this.onTouchHUD(camera, pSurfaceTouchEvent)) {
+ if (this.onTouchHUD(camera, pSurfaceTouchEvent)) {
return true;
} else {
/* If HUD didn't handle it, Scene may handle it. */
@@ -437,7 +458,7 @@ public boolean onTouchEvent(final TouchEvent pSurfaceTouchEvent) {
}
protected boolean onTouchHUD(final Camera pCamera, final TouchEvent pSceneTouchEvent) {
- if(pCamera.hasHUD()) {
+ if (pCamera.hasHUD()) {
return pCamera.getHUD().onSceneTouchEvent(pSceneTouchEvent);
} else {
return false;
@@ -445,7 +466,7 @@ protected boolean onTouchHUD(final Camera pCamera, final TouchEvent pSceneTouchE
}
protected boolean onTouchScene(final Scene pScene, final TouchEvent pSceneTouchEvent) {
- if(pScene != null) {
+ if (pScene != null) {
return pScene.onSceneTouchEvent(pSceneTouchEvent);
} else {
return false;
@@ -464,11 +485,11 @@ public void runOnUpdateThread(final Runnable pRunnable) {
* This method is useful when you want to execute code on the {@link UpdateThread}, even though the Engine is paused.
*
* @param pRunnable the {@link Runnable} to be run on the {@link UpdateThread}.
- * @param pOnlyWhenEngineRunning if true, the execution of the {@link Runnable} will be delayed until the next time {@link Engine#onUpdateUpdateHandlers(float)} is picked up, which is when {@link Engine#isRunning()} is true.
- * if false, the execution of the {@link Runnable} will happen as soon as possible on the {@link UpdateThread}, no matter what {@link Engine#isRunning()} is.
+ * @param pOnlyWhenEngineRunning if true, the execution of the {@link Runnable} will be delayed until the next time {@link #onUpdateUpdateHandlers(float)} is picked up, which is when {@link Engine#isRunning()} is true.
+ * if false, the execution of the {@link Runnable} will happen as soon as possible on the {@link UpdateThread}, no matter what {@link #isRunning()} is.
*/
public void runOnUpdateThread(final Runnable pRunnable, final boolean pOnlyWhenEngineRunning) {
- if(pOnlyWhenEngineRunning) {
+ if (pOnlyWhenEngineRunning) {
this.mUpdateThreadRunnableHandler.postRunnable(pRunnable);
} else {
this.mUpdateThread.postRunnable(pRunnable);
@@ -478,7 +499,7 @@ public void runOnUpdateThread(final Runnable pRunnable, final boolean pOnlyWhenE
/**
* @param pRunnable the {@link Runnable} to run mutually exclusive to the {@link UpdateThread} and the GL-{@link Thread}.
* When the caller already is on the {@link UpdateThread} or the GL-{@link Thread}, the {@link Runnable} is executed immediately.
- * @see {@link Engine#getEngineLock()} to manually {@link EngineLock#lock()}/{@link EngineLock#unlock()} on, while avoiding creating a {@link Runnable}.
+ * @see {@link #getEngineLock()} to manually {@link EngineLock#lock()}/{@link EngineLock#unlock()} on, while avoiding creating a {@link Runnable}.
*/
public void runSafely(final Runnable pRunnable) {
this.mEngineLock.lock();
@@ -505,6 +526,8 @@ public void onDestroy() {
this.mUpdateThread.interrupt();
}
+ this.releaseDefaultDisplay();
+
this.mVertexBufferObjectManager.onDestroy();
this.mTextureManager.onDestroy();
this.mFontManager.onDestroy();
@@ -526,16 +549,16 @@ protected Scene getSceneFromSurfaceTouchEvent(final TouchEvent pTouchEvent) {
return this.mScene;
}
- protected void convertSurfaceToSceneTouchEvent(final Camera pCamera, final TouchEvent pSurfaceTouchEvent) {
- pCamera.convertSurfaceToSceneTouchEvent(pSurfaceTouchEvent, this.mSurfaceWidth, this.mSurfaceHeight);
+ protected void convertSurfaceTouchEventToSceneTouchEvent(final Camera pCamera, final TouchEvent pSurfaceTouchEvent) {
+ pCamera.convertSurfaceTouchEventToSceneTouchEvent(pSurfaceTouchEvent, this.mSurfaceWidth, this.mSurfaceHeight);
}
- protected void convertSceneToSurfaceTouchEvent(final Camera pCamera, final TouchEvent pSurfaceTouchEvent) {
- pCamera.convertSceneToSurfaceTouchEvent(pSurfaceTouchEvent, this.mSurfaceWidth, this.mSurfaceHeight);
+ protected void convertSceneTouchEventToSurfaceTouchEvent(final Camera pCamera, final TouchEvent pSurfaceTouchEvent) {
+ pCamera.convertSceneTouchEventToSurfaceTouchEvent(pSurfaceTouchEvent, this.mSurfaceWidth, this.mSurfaceHeight);
}
void onTickUpdate() throws InterruptedException {
- if(this.mRunning) {
+ if (this.mRunning) {
final long secondsElapsed = this.getNanosecondsElapsed();
this.mEngineLock.lock();
@@ -567,7 +590,7 @@ void onTickUpdate() throws InterruptedException {
}
private void throwOnDestroyed() throws EngineDestroyedException {
- if(this.mDestroyed) {
+ if (this.mDestroyed) {
throw new EngineDestroyedException();
}
}
@@ -584,15 +607,15 @@ public void onUpdate(final long pNanosecondsElapsed) throws InterruptedException
}
protected void onUpdateScene(final float pSecondsElapsed) {
- if(this.mScene != null) {
+ if (this.mScene != null) {
this.mScene.onUpdate(pSecondsElapsed);
}
+ this.getCamera().onUpdate(pSecondsElapsed);
}
protected void onUpdateUpdateHandlers(final float pSecondsElapsed) {
this.mUpdateThreadRunnableHandler.onUpdate(pSecondsElapsed);
this.mUpdateHandlers.onUpdate(pSecondsElapsed);
- this.getCamera().onUpdate(pSecondsElapsed);
}
protected void onUpdateDrawHandlers(final GLState pGLState, final Camera pCamera) {
@@ -620,7 +643,7 @@ public void onDrawFrame(final GLState pGLState) throws InterruptedException {
}
protected void onDrawScene(final GLState pGLState, final Camera pCamera) {
- if(this.mScene != null) {
+ if (this.mScene != null) {
this.mScene.onDraw(pGLState, pCamera);
}
@@ -639,7 +662,7 @@ public boolean enableVibrator(final Context pContext) {
}
public void vibrate(final long pMilliseconds) throws IllegalStateException {
- if(this.mVibrator != null) {
+ if (this.mVibrator != null) {
this.mVibrator.vibrate(pMilliseconds);
} else {
throw new IllegalStateException("You need to enable the Vibrator before you can use it!");
@@ -647,7 +670,7 @@ public void vibrate(final long pMilliseconds) throws IllegalStateException {
}
public void vibrate(final long[] pPattern, final int pRepeat) throws IllegalStateException {
- if(this.mVibrator != null) {
+ if (this.mVibrator != null) {
this.mVibrator.vibrate(pPattern, pRepeat);
} else {
throw new IllegalStateException("You need to enable the Vibrator before you can use it!");
@@ -671,7 +694,7 @@ public void disableLocationSensor(final Context pContext) {
}
/**
- * @see {@link Engine#enableAccelerationSensor(Context, IAccelerationListener, AccelerationSensorOptions)}
+ * @see {@link #enableAccelerationSensor(Context, IAccelerationListener, AccelerationSensorOptions)}
*/
public boolean enableAccelerationSensor(final Context pContext, final IAccelerationListener pAccelerationListener) {
return this.enableAccelerationSensor(pContext, pAccelerationListener, new AccelerationSensorOptions(Engine.SENSORDELAY_DEFAULT));
@@ -682,13 +705,13 @@ public boolean enableAccelerationSensor(final Context pContext, final IAccelerat
*/
public boolean enableAccelerationSensor(final Context pContext, final IAccelerationListener pAccelerationListener, final AccelerationSensorOptions pAccelerationSensorOptions) {
final SensorManager sensorManager = (SensorManager) pContext.getSystemService(Context.SENSOR_SERVICE);
- if(this.isSensorSupported(sensorManager, Sensor.TYPE_ACCELEROMETER)) {
+ if (this.isSensorSupported(sensorManager, Sensor.TYPE_ACCELEROMETER)) {
this.mAccelerationListener = pAccelerationListener;
- if(this.mAccelerationData == null) {
- final Display display = ((WindowManager) pContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
- final int displayRotation = display.getOrientation();
- this.mAccelerationData = new AccelerationData(displayRotation);
+ this.initDefaultDisplay(pContext);
+
+ if (this.mAccelerationData == null) {
+ this.mAccelerationData = new AccelerationData();
}
this.registerSelfAsSensorListener(sensorManager, Sensor.TYPE_ACCELEROMETER, pAccelerationSensorOptions.getSensorDelay());
@@ -699,13 +722,12 @@ public boolean enableAccelerationSensor(final Context pContext, final IAccelerat
}
}
-
/**
* @return true when the sensor was successfully disabled, false otherwise.
*/
public boolean disableAccelerationSensor(final Context pContext) {
final SensorManager sensorManager = (SensorManager) pContext.getSystemService(Context.SENSOR_SERVICE);
- if(this.isSensorSupported(sensorManager, Sensor.TYPE_ACCELEROMETER)) {
+ if (this.isSensorSupported(sensorManager, Sensor.TYPE_ACCELEROMETER)) {
this.unregisterSelfAsSensorListener(sensorManager, Sensor.TYPE_ACCELEROMETER);
return true;
} else {
@@ -714,7 +736,7 @@ public boolean disableAccelerationSensor(final Context pContext) {
}
/**
- * @see {@link Engine#enableOrientationSensor(Context, IOrientationListener, OrientationSensorOptions)}
+ * @see {@link #enableOrientationSensor(Context, IOrientationListener, OrientationSensorOptions)}
*/
public boolean enableOrientationSensor(final Context pContext, final IOrientationListener pOrientationListener) {
return this.enableOrientationSensor(pContext, pOrientationListener, new OrientationSensorOptions(Engine.SENSORDELAY_DEFAULT));
@@ -725,13 +747,13 @@ public boolean enableOrientationSensor(final Context pContext, final IOrientatio
*/
public boolean enableOrientationSensor(final Context pContext, final IOrientationListener pOrientationListener, final OrientationSensorOptions pOrientationSensorOptions) {
final SensorManager sensorManager = (SensorManager) pContext.getSystemService(Context.SENSOR_SERVICE);
- if(this.isSensorSupported(sensorManager, Sensor.TYPE_ACCELEROMETER) && this.isSensorSupported(sensorManager, Sensor.TYPE_MAGNETIC_FIELD)) {
+ if (this.isSensorSupported(sensorManager, Sensor.TYPE_ACCELEROMETER) && this.isSensorSupported(sensorManager, Sensor.TYPE_MAGNETIC_FIELD)) {
this.mOrientationListener = pOrientationListener;
- if(this.mOrientationData == null) {
- final Display display = ((WindowManager) pContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
- final int displayRotation = display.getOrientation();
- this.mOrientationData = new OrientationData(displayRotation);
+ this.initDefaultDisplay(pContext);
+
+ if (this.mOrientationData == null) {
+ this.mOrientationData = new OrientationData();
}
this.registerSelfAsSensorListener(sensorManager, Sensor.TYPE_ACCELEROMETER, pOrientationSensorOptions.getSensorDelay());
@@ -749,7 +771,7 @@ public boolean enableOrientationSensor(final Context pContext, final IOrientatio
*/
public boolean disableOrientationSensor(final Context pContext) {
final SensorManager sensorManager = (SensorManager) pContext.getSystemService(Context.SENSOR_SERVICE);
- if(this.isSensorSupported(sensorManager, Sensor.TYPE_ACCELEROMETER) && this.isSensorSupported(sensorManager, Sensor.TYPE_MAGNETIC_FIELD)) {
+ if (this.isSensorSupported(sensorManager, Sensor.TYPE_ACCELEROMETER) && this.isSensorSupported(sensorManager, Sensor.TYPE_MAGNETIC_FIELD)) {
this.unregisterSelfAsSensorListener(sensorManager, Sensor.TYPE_ACCELEROMETER);
this.unregisterSelfAsSensorListener(sensorManager, Sensor.TYPE_MAGNETIC_FIELD);
return true;
@@ -772,6 +794,25 @@ private void unregisterSelfAsSensorListener(final SensorManager pSensorManager,
pSensorManager.unregisterListener(this, sensor);
}
+ private void initDefaultDisplay(final Context pContext) {
+ if (this.mDefaultDisplay == null) {
+ final WindowManager windowManager = (WindowManager) pContext.getSystemService(Context.WINDOW_SERVICE);
+ this.mDefaultDisplay = windowManager.getDefaultDisplay();
+ }
+ }
+
+ private void releaseDefaultDisplay() {
+ this.mDefaultDisplay = null;
+ }
+
+ private int getDisplayOrientation() {
+ if (this.mDefaultDisplay == null) {
+ throw new IllegalStateException();
+ } else {
+ return this.mDefaultDisplay.getOrientation();
+ }
+ }
+
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
@@ -812,12 +853,12 @@ public void setEngine(final Engine pEngine) {
public void run() {
android.os.Process.setThreadPriority(this.mEngine.getEngineOptions().getUpdateThreadPriority());
try {
- while(true) {
+ while (true) {
this.mRunnableHandler.onUpdate(0);
this.mEngine.onTickUpdate();
}
} catch (final InterruptedException e) {
- if(BuildConfig.DEBUG) {
+ if (BuildConfig.DEBUG) {
Debug.d(this.getClass().getSimpleName() + " interrupted. Don't worry - this " + e.getClass().getSimpleName() + " is most likely expected!", e);
}
this.interrupt();
@@ -914,13 +955,13 @@ void notifyCanUpdate() {
}
void waitUntilCanDraw() throws InterruptedException {
- while(!this.mDrawing.get()) {
+ while (!this.mDrawing.get()) {
this.mDrawingCondition.await();
}
}
void waitUntilCanUpdate() throws InterruptedException {
- while(this.mDrawing.get()) {
+ while (this.mDrawing.get()) {
this.mDrawingCondition.await();
}
}
diff --git a/src/org/andengine/engine/FixedStepEngine.java b/src/org/andengine/engine/FixedStepEngine.java
index 924add30b..1c1b04919 100644
--- a/src/org/andengine/engine/FixedStepEngine.java
+++ b/src/org/andengine/engine/FixedStepEngine.java
@@ -7,10 +7,10 @@
/**
* A subclass of {@link Engine} that tries to achieve a specific amount of updates per second.
* When the time since the last update is bigger long the steplength, additional updates are executed.
- *
- * (c) 2010 Nicolas Gramlich
+ *
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 10:17:47 - 02.08.2010
*/
@@ -32,6 +32,7 @@ public class FixedStepEngine extends Engine {
public FixedStepEngine(final EngineOptions pEngineOptions, final int pStepsPerSecond) {
super(pEngineOptions);
+
this.mStepLength = TimeConstants.NANOSECONDS_PER_SECOND / pStepsPerSecond;
}
@@ -48,7 +49,7 @@ public void onUpdate(final long pNanosecondsElapsed) throws InterruptedException
this.mSecondsElapsedAccumulator += pNanosecondsElapsed;
final long stepLength = this.mStepLength;
- while(this.mSecondsElapsedAccumulator >= stepLength) {
+ while (this.mSecondsElapsedAccumulator >= stepLength) {
super.onUpdate(stepLength);
this.mSecondsElapsedAccumulator -= stepLength;
}
diff --git a/src/org/andengine/engine/LimitedFPSEngine.java b/src/org/andengine/engine/LimitedFPSEngine.java
index 6b9b302d7..ee7b77aa7 100644
--- a/src/org/andengine/engine/LimitedFPSEngine.java
+++ b/src/org/andengine/engine/LimitedFPSEngine.java
@@ -7,10 +7,10 @@
* A subclass of {@link Engine} that tries to achieve a specific amount of
* updates per second. When the time since the last update is bigger long the
* steplength, additional updates are executed.
- *
- * (c) 2010 Nicolas Gramlich
+ *
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 10:17:47 - 02.08.2010
*/
@@ -31,6 +31,7 @@ public class LimitedFPSEngine extends Engine {
public LimitedFPSEngine(final EngineOptions pEngineOptions, final int pFramesPerSecond) {
super(pEngineOptions);
+
this.mPreferredFrameLengthNanoseconds = TimeConstants.NANOSECONDS_PER_SECOND / pFramesPerSecond;
}
@@ -47,7 +48,7 @@ public void onUpdate(final long pNanosecondsElapsed) throws InterruptedException
final long preferredFrameLengthNanoseconds = this.mPreferredFrameLengthNanoseconds;
final long deltaFrameLengthNanoseconds = preferredFrameLengthNanoseconds - pNanosecondsElapsed;
- if(deltaFrameLengthNanoseconds <= 0) {
+ if (deltaFrameLengthNanoseconds <= 0) {
super.onUpdate(pNanosecondsElapsed);
} else {
final int sleepTimeMilliseconds = (int) (deltaFrameLengthNanoseconds / TimeConstants.NANOSECONDS_PER_MILLISECOND);
diff --git a/src/org/andengine/engine/camera/BoundCamera.java b/src/org/andengine/engine/camera/BoundCamera.java
index d7842369d..9faeea074 100644
--- a/src/org/andengine/engine/camera/BoundCamera.java
+++ b/src/org/andengine/engine/camera/BoundCamera.java
@@ -1,9 +1,9 @@
package org.andengine.engine.camera;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:55:54 - 27.07.2010
*/
@@ -95,12 +95,12 @@ public float getBoundsHeight() {
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
-
+
@Override
public void setCenter(final float pCenterX, final float pCenterY) {
super.setCenter(pCenterX, pCenterY);
-
- if(this.mBoundsEnabled) {
+
+ if (this.mBoundsEnabled) {
this.ensureInBounds();
}
}
@@ -111,16 +111,16 @@ public void setCenter(final float pCenterX, final float pCenterY) {
protected void ensureInBounds() {
final float centerX;
- if(this.mBoundsWidth < this.getWidth()) {
+ if (this.mBoundsWidth < this.getWidth()) {
centerX = this.mBoundsCenterX;
} else {
- centerX = getBoundedX(this.getCenterX());
+ centerX = getBoundedX(this.getCenterX());
}
final float centerY;
- if(this.mBoundsHeight < this.getHeight()) {
+ if (this.mBoundsHeight < this.getHeight()) {
centerY = this.mBoundsCenterY;
} else {
- centerY = getBoundedY(this.getCenterY());
+ centerY = getBoundedY(this.getCenterY());
}
super.setCenter(centerX, centerY);
}
@@ -132,8 +132,8 @@ protected float getBoundedX(final float pX) {
final float maxXBoundExceededAmount = this.getXMax() - this.mBoundsXMax;
final boolean maxXBoundExceeded = maxXBoundExceededAmount > 0;
- if(minXBoundExceeded) {
- if(maxXBoundExceeded) {
+ if (minXBoundExceeded) {
+ if (maxXBoundExceeded) {
/* Min and max X exceeded. */
return pX - maxXBoundExceededAmount + minXBoundExceededAmount;
} else {
@@ -141,7 +141,7 @@ protected float getBoundedX(final float pX) {
return pX + minXBoundExceededAmount;
}
} else {
- if(maxXBoundExceeded) {
+ if (maxXBoundExceeded) {
/* Only max X exceeded. */
return pX - maxXBoundExceededAmount;
} else {
@@ -158,8 +158,8 @@ protected float getBoundedY(final float pY) {
final float maxYBoundExceededAmount = this.getYMax() - this.mBoundsYMax;
final boolean maxYBoundExceeded = maxYBoundExceededAmount > 0;
- if(minYBoundExceeded) {
- if(maxYBoundExceeded) {
+ if (minYBoundExceeded) {
+ if (maxYBoundExceeded) {
/* Min and max Y exceeded. */
return pY - maxYBoundExceededAmount + minYBoundExceededAmount;
} else {
@@ -167,7 +167,7 @@ protected float getBoundedY(final float pY) {
return pY + minYBoundExceededAmount;
}
} else {
- if(maxYBoundExceeded) {
+ if (maxYBoundExceeded) {
/* Only max Y exceeded. */
return pY - maxYBoundExceededAmount;
} else {
diff --git a/src/org/andengine/engine/camera/Camera.java b/src/org/andengine/engine/camera/Camera.java
index f4719398a..169a6fd49 100644
--- a/src/org/andengine/engine/camera/Camera.java
+++ b/src/org/andengine/engine/camera/Camera.java
@@ -5,18 +5,17 @@
import org.andengine.engine.handler.UpdateHandlerList;
import org.andengine.entity.IEntity;
import org.andengine.entity.primitive.Line;
-import org.andengine.entity.shape.RectangularShape;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.util.GLState;
import org.andengine.util.Constants;
import org.andengine.util.adt.transformation.Transformation;
-import org.andengine.util.algorithm.collision.RectangularShapeCollisionChecker;
+import org.andengine.util.algorithm.collision.EntityCollisionChecker;
import org.andengine.util.math.MathUtils;
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 10:24:18 - 25.03.2010
*/
@@ -136,11 +135,11 @@ public float getHeight() {
return this.mYMax - this.mYMin;
}
- public float getWidthRaw() {
+ public final float getCameraSceneWidth() {
return this.mXMax - this.mXMin;
}
- public float getHeightRaw() {
+ public final float getCameraSceneHeight() {
return this.mYMax - this.mYMin;
}
@@ -172,7 +171,7 @@ public HUD getHUD() {
public void setHUD(final HUD pHUD) {
this.mHUD = pHUD;
- if(pHUD != null) {
+ if (pHUD != null) {
pHUD.setCamera(this);
}
}
@@ -222,9 +221,9 @@ public int getSurfaceHeight() {
}
public void setSurfaceSize(final int pSurfaceX, final int pSurfaceY, final int pSurfaceWidth, final int pSurfaceHeight) {
- if(this.mSurfaceHeight == 0 && this.mSurfaceWidth == 0) {
+ if (this.mSurfaceHeight == 0 && this.mSurfaceWidth == 0) {
this.onSurfaceSizeInitialized(pSurfaceX, pSurfaceY, pSurfaceWidth, pSurfaceHeight);
- } else if(this.mSurfaceWidth != pSurfaceWidth || this.mSurfaceHeight != pSurfaceHeight) {
+ } else if (this.mSurfaceWidth != pSurfaceWidth || this.mSurfaceHeight != pSurfaceHeight) {
this.onSurfaceSizeChanged(this.mSurfaceX, this.mSurfaceY, this.mSurfaceWidth, this.mSurfaceHeight, pSurfaceX, pSurfaceY, pSurfaceWidth, pSurfaceHeight);
}
}
@@ -243,11 +242,11 @@ public void setResizeOnSurfaceSizeChanged(final boolean pResizeOnSurfaceSizeChan
@Override
public void onUpdate(final float pSecondsElapsed) {
- if(this.mUpdateHandlers != null) {
+ if (this.mUpdateHandlers != null) {
this.mUpdateHandlers.onUpdate(pSecondsElapsed);
}
- if(this.mHUD != null) {
+ if (this.mHUD != null) {
this.mHUD.onUpdate(pSecondsElapsed);
}
@@ -264,59 +263,59 @@ public void reset() {
// ===========================================================
public void onDrawHUD(final GLState pGLState) {
- if(this.mHUD != null) {
+ if (this.mHUD != null) {
this.mHUD.onDraw(pGLState, this);
}
}
public void updateChaseEntity() {
- if(this.mChaseEntity != null) {
+ if (this.mChaseEntity != null) {
final float[] centerCoordinates = this.mChaseEntity.getSceneCenterCoordinates();
this.setCenter(centerCoordinates[Constants.VERTEX_INDEX_X], centerCoordinates[Constants.VERTEX_INDEX_Y]);
}
}
public boolean isLineVisible(final Line pLine) {
- return RectangularShapeCollisionChecker.isVisible(this, pLine);
+ return EntityCollisionChecker.isVisible(this, pLine);
}
- public boolean isRectangularShapeVisible(final RectangularShape pRectangularShape) {
- return RectangularShapeCollisionChecker.isVisible(this, pRectangularShape);
+ public boolean isEntityVisible(final IEntity pEntity) {
+ return EntityCollisionChecker.isVisible(this, pEntity);
}
- public boolean isRectangularShapeVisible(final float pX, final float pY, final float pWidth, final float pHeight, final Transformation pLocalToSceneTransformation) {
- return RectangularShapeCollisionChecker.isVisible(this, pX, pY, pWidth, pHeight, pLocalToSceneTransformation);
+ public boolean isEntityVisible(final float pX, final float pY, final float pWidth, final float pHeight, final Transformation pLocalToSceneTransformation) {
+ return EntityCollisionChecker.isVisible(this, pX, pY, pWidth, pHeight, pLocalToSceneTransformation);
}
public void onApplySceneMatrix(final GLState pGLState) {
- pGLState.orthoProjectionGLMatrixf(this.getXMin(), this.getXMax(), this.getYMax(), this.getYMin(), this.mZNear, this.mZFar);
+ pGLState.orthoProjectionGLMatrixf(this.getXMin(), this.getXMax(), this.getYMin(), this.getYMax(), this.mZNear, this.mZFar);
final float rotation = this.mRotation;
- if(rotation != 0) {
+ if (rotation != 0) {
this.applyRotation(pGLState, this.getCenterX(), this.getCenterY(), rotation);
}
}
public void onApplySceneBackgroundMatrix(final GLState pGLState) {
- final float widthRaw = this.getWidthRaw();
- final float heightRaw = this.getHeightRaw();
+ final float cameraSceneWidth = this.getCameraSceneWidth();
+ final float cameraSceneHeight = this.getCameraSceneHeight();
- pGLState.orthoProjectionGLMatrixf(0, widthRaw, heightRaw, 0, this.mZNear, this.mZFar);
+ pGLState.orthoProjectionGLMatrixf(0, cameraSceneWidth, 0, cameraSceneHeight, this.mZNear, this.mZFar);
final float rotation = this.mRotation;
- if(rotation != 0) {
- this.applyRotation(pGLState, widthRaw * 0.5f, heightRaw * 0.5f, rotation);
+ if (rotation != 0) {
+ this.applyRotation(pGLState, cameraSceneWidth * 0.5f, cameraSceneHeight * 0.5f, rotation);
}
}
public void onApplyCameraSceneMatrix(final GLState pGLState) {
- final float widthRaw = this.getWidthRaw();
- final float heightRaw = this.getHeightRaw();
- pGLState.orthoProjectionGLMatrixf(0, widthRaw, heightRaw, 0, this.mZNear, this.mZFar);
+ final float cameraSceneWidth = this.getCameraSceneWidth();
+ final float cameraSceneHeight = this.getCameraSceneHeight();
+ pGLState.orthoProjectionGLMatrixf(0, cameraSceneWidth, 0, cameraSceneHeight, this.mZNear, this.mZFar);
final float cameraSceneRotation = this.mCameraSceneRotation;
- if(cameraSceneRotation != 0) {
- this.applyRotation(pGLState, widthRaw * 0.5f, heightRaw * 0.5f, cameraSceneRotation);
+ if (cameraSceneRotation != 0) {
+ this.applyRotation(pGLState, cameraSceneWidth * 0.5f, cameraSceneHeight * 0.5f, cameraSceneRotation);
}
}
@@ -326,7 +325,7 @@ private void applyRotation(final GLState pGLState, final float pRotationCenterX,
pGLState.translateProjectionGLMatrixf(-pRotationCenterX, -pRotationCenterY, 0);
}
- public void convertSceneToCameraSceneTouchEvent(final TouchEvent pSceneTouchEvent) {
+ public void convertSceneTouchEventToCameraSceneTouchEvent(final TouchEvent pSceneTouchEvent) {
this.unapplySceneRotation(pSceneTouchEvent);
this.applySceneToCameraSceneOffset(pSceneTouchEvent);
@@ -351,7 +350,7 @@ public float[] getCameraSceneCoordinatesFromSceneCoordinates(final float[] pScen
return pSceneCoordinates;
}
- public void convertCameraSceneToSceneTouchEvent(final TouchEvent pCameraSceneTouchEvent) {
+ public void convertCameraSceneTouchEventToSceneTouchEvent(final TouchEvent pCameraSceneTouchEvent) {
this.unapplyCameraSceneRotation(pCameraSceneTouchEvent);
this.unapplySceneToCameraSceneOffset(pCameraSceneTouchEvent);
@@ -396,18 +395,19 @@ protected void unapplySceneToCameraSceneOffset(final float[] pCameraSceneCoordin
private void applySceneRotation(final float[] pCameraSceneCoordinates) {
final float rotation = this.mRotation;
- if(rotation != 0) {
- MathUtils.rotateAroundCenter(pCameraSceneCoordinates, -rotation, this.getCenterX(), this.getCenterY());
+ if (rotation != 0) {
+ MathUtils.rotateAroundCenter(pCameraSceneCoordinates, rotation, this.getCenterX(), this.getCenterY()); // TODO Use a Transformation object instead!?!
}
}
private void applySceneRotation(final TouchEvent pCameraSceneTouchEvent) {
final float rotation = this.mRotation;
- if(rotation != 0) {
+
+ if (rotation != 0) {
Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pCameraSceneTouchEvent.getX();
Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pCameraSceneTouchEvent.getY();
- MathUtils.rotateAroundCenter(Camera.VERTICES_TMP, -rotation, this.getCenterX(), this.getCenterY());
+ MathUtils.rotateAroundCenter(Camera.VERTICES_TMP, rotation, this.getCenterX(), this.getCenterY()); // TODO Use a Transformation object instead!?!
pCameraSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
}
@@ -416,68 +416,72 @@ private void applySceneRotation(final TouchEvent pCameraSceneTouchEvent) {
private void unapplySceneRotation(final float[] pSceneCoordinates) {
final float rotation = this.mRotation;
- if(rotation != 0) {
- MathUtils.revertRotateAroundCenter(pSceneCoordinates, rotation, this.getCenterX(), this.getCenterY());
+ if (rotation != 0) {
+ MathUtils.revertRotateAroundCenter(pSceneCoordinates, rotation, this.getCenterX(), this.getCenterY()); // TODO Use a Transformation object instead!?!
}
}
private void unapplySceneRotation(final TouchEvent pSceneTouchEvent) {
final float rotation = this.mRotation;
- if(rotation != 0) {
+ if (rotation != 0) {
Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pSceneTouchEvent.getX();
Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pSceneTouchEvent.getY();
- MathUtils.revertRotateAroundCenter(Camera.VERTICES_TMP, rotation, this.getCenterX(), this.getCenterY());
+ MathUtils.revertRotateAroundCenter(Camera.VERTICES_TMP, rotation, this.getCenterX(), this.getCenterY()); // TODO Use a Transformation object instead!?!
pSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
}
}
private void applyCameraSceneRotation(final float[] pSceneCoordinates) {
- final float cameraSceneRotation = -this.mCameraSceneRotation;
+ final float cameraSceneRotation = this.mCameraSceneRotation;
- if(cameraSceneRotation != 0) {
- MathUtils.rotateAroundCenter(pSceneCoordinates, cameraSceneRotation, (this.mXMax - this.mXMin) * 0.5f, (this.mYMax - this.mYMin) * 0.5f);
+ if (cameraSceneRotation != 0) {
+ MathUtils.rotateAroundCenter(pSceneCoordinates, cameraSceneRotation, this.getCameraSceneWidth() * 0.5f, this.getCameraSceneHeight() * 0.5f); // TODO Use a Transformation object instead!?!
}
}
private void applyCameraSceneRotation(final TouchEvent pSceneTouchEvent) {
- final float cameraSceneRotation = -this.mCameraSceneRotation;
+ final float cameraSceneRotation = this.mCameraSceneRotation;
- if(cameraSceneRotation != 0) {
+ if (cameraSceneRotation != 0) {
Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pSceneTouchEvent.getX();
Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pSceneTouchEvent.getY();
- MathUtils.rotateAroundCenter(Camera.VERTICES_TMP, cameraSceneRotation, (this.mXMax - this.mXMin) * 0.5f, (this.mYMax - this.mYMin) * 0.5f);
+ MathUtils.rotateAroundCenter(Camera.VERTICES_TMP, cameraSceneRotation, this.getCameraSceneWidth() * 0.5f, this.getCameraSceneHeight() * 0.5f); // TODO Use a Transformation object instead!?!
pSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
}
}
private void unapplyCameraSceneRotation(final float[] pCameraSceneCoordinates) {
- final float cameraSceneRotation = -this.mCameraSceneRotation;
+ final float cameraSceneRotation = this.mCameraSceneRotation;
- if(cameraSceneRotation != 0) {
- MathUtils.revertRotateAroundCenter(pCameraSceneCoordinates, cameraSceneRotation, (this.mXMax - this.mXMin) * 0.5f, (this.mYMax - this.mYMin) * 0.5f);
+ if (cameraSceneRotation != 0) {
+ MathUtils.revertRotateAroundCenter(pCameraSceneCoordinates, cameraSceneRotation, this.getCameraSceneWidth() * 0.5f, this.getCameraSceneHeight() * 0.5f); // TODO Use a Transformation object instead!?!
}
}
private void unapplyCameraSceneRotation(final TouchEvent pCameraSceneTouchEvent) {
- final float cameraSceneRotation = -this.mCameraSceneRotation;
+ final float cameraSceneRotation = this.mCameraSceneRotation;
- if(cameraSceneRotation != 0) {
+ if (cameraSceneRotation != 0) {
Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pCameraSceneTouchEvent.getX();
Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pCameraSceneTouchEvent.getY();
- MathUtils.revertRotateAroundCenter(Camera.VERTICES_TMP, cameraSceneRotation, (this.mXMax - this.mXMin) * 0.5f, (this.mYMax - this.mYMin) * 0.5f);
+ MathUtils.revertRotateAroundCenter(Camera.VERTICES_TMP, cameraSceneRotation, this.getCameraSceneWidth() * 0.5f, this.getCameraSceneHeight() * 0.5f); // TODO Use a Transformation object instead!?!
pCameraSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
}
}
- // TODO Camera already knows about its surfaceWidth, is there a need to pass it in here again?
- public void convertSurfaceToSceneTouchEvent(final TouchEvent pSurfaceTouchEvent, final int pSurfaceWidth, final int pSurfaceHeight) {
+
+ public void convertSurfaceTouchEventToSceneTouchEvent(final TouchEvent pSurfaceTouchEvent) {
+ this.convertSurfaceTouchEventToSceneTouchEvent(pSurfaceTouchEvent, this.mSurfaceWidth, this.mSurfaceHeight);
+ }
+
+ public void convertSurfaceTouchEventToSceneTouchEvent(final TouchEvent pSurfaceTouchEvent, final int pSurfaceWidth, final int pSurfaceHeight) {
final float relativeX;
final float relativeY;
@@ -485,26 +489,60 @@ public void convertSurfaceToSceneTouchEvent(final TouchEvent pSurfaceTouchEvent,
final float surfaceTouchEventY = pSurfaceTouchEvent.getY();
final float rotation = this.mRotation;
- if(rotation == 0) {
+ if (rotation == 0) {
relativeX = surfaceTouchEventX / pSurfaceWidth;
- relativeY = surfaceTouchEventY / pSurfaceHeight;
- } else if(rotation == 180) {
- relativeX = 1 - (surfaceTouchEventX / pSurfaceWidth);
relativeY = 1 - (surfaceTouchEventY / pSurfaceHeight);
+ } else if (rotation == 180) {
+ relativeX = 1 - (surfaceTouchEventX / pSurfaceWidth);
+ relativeY = surfaceTouchEventY / pSurfaceHeight;
} else {
Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = surfaceTouchEventX;
Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = surfaceTouchEventY;
- MathUtils.rotateAroundCenter(Camera.VERTICES_TMP, rotation, pSurfaceWidth >> 1, pSurfaceHeight >> 1);
+ MathUtils.rotateAroundCenter(Camera.VERTICES_TMP, rotation, pSurfaceWidth >> 1, pSurfaceHeight >> 1); // TODO Use a Transformation object instead!?!
relativeX = Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] / pSurfaceWidth;
- relativeY = Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] / pSurfaceHeight;
+ relativeY = 1 - (Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] / pSurfaceHeight);
+ }
+
+ this.convertAxisAlignedSurfaceTouchEventToSceneTouchEvent(pSurfaceTouchEvent, relativeX, relativeY);
+ }
+
+ public float[] getSceneCoordinatesFromSurfaceCoordinates(final float pSurfaceX, final float pSurfaceY) {
+ Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pSurfaceX;
+ Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pSurfaceY;
+
+ return this.getSceneCoordinatesFromSurfaceCoordinates(Camera.VERTICES_TMP);
+ }
+
+ public float[] getSceneCoordinatesFromSurfaceCoordinates(final float[] pSurfaceCoordinates) {
+ return this.getSceneCoordinatesFromSurfaceCoordinates(pSurfaceCoordinates, this.mSurfaceWidth, this.mSurfaceHeight);
+ }
+
+ public float[] getSceneCoordinatesFromSurfaceCoordinates(final float[] pSurfaceCoordinates, final int pSurfaceWidth, final int pSurfaceHeight) {
+ final float relativeX;
+ final float relativeY;
+
+ final float rotation = this.mRotation;
+ if (rotation == 0) {
+ relativeX = pSurfaceCoordinates[Constants.VERTEX_INDEX_X] / pSurfaceWidth;
+ relativeY = 1 - (pSurfaceCoordinates[Constants.VERTEX_INDEX_Y] / pSurfaceHeight);
+ } else if (rotation == 180) {
+ relativeX = 1 - (pSurfaceCoordinates[Constants.VERTEX_INDEX_X] / pSurfaceWidth);
+ relativeY = pSurfaceCoordinates[Constants.VERTEX_INDEX_Y] / pSurfaceHeight;
+ } else {
+ MathUtils.rotateAroundCenter(pSurfaceCoordinates, rotation, pSurfaceWidth >> 1, pSurfaceHeight >> 1); // TODO Use a Transformation object instead!?!
+
+ relativeX = pSurfaceCoordinates[Constants.VERTEX_INDEX_X] / pSurfaceWidth;
+ relativeY = 1 - (pSurfaceCoordinates[Constants.VERTEX_INDEX_Y] / pSurfaceHeight);
}
- this.convertAxisAlignedSurfaceToSceneTouchEvent(pSurfaceTouchEvent, relativeX, relativeY);
+ this.convertAxisAlignedSurfaceCoordinatesToSceneCoordinates(pSurfaceCoordinates, relativeX, relativeY);
+
+ return pSurfaceCoordinates;
}
- private void convertAxisAlignedSurfaceToSceneTouchEvent(final TouchEvent pSurfaceTouchEvent, final float pRelativeX, final float pRelativeY) {
+ private void convertAxisAlignedSurfaceTouchEventToSceneTouchEvent(final TouchEvent pSurfaceTouchEvent, final float pRelativeX, final float pRelativeY) {
final float xMin = this.getXMin();
final float xMax = this.getXMax();
final float yMin = this.getYMin();
@@ -516,24 +554,74 @@ private void convertAxisAlignedSurfaceToSceneTouchEvent(final TouchEvent pSurfac
pSurfaceTouchEvent.set(x, y);
}
- public void convertSceneToSurfaceTouchEvent(final TouchEvent pSceneTouchEvent, final int pSurfaceWidth, final int pSurfaceHeight) {
+ private void convertAxisAlignedSurfaceCoordinatesToSceneCoordinates(final float[] pSurfaceCoordinates, final float pRelativeX, final float pRelativeY) {
+ final float xMin = this.getXMin();
+ final float xMax = this.getXMax();
+ final float yMin = this.getYMin();
+ final float yMax = this.getYMax();
+
+ final float x = xMin + pRelativeX * (xMax - xMin);
+ final float y = yMin + pRelativeY * (yMax - yMin);
+
+ pSurfaceCoordinates[Constants.VERTEX_INDEX_X] = x;
+ pSurfaceCoordinates[Constants.VERTEX_INDEX_Y] = y;
+ }
+
+
+ public void convertSceneTouchEventToSurfaceTouchEvent(final TouchEvent pSceneTouchEvent) {
+ this.convertSceneTouchEventToSurfaceTouchEvent(pSceneTouchEvent, this.mSurfaceWidth, this.mSurfaceHeight);
+ }
+
+ public void convertSceneTouchEventToSurfaceTouchEvent(final TouchEvent pSceneTouchEvent, final int pSurfaceWidth, final int pSurfaceHeight) {
this.convertAxisAlignedSceneToSurfaceTouchEvent(pSceneTouchEvent, pSurfaceWidth, pSurfaceHeight);
final float rotation = this.mRotation;
- if(rotation == 0) {
- /* Nothing to do. */
- } else if(rotation == 180) {
- pSceneTouchEvent.set(pSurfaceWidth - pSceneTouchEvent.getX(), pSurfaceHeight - pSceneTouchEvent.getY());
+ if (rotation == 0) {
+ /* Nothing. */
+ } else if (rotation == 180) {
+ pSceneTouchEvent.setY(pSurfaceHeight - pSceneTouchEvent.getY());
+ pSceneTouchEvent.setX(pSurfaceWidth - pSceneTouchEvent.getX());
} else {
Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pSceneTouchEvent.getX();
Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pSceneTouchEvent.getY();
- MathUtils.revertRotateAroundCenter(Camera.VERTICES_TMP, rotation, pSurfaceWidth >> 1, pSurfaceHeight >> 1);
+ MathUtils.revertRotateAroundCenter(Camera.VERTICES_TMP, -rotation, pSurfaceWidth >> 1, pSurfaceHeight >> 1); // TODO Use a Transformation object instead!?!
pSceneTouchEvent.set(Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X], Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y]);
}
}
+ public float[] getSurfaceCoordinatesFromSceneCoordinates(final float pSceneX, final float pSceneY) {
+ return this.getSurfaceCoordinatesFromSceneCoordinates(pSceneX, pSceneY, mSurfaceWidth, mSurfaceHeight);
+ }
+
+ public float[] getSurfaceCoordinatesFromSceneCoordinates(final float pSceneX, final float pSceneY, final int pSurfaceWidth, final int pSurfaceHeight) {
+ Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pSceneX;
+ Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pSceneY;
+
+ return this.getSurfaceCoordinatesFromSceneCoordinates(Camera.VERTICES_TMP, pSurfaceWidth, pSurfaceHeight);
+ }
+
+ public float[] getSurfaceCoordinatesFromSceneCoordinates(final float[] pSceneCoordinates) {
+ return this.getSurfaceCoordinatesFromSceneCoordinates(pSceneCoordinates, this.mSurfaceWidth, this.mSurfaceHeight);
+ }
+
+ public float[] getSurfaceCoordinatesFromSceneCoordinates(final float[] pSceneCoordinates, final int pSurfaceWidth, final int pSurfaceHeight) {
+ this.convertAxisAlignedSceneCoordinatesToSurfaceCoordinates(pSceneCoordinates, pSurfaceWidth, pSurfaceHeight);
+
+ final float rotation = this.mRotation;
+ if (rotation == 0) {
+ /* Nothing. */
+ } else if (rotation == 180) {
+ pSceneCoordinates[Constants.VERTEX_INDEX_Y] = pSurfaceHeight - pSceneCoordinates[Constants.VERTEX_INDEX_Y];
+ pSceneCoordinates[Constants.VERTEX_INDEX_X] = pSurfaceWidth - pSceneCoordinates[Constants.VERTEX_INDEX_X];
+ } else {
+ MathUtils.revertRotateAroundCenter(pSceneCoordinates, -rotation, pSurfaceWidth >> 1, pSurfaceHeight >> 1); // TODO Use a Transformation object instead!?!
+ }
+
+ return pSceneCoordinates;
+ }
+
private void convertAxisAlignedSceneToSurfaceTouchEvent(final TouchEvent pSceneTouchEvent, final int pSurfaceWidth, final int pSurfaceHeight) {
final float xMin = this.getXMin();
final float xMax = this.getXMax();
@@ -541,34 +629,51 @@ private void convertAxisAlignedSceneToSurfaceTouchEvent(final TouchEvent pSceneT
final float yMax = this.getYMax();
final float relativeX = (pSceneTouchEvent.getX() - xMin) / (xMax - xMin);
- final float relativeY = (pSceneTouchEvent.getY() - yMin) / (yMax - yMin);
+ final float relativeY = 1 - (pSceneTouchEvent.getY() - yMin) / (yMax - yMin);
- pSceneTouchEvent.set(relativeX * pSurfaceWidth, relativeY * pSurfaceHeight);
+ final float x = relativeX * pSurfaceWidth;
+ final float y = relativeY * pSurfaceHeight;
+
+ pSceneTouchEvent.set(x, y);
}
+ private void convertAxisAlignedSceneCoordinatesToSurfaceCoordinates(final float[] pSceneCoordinates, final int pSurfaceWidth, final int pSurfaceHeight) {
+ final float xMin = this.getXMin();
+ final float xMax = this.getXMax();
+ final float yMin = this.getYMin();
+ final float yMax = this.getYMax();
+
+ final float relativeX = (pSceneCoordinates[Constants.VERTEX_INDEX_X] - xMin) / (xMax - xMin);
+ final float relativeY = 1 - (pSceneCoordinates[Constants.VERTEX_INDEX_Y] - yMin) / (yMax - yMin);
+
+ pSceneCoordinates[Constants.VERTEX_INDEX_X] = relativeX * pSurfaceWidth;
+ pSceneCoordinates[Constants.VERTEX_INDEX_Y] = relativeY * pSurfaceHeight;
+ }
+
+
public void registerUpdateHandler(final IUpdateHandler pUpdateHandler) {
- if(this.mUpdateHandlers == null) {
+ if (this.mUpdateHandlers == null) {
this.allocateUpdateHandlers();
}
this.mUpdateHandlers.add(pUpdateHandler);
}
public boolean unregisterUpdateHandler(final IUpdateHandler pUpdateHandler) {
- if(this.mUpdateHandlers == null) {
+ if (this.mUpdateHandlers == null) {
return false;
}
return this.mUpdateHandlers.remove(pUpdateHandler);
}
public boolean unregisterUpdateHandlers(final IUpdateHandlerMatcher pUpdateHandlerMatcher) {
- if(this.mUpdateHandlers == null) {
+ if (this.mUpdateHandlers == null) {
return false;
}
return this.mUpdateHandlers.removeAll(pUpdateHandlerMatcher);
}
public void clearUpdateHandlers() {
- if(this.mUpdateHandlers == null) {
+ if (this.mUpdateHandlers == null) {
return;
}
this.mUpdateHandlers.clear();
@@ -586,23 +691,23 @@ protected void onSurfaceSizeInitialized(final int pSurfaceX, final int pSurfaceY
}
protected void onSurfaceSizeChanged(final int pOldSurfaceX, final int pOldSurfaceY, final int pOldSurfaceWidth, final int pOldSurfaceHeight, final int pNewSurfaceX, final int pNewSurfaceY, final int pNewSurfaceWidth, final int pNewSurfaceHeight) {
- if(this.mResizeOnSurfaceSizeChanged) {
+ if (this.mResizeOnSurfaceSizeChanged) {
final float surfaceWidthRatio = (float)pNewSurfaceWidth / pOldSurfaceWidth;
final float surfaceHeightRatio = (float)pNewSurfaceHeight / pOldSurfaceHeight;
final float centerX = this.getCenterX();
final float centerY = this.getCenterY();
- final float newWidthRaw = this.getWidthRaw() * surfaceWidthRatio;
- final float newHeightRaw = this.getHeightRaw() * surfaceHeightRatio;
+ final float newWidth = (this.mXMax - this.mXMin) * surfaceWidthRatio;
+ final float newHeight = (this.mYMax - this.mYMin) * surfaceHeightRatio;
- final float newWidthRawHalf = newWidthRaw * 0.5f;
- final float newHeightRawHalf = newHeightRaw * 0.5f;
+ final float newWidthHalf = newWidth * 0.5f;
+ final float newHeightHalf = newHeight * 0.5f;
- final float xMin = centerX - newWidthRawHalf;
- final float yMin = centerY - newHeightRawHalf;
- final float xMax = centerX + newWidthRawHalf;
- final float yMax = centerY + newHeightRawHalf;
+ final float xMin = centerX - newWidthHalf;
+ final float yMin = centerY - newHeightHalf;
+ final float xMax = centerX + newWidthHalf;
+ final float yMax = centerY + newHeightHalf;
this.set(xMin, yMin, xMax, yMax);
}
diff --git a/src/org/andengine/engine/camera/CameraFactory.java b/src/org/andengine/engine/camera/CameraFactory.java
index ad64d1312..e7dbadce9 100644
--- a/src/org/andengine/engine/camera/CameraFactory.java
+++ b/src/org/andengine/engine/camera/CameraFactory.java
@@ -4,13 +4,13 @@
import android.util.DisplayMetrics;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 13:50:42 - 03.07.2010
*/
-public class CameraFactory {
+public final class CameraFactory {
// ===========================================================
// Constants
// ===========================================================
@@ -23,6 +23,10 @@ public class CameraFactory {
// Constructors
// ===========================================================
+ private CameraFactory() {
+
+ }
+
// ===========================================================
// Getter & Setter
// ===========================================================
diff --git a/src/org/andengine/engine/camera/SmoothCamera.java b/src/org/andengine/engine/camera/SmoothCamera.java
index 46ebb688c..0f0823500 100644
--- a/src/org/andengine/engine/camera/SmoothCamera.java
+++ b/src/org/andengine/engine/camera/SmoothCamera.java
@@ -2,9 +2,9 @@
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 22:11:17 - 25.03.2010
*/
@@ -72,8 +72,8 @@ public void setCenterDirect(final float pCenterX, final float pCenterY) {
@Override
public void setZoomFactor(final float pZoomFactor) {
- if(this.mTargetZoomFactor != pZoomFactor) {
- if(this.mTargetZoomFactor == this.mZoomFactor) {
+ if (this.mTargetZoomFactor != pZoomFactor) {
+ if (this.mTargetZoomFactor == this.mZoomFactor) {
this.mTargetZoomFactor = pZoomFactor;
this.onSmoothZoomStarted();
@@ -84,7 +84,7 @@ public void setZoomFactor(final float pZoomFactor) {
}
public void setZoomFactorDirect(final float pZoomFactor) {
- if(this.mTargetZoomFactor != this.mZoomFactor) {
+ if (this.mTargetZoomFactor != this.mZoomFactor) {
this.mTargetZoomFactor = pZoomFactor;
super.setZoomFactor(pZoomFactor);
@@ -146,7 +146,7 @@ public void onUpdate(final float pSecondsElapsed) {
final float targetCenterX = this.mTargetCenterX;
final float targetCenterY = this.mTargetCenterY;
- if(currentCenterX != targetCenterX || currentCenterY != targetCenterY) {
+ if (currentCenterX != targetCenterX || currentCenterY != targetCenterY) {
final float diffX = targetCenterX - currentCenterX;
final float dX = this.limitToMaxVelocityX(diffX, pSecondsElapsed);
@@ -161,19 +161,19 @@ public void onUpdate(final float pSecondsElapsed) {
final float targetZoomFactor = this.mTargetZoomFactor;
- if(currentZoom != targetZoomFactor) {
+ if (currentZoom != targetZoomFactor) {
final float absoluteZoomDifference = targetZoomFactor - currentZoom;
final float zoomChange = this.limitToMaxZoomFactorChange(absoluteZoomDifference, pSecondsElapsed);
super.setZoomFactor(currentZoom + zoomChange);
- if(this.mZoomFactor == this.mTargetZoomFactor) {
+ if (this.mZoomFactor == this.mTargetZoomFactor) {
this.onSmoothZoomFinished();
}
}
}
private float limitToMaxVelocityX(final float pValue, final float pSecondsElapsed) {
- if(pValue > 0) {
+ if (pValue > 0) {
return Math.min(pValue, this.mMaxVelocityX * pSecondsElapsed);
} else {
return Math.max(pValue, -this.mMaxVelocityX * pSecondsElapsed);
@@ -181,7 +181,7 @@ private float limitToMaxVelocityX(final float pValue, final float pSecondsElapse
}
private float limitToMaxVelocityY(final float pValue, final float pSecondsElapsed) {
- if(pValue > 0) {
+ if (pValue > 0) {
return Math.min(pValue, this.mMaxVelocityY * pSecondsElapsed);
} else {
return Math.max(pValue, -this.mMaxVelocityY * pSecondsElapsed);
@@ -189,7 +189,7 @@ private float limitToMaxVelocityY(final float pValue, final float pSecondsElapse
}
private float limitToMaxZoomFactorChange(final float pValue, final float pSecondsElapsed) {
- if(pValue > 0) {
+ if (pValue > 0) {
return Math.min(pValue, this.mMaxZoomFactorChange * pSecondsElapsed);
} else {
return Math.max(pValue, -this.mMaxZoomFactorChange * pSecondsElapsed);
diff --git a/src/org/andengine/engine/camera/ZoomCamera.java b/src/org/andengine/engine/camera/ZoomCamera.java
index f94186aff..d40c6958f 100644
--- a/src/org/andengine/engine/camera/ZoomCamera.java
+++ b/src/org/andengine/engine/camera/ZoomCamera.java
@@ -9,7 +9,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:48:11 - 24.06.2010
* TODO min/max(X/Y) values could be cached and only updated once the zoomfactor/center changed.
@@ -44,7 +44,7 @@ public float getZoomFactor() {
public void setZoomFactor(final float pZoomFactor) {
this.mZoomFactor = pZoomFactor;
- if(this.mBoundsEnabled) {
+ if (this.mBoundsEnabled) {
this.ensureInBounds();
}
}
@@ -55,7 +55,7 @@ public void setZoomFactor(final float pZoomFactor) {
@Override
public float getXMin() {
- if(this.mZoomFactor == 1.0f) {
+ if (this.mZoomFactor == 1.0f) {
return super.getXMin();
} else {
final float centerX = this.getCenterX();
@@ -65,7 +65,7 @@ public float getXMin() {
@Override
public float getXMax() {
- if(this.mZoomFactor == 1.0f) {
+ if (this.mZoomFactor == 1.0f) {
return super.getXMax();
} else {
final float centerX = this.getCenterX();
@@ -75,7 +75,7 @@ public float getXMax() {
@Override
public float getYMin() {
- if(this.mZoomFactor == 1.0f) {
+ if (this.mZoomFactor == 1.0f) {
return super.getYMin();
} else {
final float centerY = this.getCenterY();
@@ -85,7 +85,7 @@ public float getYMin() {
@Override
public float getYMax() {
- if(this.mZoomFactor == 1.0f) {
+ if (this.mZoomFactor == 1.0f) {
return super.getYMax();
} else {
final float centerY = this.getCenterY();
@@ -106,7 +106,7 @@ public float getHeight() {
@Override
protected void applySceneToCameraSceneOffset(final TouchEvent pSceneTouchEvent) {
final float zoomFactor = this.mZoomFactor;
- if(zoomFactor != 1) {
+ if (zoomFactor != 1) {
Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pSceneTouchEvent.getX();
Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pSceneTouchEvent.getY();
@@ -121,7 +121,7 @@ protected void applySceneToCameraSceneOffset(final TouchEvent pSceneTouchEvent)
@Override
protected void applySceneToCameraSceneOffset(final float[] pSceneCoordinates) {
final float zoomFactor = this.mZoomFactor;
- if(zoomFactor != 1) {
+ if (zoomFactor != 1) {
MathUtils.scaleAroundCenter(pSceneCoordinates, zoomFactor, zoomFactor, this.getCenterX(), this.getCenterY()); // TODO Use a Transformation object instead!?!
}
@@ -133,7 +133,7 @@ protected void unapplySceneToCameraSceneOffset(final TouchEvent pCameraSceneTouc
super.unapplySceneToCameraSceneOffset(pCameraSceneTouchEvent);
final float zoomFactor = this.mZoomFactor;
- if(zoomFactor != 1) {
+ if (zoomFactor != 1) {
Camera.VERTICES_TMP[Constants.VERTEX_INDEX_X] = pCameraSceneTouchEvent.getX();
Camera.VERTICES_TMP[Constants.VERTEX_INDEX_Y] = pCameraSceneTouchEvent.getY();
@@ -148,7 +148,7 @@ protected void unapplySceneToCameraSceneOffset(final float[] pCameraSceneCoordin
super.unapplySceneToCameraSceneOffset(pCameraSceneCoordinates);
final float zoomFactor = this.mZoomFactor;
- if(zoomFactor != 1) {
+ if (zoomFactor != 1) {
MathUtils.revertScaleAroundCenter(pCameraSceneCoordinates, zoomFactor, zoomFactor, this.getCenterX(), this.getCenterY()); // TODO Use a Transformation object instead!?!
}
}
diff --git a/src/org/andengine/engine/camera/hud/HUD.java b/src/org/andengine/engine/camera/hud/HUD.java
index 052805d3b..4fa0bebe2 100644
--- a/src/org/andengine/engine/camera/hud/HUD.java
+++ b/src/org/andengine/engine/camera/hud/HUD.java
@@ -7,10 +7,10 @@
/**
* While you can add a {@link HUD} to {@link Scene}, you should not do so.
* {@link HUD}s are meant to be added to {@link Camera}s via {@link Camera#setHUD(HUD)}.
- *
- * (c) 2010 Nicolas Gramlich
+ *
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 14:13:13 - 01.04.2010
*/
diff --git a/src/org/andengine/engine/camera/hud/controls/AnalogOnScreenControl.java b/src/org/andengine/engine/camera/hud/controls/AnalogOnScreenControl.java
index 27bfb836b..8feff2a61 100644
--- a/src/org/andengine/engine/camera/hud/controls/AnalogOnScreenControl.java
+++ b/src/org/andengine/engine/camera/hud/controls/AnalogOnScreenControl.java
@@ -8,12 +8,10 @@
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.math.MathUtils;
-import android.util.FloatMath;
-
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 00:21:55 - 11.07.2010
*/
@@ -78,11 +76,11 @@ protected boolean onHandleControlBaseTouched(final TouchEvent pSceneTouchEvent,
@Override
protected void onUpdateControlKnob(final float pRelativeX, final float pRelativeY) {
- if(pRelativeX * pRelativeX + pRelativeY * pRelativeY <= 0.25f) {
+ if (pRelativeX * pRelativeX + pRelativeY * pRelativeY <= 0.25f) {
super.onUpdateControlKnob(pRelativeX, pRelativeY);
} else {
final float angleRad = MathUtils.atan2(pRelativeY, pRelativeX);
- super.onUpdateControlKnob(FloatMath.cos(angleRad) * 0.5f, FloatMath.sin(angleRad) * 0.5f);
+ super.onUpdateControlKnob((float) Math.cos(angleRad) * 0.5f, (float) Math.sin(angleRad) * 0.5f);
}
}
diff --git a/src/org/andengine/engine/camera/hud/controls/BaseOnScreenControl.java b/src/org/andengine/engine/camera/hud/controls/BaseOnScreenControl.java
index 43df2f888..715242edf 100644
--- a/src/org/andengine/engine/camera/hud/controls/BaseOnScreenControl.java
+++ b/src/org/andengine/engine/camera/hud/controls/BaseOnScreenControl.java
@@ -1,8 +1,5 @@
package org.andengine.engine.camera.hud.controls;
-import static org.andengine.util.Constants.VERTEX_INDEX_X;
-import static org.andengine.util.Constants.VERTEX_INDEX_Y;
-
import org.andengine.engine.camera.Camera;
import org.andengine.engine.camera.hud.HUD;
import org.andengine.engine.handler.timer.ITimerCallback;
@@ -18,9 +15,9 @@
import android.view.MotionEvent;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 10:43:09 - 11.07.2010
*/
@@ -43,7 +40,7 @@ public abstract class BaseOnScreenControl extends HUD implements IOnSceneTouchLi
private final IOnScreenControlListener mOnScreenControlListener;
- private int mActivePointerID = INVALID_POINTER_ID;
+ private int mActivePointerID = BaseOnScreenControl.INVALID_POINTER_ID;
// ===========================================================
// Constructors
@@ -76,7 +73,7 @@ public void onTimePassed(final TimerHandler pTimerHandler) {
}));
this.attachChild(this.mControlBase);
- this.attachChild(this.mControlKnob);
+ this.mControlBase.attachChild(this.mControlKnob);
this.setTouchAreaBindingOnActionDownEnabled(true);
}
@@ -104,13 +101,13 @@ public IOnScreenControlListener getOnScreenControlListener() {
@Override
public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {
final int pointerID = pSceneTouchEvent.getPointerID();
- if(pointerID == this.mActivePointerID) {
+ if (pointerID == this.mActivePointerID) {
this.onHandleControlBaseLeft();
- switch(pSceneTouchEvent.getAction()) {
+ switch (pSceneTouchEvent.getAction()) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
- this.mActivePointerID = INVALID_POINTER_ID;
+ this.mActivePointerID = BaseOnScreenControl.INVALID_POINTER_ID;
}
}
return false;
@@ -125,8 +122,8 @@ public void refreshControlKnobPosition() {
}
/**
- * When the touch happened outside of the bounds of this OnScreenControl.
- * */
+ * When the touch happened outside of the bounds of this OnScreenControl.
+ */
protected void onHandleControlBaseLeft() {
this.onUpdateControlKnob(0, 0);
}
@@ -141,9 +138,9 @@ protected void onHandleControlKnobReleased() {
protected boolean onHandleControlBaseTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
final int pointerID = pSceneTouchEvent.getPointerID();
- switch(pSceneTouchEvent.getAction()) {
+ switch (pSceneTouchEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
- if(this.mActivePointerID == INVALID_POINTER_ID) {
+ if (this.mActivePointerID == BaseOnScreenControl.INVALID_POINTER_ID) {
this.mActivePointerID = pointerID;
this.updateControlKnob(pTouchAreaLocalX, pTouchAreaLocalY);
return true;
@@ -151,14 +148,14 @@ protected boolean onHandleControlBaseTouched(final TouchEvent pSceneTouchEvent,
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
- if(this.mActivePointerID == pointerID) {
- this.mActivePointerID = INVALID_POINTER_ID;
+ if (this.mActivePointerID == pointerID) {
+ this.mActivePointerID = BaseOnScreenControl.INVALID_POINTER_ID;
this.onHandleControlKnobReleased();
return true;
}
break;
default:
- if(this.mActivePointerID == pointerID) {
+ if (this.mActivePointerID == pointerID) {
this.updateControlKnob(pTouchAreaLocalX, pTouchAreaLocalY);
return true;
}
@@ -170,15 +167,15 @@ protected boolean onHandleControlBaseTouched(final TouchEvent pSceneTouchEvent,
private void updateControlKnob(final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
final Sprite controlBase = this.mControlBase;
- final float relativeX = MathUtils.bringToBounds(0, controlBase.getWidth(), pTouchAreaLocalX) / controlBase.getWidth() - 0.5f;
- final float relativeY = MathUtils.bringToBounds(0, controlBase.getHeight(), pTouchAreaLocalY) / controlBase.getHeight() - 0.5f;
+ final float relativeX = (MathUtils.bringToBounds(0, controlBase.getWidth(), pTouchAreaLocalX) / controlBase.getWidth()) - 0.5f;
+ final float relativeY = (MathUtils.bringToBounds(0, controlBase.getHeight(), pTouchAreaLocalY) / controlBase.getHeight()) - 0.5f;
this.onUpdateControlKnob(relativeX, relativeY);
}
/**
- * @param pRelativeX from -0.5 (left) to 0.5 (right).
- * @param pRelativeY from -0.5 (top) to 0.5 (bottom).
+ * @param pRelativeX from -0.5f (left) to 0.5 (right).
+ * @param pRelativeY from -0.5f (bottom) to 0.5f (top).
*/
protected void onUpdateControlKnob(final float pRelativeX, final float pRelativeY) {
final Sprite controlBase = this.mControlBase;
@@ -187,9 +184,8 @@ protected void onUpdateControlKnob(final float pRelativeX, final float pRelative
this.mControlValueX = 2 * pRelativeX;
this.mControlValueY = 2 * pRelativeY;
- final float[] controlBaseSceneCenterCoordinates = controlBase.getSceneCenterCoordinates();
- final float x = controlBaseSceneCenterCoordinates[VERTEX_INDEX_X] - controlKnob.getWidth() * 0.5f + pRelativeX * controlBase.getWidthScaled();
- final float y = controlBaseSceneCenterCoordinates[VERTEX_INDEX_Y] - controlKnob.getHeight() * 0.5f + pRelativeY * controlBase.getHeightScaled();
+ final float x = controlBase.getWidth() * (0.5f + pRelativeX);
+ final float y = controlBase.getHeight() * (0.5f + pRelativeY);
controlKnob.setPosition(x, y);
}
diff --git a/src/org/andengine/engine/camera/hud/controls/DigitalOnScreenControl.java b/src/org/andengine/engine/camera/hud/controls/DigitalOnScreenControl.java
index a4bf87c5d..818fe7010 100644
--- a/src/org/andengine/engine/camera/hud/controls/DigitalOnScreenControl.java
+++ b/src/org/andengine/engine/camera/hud/controls/DigitalOnScreenControl.java
@@ -6,9 +6,9 @@
import org.andengine.util.math.MathUtils;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 00:21:55 - 11.07.2010
*/
@@ -61,47 +61,47 @@ public void setAllowDiagonal(final boolean pAllowDiagonal) {
@Override
protected void onUpdateControlKnob(final float pRelativeX, final float pRelativeY) {
- if(pRelativeX == 0 && pRelativeY == 0) {
+ if (pRelativeX == 0 && pRelativeY == 0) {
super.onUpdateControlKnob(0, 0);
return;
}
- if(this.mAllowDiagonal) {
+ if (this.mAllowDiagonal) {
final float angle = MathUtils.radToDeg(MathUtils.atan2(pRelativeY, pRelativeX)) + 180;
- if(this.testDiagonalAngle(0, angle) || this.testDiagonalAngle(360, angle)) {
+ if (this.testDiagonalAngle(0, angle) || this.testDiagonalAngle(360, angle)) {
super.onUpdateControlKnob(-EXTENT_SIDE, 0);
- } else if(this.testDiagonalAngle(45, angle)) {
+ } else if (this.testDiagonalAngle(45, angle)) {
super.onUpdateControlKnob(-EXTENT_DIAGONAL, -EXTENT_DIAGONAL);
- } else if(this.testDiagonalAngle(90, angle)) {
+ } else if (this.testDiagonalAngle(90, angle)) {
super.onUpdateControlKnob(0, -EXTENT_SIDE);
- } else if(this.testDiagonalAngle(135, angle)) {
+ } else if (this.testDiagonalAngle(135, angle)) {
super.onUpdateControlKnob(EXTENT_DIAGONAL, -EXTENT_DIAGONAL);
- } else if(this.testDiagonalAngle(180, angle)) {
+ } else if (this.testDiagonalAngle(180, angle)) {
super.onUpdateControlKnob(EXTENT_SIDE, 0);
- } else if(this.testDiagonalAngle(225, angle)) {
+ } else if (this.testDiagonalAngle(225, angle)) {
super.onUpdateControlKnob(EXTENT_DIAGONAL, EXTENT_DIAGONAL);
- } else if(this.testDiagonalAngle(270, angle)) {
+ } else if (this.testDiagonalAngle(270, angle)) {
super.onUpdateControlKnob(0, EXTENT_SIDE);
- } else if(this.testDiagonalAngle(315, angle)) {
+ } else if (this.testDiagonalAngle(315, angle)) {
super.onUpdateControlKnob(-EXTENT_DIAGONAL, EXTENT_DIAGONAL);
} else {
super.onUpdateControlKnob(0, 0);
}
} else {
- if(Math.abs(pRelativeX) > Math.abs(pRelativeY)) {
- if(pRelativeX > 0) {
+ if (Math.abs(pRelativeX) > Math.abs(pRelativeY)) {
+ if (pRelativeX > 0) {
super.onUpdateControlKnob(EXTENT_SIDE, 0);
- } else if(pRelativeX < 0) {
+ } else if (pRelativeX < 0) {
super.onUpdateControlKnob(-EXTENT_SIDE, 0);
- } else if(pRelativeX == 0) {
+ } else if (pRelativeX == 0) {
super.onUpdateControlKnob(0, 0);
}
} else {
- if(pRelativeY > 0) {
+ if (pRelativeY > 0) {
super.onUpdateControlKnob(0, EXTENT_SIDE);
- } else if(pRelativeY < 0) {
+ } else if (pRelativeY < 0) {
super.onUpdateControlKnob(0, -EXTENT_SIDE);
- } else if(pRelativeY == 0) {
+ } else if (pRelativeY == 0) {
super.onUpdateControlKnob(0, 0);
}
}
diff --git a/src/org/andengine/engine/handler/BaseEntityUpdateHandler.java b/src/org/andengine/engine/handler/BaseEntityUpdateHandler.java
index 33c49e2ba..26883ea76 100644
--- a/src/org/andengine/engine/handler/BaseEntityUpdateHandler.java
+++ b/src/org/andengine/engine/handler/BaseEntityUpdateHandler.java
@@ -5,7 +5,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 14:00:25 - 24.12.2010
*/
diff --git a/src/org/andengine/engine/handler/DrawHandlerList.java b/src/org/andengine/engine/handler/DrawHandlerList.java
index 8d844a67e..cd1161376 100644
--- a/src/org/andengine/engine/handler/DrawHandlerList.java
+++ b/src/org/andengine/engine/handler/DrawHandlerList.java
@@ -5,7 +5,7 @@
import org.andengine.util.adt.list.SmartList;
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 17:42:49 - 22.11.2011
@@ -44,7 +44,7 @@ public DrawHandlerList(final int pCapacity) {
@Override
public void onDraw(final GLState pGLState, final Camera pCamera) {
final int handlerCount = this.size();
- for(int i = handlerCount - 1; i >= 0; i--) {
+ for (int i = handlerCount - 1; i >= 0; i--) {
this.get(i).onDraw(pGLState, pCamera);
}
}
diff --git a/src/org/andengine/engine/handler/IDrawHandler.java b/src/org/andengine/engine/handler/IDrawHandler.java
index d7d0ccfa5..c3d1fc5e9 100644
--- a/src/org/andengine/engine/handler/IDrawHandler.java
+++ b/src/org/andengine/engine/handler/IDrawHandler.java
@@ -5,9 +5,9 @@
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 10:50:58 - 08.08.2010
*/
diff --git a/src/org/andengine/engine/handler/IUpdateHandler.java b/src/org/andengine/engine/handler/IUpdateHandler.java
index a5378b11d..f9ac4927d 100644
--- a/src/org/andengine/engine/handler/IUpdateHandler.java
+++ b/src/org/andengine/engine/handler/IUpdateHandler.java
@@ -3,9 +3,9 @@
import org.andengine.util.IMatcher;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 12:24:09 - 11.03.2010
*/
@@ -20,13 +20,13 @@ public interface IUpdateHandler {
public void onUpdate(final float pSecondsElapsed);
public void reset();
-
+
// TODO Maybe add onRegister and onUnregister. (Maybe add SimpleUpdateHandler that implements all methods, but onUpdate)
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
-
+
public interface IUpdateHandlerMatcher extends IMatcher {
// ===========================================================
// Constants
diff --git a/src/org/andengine/engine/handler/UpdateHandlerList.java b/src/org/andengine/engine/handler/UpdateHandlerList.java
index e7676e36b..cad9a696d 100644
--- a/src/org/andengine/engine/handler/UpdateHandlerList.java
+++ b/src/org/andengine/engine/handler/UpdateHandlerList.java
@@ -3,9 +3,9 @@
import org.andengine.util.adt.list.SmartList;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 09:45:22 - 31.03.2010
*/
@@ -43,7 +43,7 @@ public UpdateHandlerList(final int pCapacity) {
@Override
public void onUpdate(final float pSecondsElapsed) {
final int handlerCount = this.size();
- for(int i = handlerCount - 1; i >= 0; i--) {
+ for (int i = handlerCount - 1; i >= 0; i--) {
this.get(i).onUpdate(pSecondsElapsed);
}
}
@@ -51,7 +51,7 @@ public void onUpdate(final float pSecondsElapsed) {
@Override
public void reset() {
final int handlerCount = this.size();
- for(int i = handlerCount - 1; i >= 0; i--) {
+ for (int i = handlerCount - 1; i >= 0; i--) {
this.get(i).reset();
}
}
diff --git a/src/org/andengine/engine/handler/collision/CollisionHandler.java b/src/org/andengine/engine/handler/collision/CollisionHandler.java
index dc8f5d84b..085c77a71 100644
--- a/src/org/andengine/engine/handler/collision/CollisionHandler.java
+++ b/src/org/andengine/engine/handler/collision/CollisionHandler.java
@@ -7,9 +7,9 @@
import org.andengine.util.adt.list.ListUtils;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 12:19:35 - 11.03.2010
*/
@@ -64,10 +64,10 @@ public void onUpdate(final float pSecondsElapsed) {
final ArrayList extends IShape> staticEntities = this.mTargetStaticEntities;
final int staticEntityCount = staticEntities.size();
- for(int i = 0; i < staticEntityCount; i++){
- if(checkShape.collidesWith(staticEntities.get(i))){
+ for (int i = 0; i < staticEntityCount; i++) {
+ if (checkShape.collidesWith(staticEntities.get(i))) {
final boolean proceed = this.mCollisionCallback.onCollision(checkShape, staticEntities.get(i));
- if(!proceed) {
+ if (!proceed) {
return;
}
}
diff --git a/src/org/andengine/engine/handler/collision/ICollisionCallback.java b/src/org/andengine/engine/handler/collision/ICollisionCallback.java
index ece85fcb2..c944609f2 100644
--- a/src/org/andengine/engine/handler/collision/ICollisionCallback.java
+++ b/src/org/andengine/engine/handler/collision/ICollisionCallback.java
@@ -3,9 +3,9 @@
import org.andengine.entity.shape.IShape;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 12:05:39 - 11.03.2010
*/
diff --git a/src/org/andengine/engine/handler/physics/PhysicsHandler.java b/src/org/andengine/engine/handler/physics/PhysicsHandler.java
index f1629060f..c95ddf1a3 100644
--- a/src/org/andengine/engine/handler/physics/PhysicsHandler.java
+++ b/src/org/andengine/engine/handler/physics/PhysicsHandler.java
@@ -4,9 +4,9 @@
import org.andengine.entity.IEntity;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 13:53:07 - 24.12.2010
*/
@@ -120,25 +120,25 @@ public void setAngularVelocity(final float pAngularVelocity) {
@Override
protected void onUpdate(final float pSecondsElapsed, final IEntity pEntity) {
- if(this.mEnabled) {
+ if (this.mEnabled) {
/* Apply linear acceleration. */
final float accelerationX = this.mAccelerationX;
final float accelerationY = this.mAccelerationY;
- if(accelerationX != 0 || accelerationY != 0) {
+ if (accelerationX != 0 || accelerationY != 0) {
this.mVelocityX += accelerationX * pSecondsElapsed;
this.mVelocityY += accelerationY * pSecondsElapsed;
}
/* Apply angular velocity. */
final float angularVelocity = this.mAngularVelocity;
- if(angularVelocity != 0) {
+ if (angularVelocity != 0) {
pEntity.setRotation(pEntity.getRotation() + angularVelocity * pSecondsElapsed);
}
/* Apply linear velocity. */
final float velocityX = this.mVelocityX;
final float velocityY = this.mVelocityY;
- if(velocityX != 0 || velocityY != 0) {
+ if (velocityX != 0 || velocityY != 0) {
pEntity.setPosition(pEntity.getX() + velocityX * pSecondsElapsed, pEntity.getY() + velocityY * pSecondsElapsed);
}
}
diff --git a/src/org/andengine/engine/handler/runnable/RunnableHandler.java b/src/org/andengine/engine/handler/runnable/RunnableHandler.java
index e82e4e05b..db7d3301d 100644
--- a/src/org/andengine/engine/handler/runnable/RunnableHandler.java
+++ b/src/org/andengine/engine/handler/runnable/RunnableHandler.java
@@ -5,9 +5,9 @@
import org.andengine.engine.handler.IUpdateHandler;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 10:24:39 - 18.06.2010
*/
@@ -38,7 +38,7 @@ public class RunnableHandler implements IUpdateHandler {
public synchronized void onUpdate(final float pSecondsElapsed) {
final ArrayList runnables = this.mRunnables;
final int runnableCount = runnables.size();
- for(int i = runnableCount - 1; i >= 0; i--) {
+ for (int i = runnableCount - 1; i >= 0; i--) {
runnables.get(i).run();
}
runnables.clear();
diff --git a/src/org/andengine/engine/handler/timer/ITimerCallback.java b/src/org/andengine/engine/handler/timer/ITimerCallback.java
index 14c45fd8d..2139ec622 100644
--- a/src/org/andengine/engine/handler/timer/ITimerCallback.java
+++ b/src/org/andengine/engine/handler/timer/ITimerCallback.java
@@ -1,9 +1,9 @@
package org.andengine.engine.handler.timer;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 16:23:25 - 12.03.2010
*/
diff --git a/src/org/andengine/engine/handler/timer/TimerHandler.java b/src/org/andengine/engine/handler/timer/TimerHandler.java
index bb7b16990..9b278632c 100644
--- a/src/org/andengine/engine/handler/timer/TimerHandler.java
+++ b/src/org/andengine/engine/handler/timer/TimerHandler.java
@@ -3,9 +3,9 @@
import org.andengine.engine.handler.IUpdateHandler;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 16:23:58 - 12.03.2010
*/
@@ -33,7 +33,7 @@ public TimerHandler(final float pTimerSeconds, final ITimerCallback pTimerCallba
}
public TimerHandler(final float pTimerSeconds, final boolean pAutoReset, final ITimerCallback pTimerCallback) {
- if(pTimerSeconds <= 0){
+ if (pTimerSeconds <= 0) {
throw new IllegalStateException("pTimerSeconds must be >= 0!");
}
@@ -65,7 +65,7 @@ public float getTimerSeconds() {
public float getTimerSecondsElapsed() {
return this.mTimerSecondsElapsed;
}
-
+
public boolean isTimerCallbackTriggered() {
return this.mTimerCallbackTriggered;
}
@@ -80,16 +80,16 @@ public void setTimerCallbackTriggered(boolean pTimerCallbackTriggered) {
@Override
public void onUpdate(final float pSecondsElapsed) {
- if(this.mAutoReset) {
+ if (this.mAutoReset) {
this.mTimerSecondsElapsed += pSecondsElapsed;
- while(this.mTimerSecondsElapsed >= this.mTimerSeconds) {
+ while (this.mTimerSecondsElapsed >= this.mTimerSeconds) {
this.mTimerSecondsElapsed -= this.mTimerSeconds;
this.mTimerCallback.onTimePassed(this);
}
} else {
- if(!this.mTimerCallbackTriggered) {
+ if (!this.mTimerCallbackTriggered) {
this.mTimerSecondsElapsed += pSecondsElapsed;
- if(this.mTimerSecondsElapsed >= this.mTimerSeconds) {
+ if (this.mTimerSecondsElapsed >= this.mTimerSeconds) {
this.mTimerCallbackTriggered = true;
this.mTimerCallback.onTimePassed(this);
}
diff --git a/src/org/andengine/engine/options/AudioOptions.java b/src/org/andengine/engine/options/AudioOptions.java
index 3dbfe3a73..53338c808 100644
--- a/src/org/andengine/engine/options/AudioOptions.java
+++ b/src/org/andengine/engine/options/AudioOptions.java
@@ -1,7 +1,7 @@
package org.andengine.engine.options;
-/**
- * (c) Zynga 2011
+/**
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 23:13:07 - 22.11.2011
diff --git a/src/org/andengine/engine/options/ConfigChooserOptions.java b/src/org/andengine/engine/options/ConfigChooserOptions.java
new file mode 100644
index 000000000..289c63c86
--- /dev/null
+++ b/src/org/andengine/engine/options/ConfigChooserOptions.java
@@ -0,0 +1,117 @@
+package org.andengine.engine.options;
+
+/**
+ * (c) 2012 Zynga Inc.
+ *
+ * @author Nicolas Gramlich
+ * @since 16:01:53 - 12.05.2012
+ */
+public class ConfigChooserOptions {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ private static final int RED_SIZE_DEFAULT = 5;
+ private static final int GREEN_SIZE_DEFAULT = 6;
+ private static final int BLUE_SIZE_DEFAULT = 5;
+ private static final int DEPTH_SIZE_DEFAULT = 0;
+ private static final int ALPHA_SIZE_DEFAULT = 0;
+ private static final int STENCIL_SIZE_DEFAULT = 0;
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ private boolean mRequestedMultiSampling;
+
+ private int mRequestedRedSize = ConfigChooserOptions.RED_SIZE_DEFAULT;
+ private int mRequestedGreenSize = ConfigChooserOptions.GREEN_SIZE_DEFAULT;
+ private int mRequestedBlueSize = ConfigChooserOptions.BLUE_SIZE_DEFAULT;
+ private int mRequestedAlphaSize = ConfigChooserOptions.ALPHA_SIZE_DEFAULT;
+ private int mRequestedDepthSize = ConfigChooserOptions.DEPTH_SIZE_DEFAULT;
+ private int mRequestedStencilSize = ConfigChooserOptions.STENCIL_SIZE_DEFAULT;
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ public boolean isRequestedMultiSampling() {
+ return this.mRequestedMultiSampling;
+ }
+
+ public void setRequestedMultiSampling(final boolean pRequestedMultiSampling) {
+ this.mRequestedMultiSampling = pRequestedMultiSampling;
+ }
+
+ public int getRequestedRedSize() {
+ return this.mRequestedRedSize;
+ }
+
+ public void setRequestedRedSize(final int pRequestedRedSize) {
+ this.mRequestedRedSize = pRequestedRedSize;
+ }
+
+ public int getRequestedGreenSize() {
+ return this.mRequestedGreenSize;
+ }
+
+ public void setRequestedGreenSize(final int pRequestedGreenSize) {
+ this.mRequestedGreenSize = pRequestedGreenSize;
+ }
+
+ public int getRequestedBlueSize() {
+ return this.mRequestedBlueSize;
+ }
+
+ public void setRequestedBlueSize(final int pRequestedBlueSize) {
+ this.mRequestedBlueSize = pRequestedBlueSize;
+ }
+
+ public int getRequestedAlphaSize() {
+ return this.mRequestedAlphaSize;
+ }
+
+ public void setRequestedAlphaSize(final int pRequestedAlphaSize) {
+ this.mRequestedAlphaSize = pRequestedAlphaSize;
+ }
+
+ public int getRequestedDepthSize() {
+ return this.mRequestedDepthSize;
+ }
+
+ public void setRequestedDepthSize(final int pRequestedDepthSize) {
+ this.mRequestedDepthSize = pRequestedDepthSize;
+ }
+
+ public int getRequestedStencilSize() {
+ return this.mRequestedStencilSize;
+ }
+
+ public void setRequestedStencilSize(final int pRequestedStencilSize) {
+ this.mRequestedStencilSize = pRequestedStencilSize;
+ }
+
+ public boolean isRequestedRGBA8888() {
+ return (this.mRequestedRedSize == 8) && (this.mRequestedGreenSize == 8) && (this.mRequestedBlueSize == 8) && (this.mRequestedAlphaSize == 8);
+ }
+
+ public boolean isRequestedRGB565() {
+ return (this.mRequestedRedSize == 5) && (this.mRequestedGreenSize == 6) && (this.mRequestedBlueSize == 5) && (this.mRequestedAlphaSize == 0);
+ }
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
diff --git a/src/org/andengine/engine/options/EngineOptions.java b/src/org/andengine/engine/options/EngineOptions.java
index 2eae1c417..e3a55cfc8 100644
--- a/src/org/andengine/engine/options/EngineOptions.java
+++ b/src/org/andengine/engine/options/EngineOptions.java
@@ -8,7 +8,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:59:52 - 09.03.2010
*/
diff --git a/src/org/andengine/engine/options/MusicOptions.java b/src/org/andengine/engine/options/MusicOptions.java
index bf12cfbf1..a2faf2eb1 100644
--- a/src/org/andengine/engine/options/MusicOptions.java
+++ b/src/org/andengine/engine/options/MusicOptions.java
@@ -2,7 +2,7 @@
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 23:13:07 - 22.11.2011
diff --git a/src/org/andengine/engine/options/RenderOptions.java b/src/org/andengine/engine/options/RenderOptions.java
index c8738f4f2..fadd067c4 100644
--- a/src/org/andengine/engine/options/RenderOptions.java
+++ b/src/org/andengine/engine/options/RenderOptions.java
@@ -3,7 +3,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 13:01:40 - 02.07.2010
*/
@@ -16,8 +16,9 @@ public class RenderOptions {
// Fields
// ===========================================================
- private boolean mMultiSampling = false;
- private boolean mDithering = false;
+ private boolean mDithering;
+
+ private ConfigChooserOptions mConfigChooserOptions = new ConfigChooserOptions();
// ===========================================================
// Constructors
@@ -27,14 +28,6 @@ public class RenderOptions {
// Getter & Setter
// ===========================================================
- public boolean isMultiSampling() {
- return this.mMultiSampling;
- }
-
- public void setMultiSampling(final boolean pMultiSampling) {
- this.mMultiSampling = pMultiSampling;
- }
-
public boolean isDithering() {
return this.mDithering;
}
@@ -43,6 +36,10 @@ public void setDithering(final boolean pDithering) {
this.mDithering = pDithering;
}
+ public ConfigChooserOptions getConfigChooserOptions() {
+ return this.mConfigChooserOptions;
+ }
+
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
diff --git a/src/org/andengine/engine/options/ScreenOrientation.java b/src/org/andengine/engine/options/ScreenOrientation.java
index 6a6d218bf..2521e0311 100644
--- a/src/org/andengine/engine/options/ScreenOrientation.java
+++ b/src/org/andengine/engine/options/ScreenOrientation.java
@@ -1,7 +1,7 @@
package org.andengine.engine.options;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 16:48:03 - 04.04.2012
diff --git a/src/org/andengine/engine/options/SoundOptions.java b/src/org/andengine/engine/options/SoundOptions.java
index a58ac3b0e..397fdb128 100644
--- a/src/org/andengine/engine/options/SoundOptions.java
+++ b/src/org/andengine/engine/options/SoundOptions.java
@@ -3,7 +3,7 @@
import org.andengine.audio.sound.SoundManager;
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 23:13:07 - 22.11.2011
diff --git a/src/org/andengine/engine/options/TouchOptions.java b/src/org/andengine/engine/options/TouchOptions.java
index 4b031e547..4c26eac42 100644
--- a/src/org/andengine/engine/options/TouchOptions.java
+++ b/src/org/andengine/engine/options/TouchOptions.java
@@ -1,7 +1,7 @@
package org.andengine.engine.options;
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 23:18:06 - 22.11.2011
diff --git a/src/org/andengine/engine/options/WakeLockOptions.java b/src/org/andengine/engine/options/WakeLockOptions.java
index 8d007ac83..efd295bdf 100644
--- a/src/org/andengine/engine/options/WakeLockOptions.java
+++ b/src/org/andengine/engine/options/WakeLockOptions.java
@@ -3,9 +3,9 @@
import android.os.PowerManager;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 19:45:23 - 10.07.2010
*/
diff --git a/src/org/andengine/engine/options/resolutionpolicy/BaseResolutionPolicy.java b/src/org/andengine/engine/options/resolutionpolicy/BaseResolutionPolicy.java
index 40abb95c9..6cfad8583 100644
--- a/src/org/andengine/engine/options/resolutionpolicy/BaseResolutionPolicy.java
+++ b/src/org/andengine/engine/options/resolutionpolicy/BaseResolutionPolicy.java
@@ -3,9 +3,9 @@
import android.view.View.MeasureSpec;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 22:46:43 - 06.10.2010
*/
diff --git a/src/org/andengine/engine/options/resolutionpolicy/FillResolutionPolicy.java b/src/org/andengine/engine/options/resolutionpolicy/FillResolutionPolicy.java
index b9b062306..874b714e8 100644
--- a/src/org/andengine/engine/options/resolutionpolicy/FillResolutionPolicy.java
+++ b/src/org/andengine/engine/options/resolutionpolicy/FillResolutionPolicy.java
@@ -1,13 +1,11 @@
package org.andengine.engine.options.resolutionpolicy;
-import org.andengine.opengl.view.RenderSurfaceView;
-
import android.view.View.MeasureSpec;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 11:22:48 - 29.03.2010
*/
@@ -33,13 +31,13 @@ public class FillResolutionPolicy extends BaseResolutionPolicy {
// ===========================================================
@Override
- public void onMeasure(final RenderSurfaceView pRenderSurfaceView, final int pWidthMeasureSpec, final int pHeightMeasureSpec) {
+ public void onMeasure(final IResolutionPolicy.Callback pResolutionPolicyCallback, final int pWidthMeasureSpec, final int pHeightMeasureSpec) {
BaseResolutionPolicy.throwOnNotMeasureSpecEXACTLY(pWidthMeasureSpec, pHeightMeasureSpec);
final int measuredWidth = MeasureSpec.getSize(pWidthMeasureSpec);
final int measuredHeight = MeasureSpec.getSize(pHeightMeasureSpec);
- pRenderSurfaceView.setMeasuredDimensionProxy(measuredWidth, measuredHeight);
+ pResolutionPolicyCallback.onResolutionChanged(measuredWidth, measuredHeight);
}
// ===========================================================
diff --git a/src/org/andengine/engine/options/resolutionpolicy/FixedResolutionPolicy.java b/src/org/andengine/engine/options/resolutionpolicy/FixedResolutionPolicy.java
index 4d823ffd2..f64ca3dfe 100644
--- a/src/org/andengine/engine/options/resolutionpolicy/FixedResolutionPolicy.java
+++ b/src/org/andengine/engine/options/resolutionpolicy/FixedResolutionPolicy.java
@@ -1,11 +1,10 @@
package org.andengine.engine.options.resolutionpolicy;
-import org.andengine.opengl.view.RenderSurfaceView;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 11:23:00 - 29.03.2010
*/
@@ -39,8 +38,8 @@ public FixedResolutionPolicy(final int pWidth, final int pHeight) {
// ===========================================================
@Override
- public void onMeasure(final RenderSurfaceView pRenderSurfaceView, final int pWidthMeasureSpec, final int pHeightMeasureSpec) {
- pRenderSurfaceView.setMeasuredDimensionProxy(this.mWidth, this.mHeight);
+ public void onMeasure(final IResolutionPolicy.Callback pResolutionPolicyCallback, final int pWidthMeasureSpec, final int pHeightMeasureSpec) {
+ pResolutionPolicyCallback.onResolutionChanged(this.mWidth, this.mHeight);
}
// ===========================================================
diff --git a/src/org/andengine/engine/options/resolutionpolicy/IResolutionPolicy.java b/src/org/andengine/engine/options/resolutionpolicy/IResolutionPolicy.java
index 4e8884f70..6d0ded3da 100644
--- a/src/org/andengine/engine/options/resolutionpolicy/IResolutionPolicy.java
+++ b/src/org/andengine/engine/options/resolutionpolicy/IResolutionPolicy.java
@@ -1,11 +1,10 @@
package org.andengine.engine.options.resolutionpolicy;
-import org.andengine.opengl.view.RenderSurfaceView;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 11:02:35 - 29.03.2010
*/
@@ -18,5 +17,21 @@ public interface IResolutionPolicy {
// Methods
// ===========================================================
- public void onMeasure(final RenderSurfaceView pRenderSurfaceView, final int pWidthMeasureSpec, final int pHeightMeasureSpec);
+ public void onMeasure(final IResolutionPolicy.Callback pResolutionPolicyCallback, final int pWidthMeasureSpec, final int pHeightMeasureSpec);
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+
+ public static interface Callback {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ public void onResolutionChanged(final int pWidth, final int pHeight);
+ }
}
diff --git a/src/org/andengine/engine/options/resolutionpolicy/RatioResolutionPolicy.java b/src/org/andengine/engine/options/resolutionpolicy/RatioResolutionPolicy.java
index 46ffa5b95..57f86e7ac 100644
--- a/src/org/andengine/engine/options/resolutionpolicy/RatioResolutionPolicy.java
+++ b/src/org/andengine/engine/options/resolutionpolicy/RatioResolutionPolicy.java
@@ -1,13 +1,11 @@
package org.andengine.engine.options.resolutionpolicy;
-import org.andengine.opengl.view.RenderSurfaceView;
-
import android.view.View.MeasureSpec;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 11:23:00 - 29.03.2010
*/
@@ -43,18 +41,18 @@ public RatioResolutionPolicy(final float pWidthRatio, final float pHeightRatio)
// ===========================================================
@Override
- public void onMeasure(final RenderSurfaceView pRenderSurfaceView, final int pWidthMeasureSpec, final int pHeightMeasureSpec) {
+ public void onMeasure(final IResolutionPolicy.Callback pResolutionPolicyCallback, final int pWidthMeasureSpec, final int pHeightMeasureSpec) {
BaseResolutionPolicy.throwOnNotMeasureSpecEXACTLY(pWidthMeasureSpec, pHeightMeasureSpec);
final int specWidth = MeasureSpec.getSize(pWidthMeasureSpec);
final int specHeight = MeasureSpec.getSize(pHeightMeasureSpec);
final float desiredRatio = this.mRatio;
- final float realRatio = (float)specWidth / specHeight;
+ final float realRatio = ((float) specWidth) / specHeight;
int measuredWidth;
int measuredHeight;
- if(realRatio < desiredRatio) {
+ if (realRatio < desiredRatio) {
measuredWidth = specWidth;
measuredHeight = Math.round(measuredWidth / desiredRatio);
} else {
@@ -62,7 +60,7 @@ public void onMeasure(final RenderSurfaceView pRenderSurfaceView, final int pWid
measuredWidth = Math.round(measuredHeight * desiredRatio);
}
- pRenderSurfaceView.setMeasuredDimensionProxy(measuredWidth, measuredHeight);
+ pResolutionPolicyCallback.onResolutionChanged(measuredWidth, measuredHeight);
}
// ===========================================================
diff --git a/src/org/andengine/engine/options/resolutionpolicy/RelativeResolutionPolicy.java b/src/org/andengine/engine/options/resolutionpolicy/RelativeResolutionPolicy.java
index 6ed0ec232..c84f24c0b 100644
--- a/src/org/andengine/engine/options/resolutionpolicy/RelativeResolutionPolicy.java
+++ b/src/org/andengine/engine/options/resolutionpolicy/RelativeResolutionPolicy.java
@@ -1,13 +1,11 @@
package org.andengine.engine.options.resolutionpolicy;
-import org.andengine.opengl.view.RenderSurfaceView;
-
import android.view.View.MeasureSpec;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 11:23:00 - 29.03.2010
*/
@@ -45,13 +43,13 @@ public RelativeResolutionPolicy(final float pWidthScale, final float pHeightScal
// ===========================================================
@Override
- public void onMeasure(final RenderSurfaceView pRenderSurfaceView, final int pWidthMeasureSpec, final int pHeightMeasureSpec) {
+ public void onMeasure(final IResolutionPolicy.Callback pResolutionPolicyCallback, final int pWidthMeasureSpec, final int pHeightMeasureSpec) {
BaseResolutionPolicy.throwOnNotMeasureSpecEXACTLY(pWidthMeasureSpec, pHeightMeasureSpec);
- final int measuredWidth = (int)(MeasureSpec.getSize(pWidthMeasureSpec) * this.mWidthScale);
- final int measuredHeight = (int)(MeasureSpec.getSize(pHeightMeasureSpec) * this.mHeightScale);
+ final int measuredWidth = (int) (MeasureSpec.getSize(pWidthMeasureSpec) * this.mWidthScale);
+ final int measuredHeight = (int) (MeasureSpec.getSize(pHeightMeasureSpec) * this.mHeightScale);
- pRenderSurfaceView.setMeasuredDimensionProxy(measuredWidth, measuredHeight);
+ pResolutionPolicyCallback.onResolutionChanged(measuredWidth, measuredHeight);
}
// ===========================================================
diff --git a/src/org/andengine/engine/splitscreen/DoubleSceneSplitScreenEngine.java b/src/org/andengine/engine/splitscreen/DoubleSceneSplitScreenEngine.java
index c52fefc79..151bf6808 100644
--- a/src/org/andengine/engine/splitscreen/DoubleSceneSplitScreenEngine.java
+++ b/src/org/andengine/engine/splitscreen/DoubleSceneSplitScreenEngine.java
@@ -10,9 +10,9 @@
import android.opengl.GLES20;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 22:28:34 - 27.03.2010
*/
@@ -41,6 +41,9 @@ public DoubleSceneSplitScreenEngine(final EngineOptions pEngineOptions, final Ca
// Getter & Setter
// ===========================================================
+ /**
+ * @deprecated Instead use {@link #getFirstCamera()} or {@link #getSecondCamera()}.
+ */
@Deprecated
@Override
public Camera getCamera() {
@@ -55,6 +58,9 @@ public Camera getSecondCamera() {
return this.mSecondCamera;
}
+ /**
+ * @deprecated Instead use {@link #getFirstCamera()} or {@link #getSecondScene()}.
+ */
@Deprecated
@Override
public Scene getScene() {
@@ -69,6 +75,9 @@ public Scene getSecondScene() {
return this.mSecondScene;
}
+ /**
+ * @deprecated Instead use {@link #setFirstScene(Scene)} or {@link #setSecondScene(Scene)}.
+ */
@Deprecated
@Override
public void setScene(final Scene pScene) {
@@ -87,6 +96,17 @@ public void setSecondScene(final Scene pScene) {
// Methods for/from SuperClass/Interfaces
// ===========================================================
+ @Override
+ protected void onUpdateScene(final float pSecondsElapsed) {
+ super.onUpdateScene(pSecondsElapsed);
+
+ if (this.mSecondScene != null) {
+ this.mSecondScene.onUpdate(pSecondsElapsed);
+ }
+
+ this.getSecondCamera().onUpdate(pSecondsElapsed);
+ }
+
@Override
protected void onDrawScene(final GLState pGLState, final Camera pFirstCamera) {
final Camera secondCamera = this.getSecondCamera();
@@ -99,7 +119,7 @@ protected void onDrawScene(final GLState pGLState, final Camera pFirstCamera) {
pGLState.enableScissorTest();
/* First Screen. With first camera, on the left half of the screens width. */
- if(super.mScene != null) {
+ if (super.mScene != null) {
GLES20.glScissor(0, 0, surfaceWidthHalf, surfaceHeight);
GLES20.glViewport(0, 0, surfaceWidthHalf, surfaceHeight);
@@ -108,7 +128,7 @@ protected void onDrawScene(final GLState pGLState, final Camera pFirstCamera) {
}
/* Second Screen. With second camera, on the right half of the screens width. */
- if(this.mSecondScene != null) {
+ if (this.mSecondScene != null) {
GLES20.glScissor(surfaceWidthHalf, 0, surfaceWidthHalf, surfaceHeight);
GLES20.glViewport(surfaceWidthHalf, 0, surfaceWidthHalf, surfaceHeight);
@@ -121,7 +141,7 @@ protected void onDrawScene(final GLState pGLState, final Camera pFirstCamera) {
@Override
protected Camera getCameraFromSurfaceTouchEvent(final TouchEvent pTouchEvent) {
- if(pTouchEvent.getX() <= this.mSurfaceWidth >> 1) {
+ if (pTouchEvent.getX() <= this.mSurfaceWidth >> 1) {
return this.getFirstCamera();
} else {
return this.getSecondCamera();
@@ -130,7 +150,7 @@ protected Camera getCameraFromSurfaceTouchEvent(final TouchEvent pTouchEvent) {
@Override
protected Scene getSceneFromSurfaceTouchEvent(final TouchEvent pTouchEvent) {
- if(pTouchEvent.getX() <= this.mSurfaceWidth >> 1) {
+ if (pTouchEvent.getX() <= this.mSurfaceWidth >> 1) {
return this.getFirstScene();
} else {
return this.getSecondScene();
@@ -138,31 +158,17 @@ protected Scene getSceneFromSurfaceTouchEvent(final TouchEvent pTouchEvent) {
}
@Override
- protected void onUpdateScene(final float pSecondsElapsed) {
- super.onUpdateScene(pSecondsElapsed);
- if(this.mSecondScene != null) {
- this.mSecondScene.onUpdate(pSecondsElapsed);
- }
- }
-
- @Override
- protected void convertSurfaceToSceneTouchEvent(final Camera pCamera, final TouchEvent pSurfaceTouchEvent) {
+ protected void convertSurfaceTouchEventToSceneTouchEvent(final Camera pCamera, final TouchEvent pSurfaceTouchEvent) {
final int surfaceWidthHalf = this.mSurfaceWidth >> 1;
- if(pCamera == this.getFirstCamera()) {
- pCamera.convertSurfaceToSceneTouchEvent(pSurfaceTouchEvent, surfaceWidthHalf, this.mSurfaceHeight);
+ if (pCamera == this.getFirstCamera()) {
+ pCamera.convertSurfaceTouchEventToSceneTouchEvent(pSurfaceTouchEvent, surfaceWidthHalf, this.mSurfaceHeight);
} else {
pSurfaceTouchEvent.offset(-surfaceWidthHalf, 0);
- pCamera.convertSurfaceToSceneTouchEvent(pSurfaceTouchEvent, surfaceWidthHalf, this.mSurfaceHeight);
+ pCamera.convertSurfaceTouchEventToSceneTouchEvent(pSurfaceTouchEvent, surfaceWidthHalf, this.mSurfaceHeight);
}
}
- @Override
- protected void onUpdateUpdateHandlers(final float pSecondsElapsed) {
- super.onUpdateUpdateHandlers(pSecondsElapsed);
- this.getSecondCamera().onUpdate(pSecondsElapsed);
- }
-
@Override
protected void onUpdateCameraSurface() {
final int surfaceWidth = this.mSurfaceWidth;
diff --git a/src/org/andengine/engine/splitscreen/SingleSceneSplitScreenEngine.java b/src/org/andengine/engine/splitscreen/SingleSceneSplitScreenEngine.java
index c8df8605a..c10e2da83 100644
--- a/src/org/andengine/engine/splitscreen/SingleSceneSplitScreenEngine.java
+++ b/src/org/andengine/engine/splitscreen/SingleSceneSplitScreenEngine.java
@@ -9,9 +9,9 @@
import android.opengl.GLES20;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 22:28:34 - 27.03.2010
*/
@@ -39,6 +39,9 @@ public SingleSceneSplitScreenEngine(final EngineOptions pEngineOptions, final Ca
// Getter & Setter
// ===========================================================
+ /**
+ * @deprecated Instead use {@link #getFirstCamera()} or {@link #getSecondCamera()}.
+ */
@Deprecated
@Override
public Camera getCamera() {
@@ -57,43 +60,50 @@ public Camera getSecondCamera() {
// Methods for/from SuperClass/Interfaces
// ===========================================================
+ @Override
+ protected void onUpdateScene(final float pSecondsElapsed) {
+ super.onUpdateScene(pSecondsElapsed);
+
+ this.getSecondCamera().onUpdate(pSecondsElapsed);
+ }
+
@Override
protected void onDrawScene(final GLState pGLState, final Camera pFirstCamera) {
- if(super.mScene != null) {
+ if (super.mScene != null) {
final Camera secondCamera = this.getSecondCamera();
-
+
final int surfaceWidth = this.mSurfaceWidth;
final int surfaceWidthHalf = surfaceWidth >> 1;
-
+
final int surfaceHeight = this.mSurfaceHeight;
-
+
pGLState.enableScissorTest();
-
+
/* First Screen. With first camera, on the left half of the screens width. */
{
GLES20.glScissor(0, 0, surfaceWidthHalf, surfaceHeight);
GLES20.glViewport(0, 0, surfaceWidthHalf, surfaceHeight);
-
+
super.mScene.onDraw(pGLState, pFirstCamera);
pFirstCamera.onDrawHUD(pGLState);
}
-
+
/* Second Screen. With second camera, on the right half of the screens width. */
{
GLES20.glScissor(surfaceWidthHalf, 0, surfaceWidthHalf, surfaceHeight);
GLES20.glViewport(surfaceWidthHalf, 0, surfaceWidthHalf, surfaceHeight);
-
+
super.mScene.onDraw(pGLState, secondCamera);
secondCamera.onDrawHUD(pGLState);
}
-
+
pGLState.disableScissorTest();
}
}
@Override
protected Camera getCameraFromSurfaceTouchEvent(final TouchEvent pTouchEvent) {
- if(pTouchEvent.getX() <= this.mSurfaceWidth >> 1) {
+ if (pTouchEvent.getX() <= this.mSurfaceWidth >> 1) {
return this.getFirstCamera();
} else {
return this.getSecondCamera();
@@ -101,23 +111,17 @@ protected Camera getCameraFromSurfaceTouchEvent(final TouchEvent pTouchEvent) {
}
@Override
- protected void convertSurfaceToSceneTouchEvent(final Camera pCamera, final TouchEvent pSurfaceTouchEvent) {
+ protected void convertSurfaceTouchEventToSceneTouchEvent(final Camera pCamera, final TouchEvent pSurfaceTouchEvent) {
final int surfaceWidthHalf = this.mSurfaceWidth >> 1;
- if(pCamera == this.getFirstCamera()) {
- pCamera.convertSurfaceToSceneTouchEvent(pSurfaceTouchEvent, surfaceWidthHalf, this.mSurfaceHeight);
+ if (pCamera == this.getFirstCamera()) {
+ pCamera.convertSurfaceTouchEventToSceneTouchEvent(pSurfaceTouchEvent, surfaceWidthHalf, this.mSurfaceHeight);
} else {
pSurfaceTouchEvent.offset(-surfaceWidthHalf, 0);
- pCamera.convertSurfaceToSceneTouchEvent(pSurfaceTouchEvent, surfaceWidthHalf, this.mSurfaceHeight);
+ pCamera.convertSurfaceTouchEventToSceneTouchEvent(pSurfaceTouchEvent, surfaceWidthHalf, this.mSurfaceHeight);
}
}
- @Override
- protected void onUpdateUpdateHandlers(final float pSecondsElapsed) {
- super.onUpdateUpdateHandlers(pSecondsElapsed);
- this.getSecondCamera().onUpdate(pSecondsElapsed);
- }
-
@Override
protected void onUpdateCameraSurface() {
final int surfaceWidth = this.mSurfaceWidth;
diff --git a/src/org/andengine/entity/Entity.java b/src/org/andengine/entity/Entity.java
index 8716fa98a..dbfc92b69 100644
--- a/src/org/andengine/entity/Entity.java
+++ b/src/org/andengine/entity/Entity.java
@@ -9,18 +9,22 @@
import org.andengine.entity.modifier.EntityModifierList;
import org.andengine.entity.modifier.IEntityModifier;
import org.andengine.entity.modifier.IEntityModifier.IEntityModifierMatcher;
+import org.andengine.entity.primitive.Line;
+import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.util.GLState;
import org.andengine.util.Constants;
+import org.andengine.util.adt.color.Color;
+import org.andengine.util.adt.color.ColorUtils;
import org.andengine.util.adt.list.SmartList;
import org.andengine.util.adt.transformation.Transformation;
+import org.andengine.util.algorithm.collision.EntityCollisionChecker;
import org.andengine.util.call.ParameterCallable;
-import org.andengine.util.color.Color;
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 12:00:48 - 08.03.2010
*/
@@ -35,6 +39,8 @@ public class Entity implements IEntity {
private static final float[] VERTICES_SCENE_TO_LOCAL_TMP = new float[2];
private static final float[] VERTICES_LOCAL_TO_SCENE_TMP = new float[2];
+ private static final float[] VERTICES_PARENT_TO_LOCAL_TMP = new float[2];
+ private static final float[] VERTICES_LOCAL_TO_PARENT_TMP = new float[2];
private static final ParameterCallable PARAMETERCALLABLE_DETACHCHILD = new ParameterCallable() {
@Override
@@ -56,9 +62,9 @@ public void call(final IEntity pEntity) {
protected boolean mChildrenIgnoreUpdate;
protected boolean mChildrenSortPending;
- protected int mTag = IEntity.TAG_INVALID;
+ protected int mTag = IEntity.TAG_DEFAULT;
- protected int mZIndex = 0;
+ protected int mZIndex = IEntity.ZINDEX_DEFAULT;
private IEntity mParent;
@@ -66,27 +72,41 @@ public void call(final IEntity pEntity) {
private EntityModifierList mEntityModifiers;
private UpdateHandlerList mUpdateHandlers;
- protected Color mColor = new Color(1, 1, 1, 1);
+ protected Color mColor = new Color(Color.WHITE);
protected float mX;
protected float mY;
- protected float mRotation = 0;
+ protected float mOffsetCenterX = IEntity.OFFSET_CENTER_X_DEFAULT;
+ protected float mOffsetCenterY = IEntity.OFFSET_CENTER_Y_DEFAULT;
+ protected float mLocalOffsetCenterX;
+ protected float mLocalOffsetCenterY;
- protected float mRotationCenterX = 0;
- protected float mRotationCenterY = 0;
+ protected float mWidth;
+ protected float mHeight;
- protected float mScaleX = 1;
- protected float mScaleY = 1;
+ protected float mRotation = IEntity.ROTATION_DEFAULT;
- protected float mScaleCenterX = 0;
- protected float mScaleCenterY = 0;
+ protected float mRotationCenterX = IEntity.ROTATION_CENTER_X_DEFAULT;
+ protected float mRotationCenterY = IEntity.ROTATION_CENTER_Y_DEFAULT;
+ protected float mLocalRotationCenterX;
+ protected float mLocalRotationCenterY;
- protected float mSkewX = 0;
- protected float mSkewY = 0;
+ protected float mScaleX = IEntity.SCALE_X_DEFAULT;
+ protected float mScaleY = IEntity.SCALE_Y_DEFAULT;
- protected float mSkewCenterX = 0;
- protected float mSkewCenterY = 0;
+ protected float mScaleCenterX = IEntity.SCALE_CENTER_X_DEFAULT;
+ protected float mScaleCenterY = IEntity.SCALE_CENTER_Y_DEFAULT;
+ protected float mLocalScaleCenterX;
+ protected float mLocalScaleCenterY;
+
+ protected float mSkewX = IEntity.SKEW_X_DEFAULT;
+ protected float mSkewY = IEntity.SKEW_Y_DEFAULT;
+
+ protected float mSkewCenterX = IEntity.SKEW_CENTER_X_DEFAULT;
+ protected float mSkewCenterY = IEntity.SKEW_CENTER_Y_DEFAULT;
+ protected float mLocalSkewCenterX;
+ protected float mLocalSkewCenterY;
private boolean mLocalToParentTransformationDirty = true;
private boolean mParentToLocalTransformationDirty = true;
@@ -108,8 +128,17 @@ public Entity() {
}
public Entity(final float pX, final float pY) {
+ this(pX, pY, 0, 0);
+ }
+
+ public Entity(final float pX, final float pY, final float pWidth, final float pHeight) {
this.mX = pX;
this.mY = pY;
+
+ this.mWidth = pWidth;
+ this.mHeight = pHeight;
+
+ this.updateLocalCenters();
}
// ===========================================================
@@ -151,6 +180,25 @@ public void setCullingEnabled(final boolean pCullingEnabled) {
@Override
public boolean isCulled(final Camera pCamera) {
+ return !EntityCollisionChecker.isVisible(pCamera, this);
+ }
+
+ @Override
+ public boolean collidesWith(final IEntity pOtherEntity) {
+ if (pOtherEntity instanceof Line) {
+ return EntityCollisionChecker.checkCollision(this, (Line) pOtherEntity);
+ } else {
+ return EntityCollisionChecker.checkCollision(this, pOtherEntity);
+ }
+ }
+
+ @Override
+ public boolean contains(final float pX, final float pY) {
+ return EntityCollisionChecker.checkContains(this, pX, pY);
+ }
+
+ @Override
+ public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
return false;
}
@@ -199,6 +247,17 @@ public void setParent(final IEntity pEntity) {
this.mParent = pEntity;
}
+ @Override
+ public IEntity getRootEntity() {
+ IEntity rootEntity = this;
+
+ while (rootEntity.hasParent()) {
+ rootEntity = rootEntity.getParent();
+ }
+
+ return rootEntity;
+ }
+
@Override
public int getTag() {
return this.mTag;
@@ -259,6 +318,91 @@ public void setPosition(final float pX, final float pY) {
this.mParentToLocalTransformationDirty = true;
}
+ @Override
+ public float getWidth() {
+ return this.mWidth;
+ }
+
+ @Deprecated
+ @Override
+ public float getWidthScaled() {
+ return this.mWidth * this.mScaleX;
+ }
+
+ @Override
+ public void setWidth(final float pWidth) {
+ this.mWidth = pWidth;
+
+ this.updateLocalCenterXs();
+ }
+
+ @Override
+ public float getHeight() {
+ return this.mHeight;
+ }
+
+ @Deprecated
+ @Override
+ public float getHeightScaled() {
+ return this.mHeight * this.mScaleY;
+ }
+
+ @Override
+ public void setHeight(final float pHeight) {
+ this.mHeight = pHeight;
+
+ this.updateLocalCenterYs();
+ }
+
+ @Override
+ public void setSize(final float pWidth, final float pHeight) {
+ this.mWidth = pWidth;
+ this.mHeight = pHeight;
+
+ this.updateLocalCenters();
+ }
+
+ @Override
+ public float getOffsetCenterX() {
+ return this.mOffsetCenterX;
+ }
+
+ @Override
+ public float getOffsetCenterY() {
+ return this.mOffsetCenterY;
+ }
+
+ @Override
+ public void setOffsetCenterX(final float pOffsetCenterX) {
+ this.mOffsetCenterX = pOffsetCenterX;
+
+ this.updateLocalOffsetCenterX();
+
+ this.mLocalToParentTransformationDirty = true;
+ this.mParentToLocalTransformationDirty = true;
+ }
+
+ @Override
+ public void setOffsetCenterY(final float pOffsetCenterY) {
+ this.mOffsetCenterY = pOffsetCenterY;
+
+ this.updateLocalOffsetCenterY();
+
+ this.mLocalToParentTransformationDirty = true;
+ this.mParentToLocalTransformationDirty = true;
+ }
+
+ @Override
+ public void setOffsetCenter(final float pOffsetCenterX, final float pOffsetCenterY) {
+ this.mOffsetCenterX = pOffsetCenterX;
+ this.mOffsetCenterY = pOffsetCenterY;
+
+ this.updateLocalOffsetCenter();
+
+ this.mLocalToParentTransformationDirty = true;
+ this.mParentToLocalTransformationDirty = true;
+ }
+
@Override
public float getRotation() {
return this.mRotation;
@@ -291,6 +435,8 @@ public float getRotationCenterY() {
public void setRotationCenterX(final float pRotationCenterX) {
this.mRotationCenterX = pRotationCenterX;
+ this.updateLocalRotationCenterX();
+
this.mLocalToParentTransformationDirty = true;
this.mParentToLocalTransformationDirty = true;
}
@@ -299,6 +445,8 @@ public void setRotationCenterX(final float pRotationCenterX) {
public void setRotationCenterY(final float pRotationCenterY) {
this.mRotationCenterY = pRotationCenterY;
+ this.updateLocalRotationCenterY();
+
this.mLocalToParentTransformationDirty = true;
this.mParentToLocalTransformationDirty = true;
}
@@ -308,6 +456,8 @@ public void setRotationCenter(final float pRotationCenterX, final float pRotatio
this.mRotationCenterX = pRotationCenterX;
this.mRotationCenterY = pRotationCenterY;
+ this.updateLocalRotationCenter();
+
this.mLocalToParentTransformationDirty = true;
this.mParentToLocalTransformationDirty = true;
}
@@ -345,11 +495,7 @@ public void setScaleY(final float pScaleY) {
@Override
public void setScale(final float pScale) {
- this.mScaleX = pScale;
- this.mScaleY = pScale;
-
- this.mLocalToParentTransformationDirty = true;
- this.mParentToLocalTransformationDirty = true;
+ this.setScale(pScale, pScale);
}
@Override
@@ -375,6 +521,8 @@ public float getScaleCenterY() {
public void setScaleCenterX(final float pScaleCenterX) {
this.mScaleCenterX = pScaleCenterX;
+ this.updateLocalScaleCenterX();
+
this.mLocalToParentTransformationDirty = true;
this.mParentToLocalTransformationDirty = true;
}
@@ -383,6 +531,8 @@ public void setScaleCenterX(final float pScaleCenterX) {
public void setScaleCenterY(final float pScaleCenterY) {
this.mScaleCenterY = pScaleCenterY;
+ this.updateLocalScaleCenterY();
+
this.mLocalToParentTransformationDirty = true;
this.mParentToLocalTransformationDirty = true;
}
@@ -392,6 +542,8 @@ public void setScaleCenter(final float pScaleCenterX, final float pScaleCenterY)
this.mScaleCenterX = pScaleCenterX;
this.mScaleCenterY = pScaleCenterY;
+ this.updateLocalScaleCenter();
+
this.mLocalToParentTransformationDirty = true;
this.mParentToLocalTransformationDirty = true;
}
@@ -429,11 +581,7 @@ public void setSkewY(final float pSkewY) {
@Override
public void setSkew(final float pSkew) {
- this.mSkewX = pSkew;
- this.mSkewY = pSkew;
-
- this.mLocalToParentTransformationDirty = true;
- this.mParentToLocalTransformationDirty = true;
+ this.setSkew(pSkew, pSkew);
}
@Override
@@ -459,6 +607,8 @@ public float getSkewCenterY() {
public void setSkewCenterX(final float pSkewCenterX) {
this.mSkewCenterX = pSkewCenterX;
+ this.updateLocalSkewCenterX();
+
this.mLocalToParentTransformationDirty = true;
this.mParentToLocalTransformationDirty = true;
}
@@ -467,6 +617,8 @@ public void setSkewCenterX(final float pSkewCenterX) {
public void setSkewCenterY(final float pSkewCenterY) {
this.mSkewCenterY = pSkewCenterY;
+ this.updateLocalSkewCenterY();
+
this.mLocalToParentTransformationDirty = true;
this.mParentToLocalTransformationDirty = true;
}
@@ -476,6 +628,8 @@ public void setSkewCenter(final float pSkewCenterX, final float pSkewCenterY) {
this.mSkewCenterX = pSkewCenterX;
this.mSkewCenterY = pSkewCenterY;
+ this.updateLocalSkewCenter();
+
this.mLocalToParentTransformationDirty = true;
this.mParentToLocalTransformationDirty = true;
}
@@ -485,6 +639,30 @@ public boolean isRotatedOrScaledOrSkewed() {
return (this.mRotation != 0) || (this.mScaleX != 1) || (this.mScaleY != 1) || (this.mSkewX != 0) || (this.mSkewY != 0);
}
+ @Override
+ public void setAnchorCenterX(final float pAnchorCenterX) {
+ this.setOffsetCenterX(pAnchorCenterX);
+ this.setRotationCenterX(pAnchorCenterX);
+ this.setScaleCenterX(pAnchorCenterX);
+ this.setSkewCenterX(pAnchorCenterX);
+ }
+
+ @Override
+ public void setAnchorCenterY(final float pAnchorCenterY) {
+ this.setOffsetCenterY(pAnchorCenterY);
+ this.setRotationCenterY(pAnchorCenterY);
+ this.setScaleCenterY(pAnchorCenterY);
+ this.setSkewCenterY(pAnchorCenterY);
+ }
+
+ @Override
+ public void setAnchorCenter(final float pAnchorCenterX, final float pAnchorCenterY) {
+ this.setOffsetCenter(pAnchorCenterX, pAnchorCenterY);
+ this.setRotationCenter(pAnchorCenterX, pAnchorCenterY);
+ this.setScaleCenter(pAnchorCenterX, pAnchorCenterY);
+ this.setSkewCenter(pAnchorCenterX, pAnchorCenterY);
+ }
+
@Override
public float getRed() {
return this.mColor.getRed();
@@ -517,12 +695,19 @@ public void setColor(final Color pColor) {
this.onUpdateColor();
}
+ @Override
+ public void setColor(final int pARGBPackedInt) {
+ ColorUtils.convertARGBPackedIntToColor(pARGBPackedInt, this.mColor);
+
+ this.onUpdateColor();
+ }
+
/**
* @param pRed from 0.0f to 1.0f
*/
@Override
public void setRed(final float pRed) {
- if(this.mColor.setRedChecking(pRed)) {
+ if (this.mColor.setRedChecking(pRed)) { // TODO Is this check worth it?
this.onUpdateColor();
}
}
@@ -532,7 +717,7 @@ public void setRed(final float pRed) {
*/
@Override
public void setGreen(final float pGreen) {
- if(this.mColor.setGreenChecking(pGreen)) {
+ if (this.mColor.setGreenChecking(pGreen)) { // TODO Is this check worth it?
this.onUpdateColor();
}
}
@@ -542,7 +727,7 @@ public void setGreen(final float pGreen) {
*/
@Override
public void setBlue(final float pBlue) {
- if(this.mColor.setBlueChecking(pBlue)) {
+ if (this.mColor.setBlueChecking(pBlue)) { // TODO Is this check worth it?
this.onUpdateColor();
}
}
@@ -552,7 +737,7 @@ public void setBlue(final float pBlue) {
*/
@Override
public void setAlpha(final float pAlpha) {
- if(this.mColor.setAlphaChecking(pAlpha)) {
+ if (this.mColor.setAlphaChecking(pAlpha)) { // TODO Is this check worth it?
this.onUpdateColor();
}
}
@@ -564,7 +749,7 @@ public void setAlpha(final float pAlpha) {
*/
@Override
public void setColor(final float pRed, final float pGreen, final float pBlue) {
- if(this.mColor.setChecking(pRed, pGreen, pBlue)) { // TODO Is this check worth it?
+ if (this.mColor.setChecking(pRed, pGreen, pBlue)) { // TODO Is this check worth it?
this.onUpdateColor();
}
}
@@ -577,14 +762,14 @@ public void setColor(final float pRed, final float pGreen, final float pBlue) {
*/
@Override
public void setColor(final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
- if(this.mColor.setChecking(pRed, pGreen, pBlue, pAlpha)) { // TODO Is this check worth it?
+ if (this.mColor.setChecking(pRed, pGreen, pBlue, pAlpha)) { // TODO Is this check worth it?
this.onUpdateColor();
}
}
@Override
public int getChildCount() {
- if(this.mChildren == null) {
+ if (this.mChildren == null) {
return 0;
}
return this.mChildren.size();
@@ -592,12 +777,12 @@ public int getChildCount() {
@Override
public IEntity getChildByTag(final int pTag) {
- if(this.mChildren == null) {
+ if (this.mChildren == null) {
return null;
}
- for(int i = this.mChildren.size() - 1; i >= 0; i--) {
+ for (int i = this.mChildren.size() - 1; i >= 0; i--) {
final IEntity child = this.mChildren.get(i);
- if(child.getTag() == pTag) {
+ if (child.getTag() == pTag) {
return child;
}
}
@@ -606,15 +791,15 @@ public IEntity getChildByTag(final int pTag) {
@Override
public IEntity getChildByIndex(final int pIndex) {
- if(this.mChildren == null) {
- return null;
- }
- return this.mChildren.get(pIndex);
+ if (this.mChildren == null) {
+ return null;
+ }
+ return this.mChildren.get(pIndex);
}
@Override
public IEntity getChildByMatcher(final IEntityMatcher pEntityMatcher) {
- if(this.mChildren == null) {
+ if (this.mChildren == null) {
return null;
}
return this.mChildren.get(pEntityMatcher);
@@ -622,7 +807,7 @@ public IEntity getChildByMatcher(final IEntityMatcher pEntityMatcher) {
@Override
public IEntity getFirstChild() {
- if(this.mChildren == null) {
+ if (this.mChildren == null) {
return null;
}
return this.mChildren.get(0);
@@ -630,7 +815,7 @@ public IEntity getFirstChild() {
@Override
public IEntity getLastChild() {
- if(this.mChildren == null) {
+ if (this.mChildren == null) {
return null;
}
return this.mChildren.get(this.mChildren.size() - 1);
@@ -650,14 +835,14 @@ public IEntity queryFirst(final IEntityMatcher pEntityMatcher) {
@Override
public S queryFirstForSubclass(final IEntityMatcher pEntityMatcher) {
final int childCount = this.getChildCount();
- for(int i = 0; i < childCount; i++) {
+ for (int i = 0; i < childCount; i++) {
final IEntity child = this.mChildren.get(i);
- if(pEntityMatcher.matches(child)) {
+ if (pEntityMatcher.matches(child)) {
return (S)child;
}
final S childQueryFirst = child.queryFirstForSubclass(pEntityMatcher);
- if(childQueryFirst != null) {
+ if (childQueryFirst != null) {
return childQueryFirst;
}
}
@@ -668,9 +853,9 @@ public S queryFirstForSubclass(final IEntityMatcher pEntityM
@Override
public > L query(final IEntityMatcher pEntityMatcher, final L pResult) {
final int childCount = this.getChildCount();
- for(int i = 0; i < childCount; i++) {
+ for (int i = 0; i < childCount; i++) {
final IEntity child = this.mChildren.get(i);
- if(pEntityMatcher.matches(child)) {
+ if (pEntityMatcher.matches(child)) {
pResult.add(child);
}
@@ -689,10 +874,10 @@ public ArrayList queryForSubclass(final IEntityMatcher pE
@Override
public , S extends IEntity> L queryForSubclass(final IEntityMatcher pEntityMatcher, final L pResult) throws ClassCastException {
final int childCount = this.getChildCount();
- for(int i = 0; i < childCount; i++) {
+ for (int i = 0; i < childCount; i++) {
final IEntity child = this.mChildren.get(i);
- if(pEntityMatcher.matches(child)) {
- pResult.add((S)child);
+ if (pEntityMatcher.matches(child)) {
+ pResult.add((S) child);
}
child.queryForSubclass(pEntityMatcher, pResult);
@@ -704,7 +889,7 @@ public , S extends IEntity> L queryForSubclass(final IEntityMa
@Override
public boolean detachSelf() {
final IEntity parent = this.mParent;
- if(parent != null) {
+ if (parent != null) {
return parent.detachChild(this);
} else {
return false;
@@ -713,7 +898,7 @@ public boolean detachSelf() {
@Override
public void detachChildren() {
- if(this.mChildren == null) {
+ if (this.mChildren == null) {
return;
}
this.mChildren.clear(Entity.PARAMETERCALLABLE_DETACHCHILD);
@@ -723,7 +908,7 @@ public void detachChildren() {
public void attachChild(final IEntity pEntity) throws IllegalStateException {
this.assertEntityHasNoParent(pEntity);
- if(this.mChildren == null) {
+ if (this.mChildren == null) {
this.allocateChildren();
}
this.mChildren.add(pEntity);
@@ -738,10 +923,10 @@ public void sortChildren() {
@Override
public void sortChildren(final boolean pImmediate) {
- if(this.mChildren == null) {
+ if (this.mChildren == null) {
return;
}
- if(pImmediate) {
+ if (pImmediate) {
ZIndexSorter.getInstance().sort(this.mChildren);
} else {
this.mChildrenSortPending = true;
@@ -750,7 +935,7 @@ public void sortChildren(final boolean pImmediate) {
@Override
public void sortChildren(final IEntityComparator pEntityComparator) {
- if(this.mChildren == null) {
+ if (this.mChildren == null) {
return;
}
ZIndexSorter.getInstance().sort(this.mChildren, pEntityComparator);
@@ -758,7 +943,7 @@ public void sortChildren(final IEntityComparator pEntityComparator) {
@Override
public boolean detachChild(final IEntity pEntity) {
- if(this.mChildren == null) {
+ if (this.mChildren == null) {
return false;
}
return this.mChildren.remove(pEntity, Entity.PARAMETERCALLABLE_DETACHCHILD);
@@ -766,11 +951,11 @@ public boolean detachChild(final IEntity pEntity) {
@Override
public IEntity detachChild(final int pTag) {
- if(this.mChildren == null) {
+ if (this.mChildren == null) {
return null;
}
- for(int i = this.mChildren.size() - 1; i >= 0; i--) {
- if(this.mChildren.get(i).getTag() == pTag) {
+ for (int i = this.mChildren.size() - 1; i >= 0; i--) {
+ if (this.mChildren.get(i).getTag() == pTag) {
final IEntity removed = this.mChildren.remove(i);
Entity.PARAMETERCALLABLE_DETACHCHILD.call(removed);
return removed;
@@ -781,7 +966,7 @@ public IEntity detachChild(final int pTag) {
@Override
public IEntity detachChild(final IEntityMatcher pEntityMatcher) {
- if(this.mChildren == null) {
+ if (this.mChildren == null) {
return null;
}
return this.mChildren.remove(pEntityMatcher, Entity.PARAMETERCALLABLE_DETACHCHILD);
@@ -789,7 +974,7 @@ public IEntity detachChild(final IEntityMatcher pEntityMatcher) {
@Override
public boolean detachChildren(final IEntityMatcher pEntityMatcher) {
- if(this.mChildren == null) {
+ if (this.mChildren == null) {
return false;
}
return this.mChildren.removeAll(pEntityMatcher, Entity.PARAMETERCALLABLE_DETACHCHILD);
@@ -797,7 +982,7 @@ public boolean detachChildren(final IEntityMatcher pEntityMatcher) {
@Override
public void callOnChildren(final IEntityParameterCallable pEntityParameterCallable) {
- if(this.mChildren == null) {
+ if (this.mChildren == null) {
return;
}
this.mChildren.call(pEntityParameterCallable);
@@ -805,7 +990,7 @@ public void callOnChildren(final IEntityParameterCallable pEntityParameterCallab
@Override
public void callOnChildren(final IEntityParameterCallable pEntityParameterCallable, final IEntityMatcher pEntityMatcher) {
- if(this.mChildren == null) {
+ if (this.mChildren == null) {
return;
}
this.mChildren.call(pEntityMatcher, pEntityParameterCallable);
@@ -813,7 +998,7 @@ public void callOnChildren(final IEntityParameterCallable pEntityParameterCallab
@Override
public void registerUpdateHandler(final IUpdateHandler pUpdateHandler) {
- if(this.mUpdateHandlers == null) {
+ if (this.mUpdateHandlers == null) {
this.allocateUpdateHandlers();
}
this.mUpdateHandlers.add(pUpdateHandler);
@@ -821,7 +1006,7 @@ public void registerUpdateHandler(final IUpdateHandler pUpdateHandler) {
@Override
public boolean unregisterUpdateHandler(final IUpdateHandler pUpdateHandler) {
- if(this.mUpdateHandlers == null) {
+ if (this.mUpdateHandlers == null) {
return false;
}
return this.mUpdateHandlers.remove(pUpdateHandler);
@@ -829,15 +1014,23 @@ public boolean unregisterUpdateHandler(final IUpdateHandler pUpdateHandler) {
@Override
public boolean unregisterUpdateHandlers(final IUpdateHandlerMatcher pUpdateHandlerMatcher) {
- if(this.mUpdateHandlers == null) {
+ if (this.mUpdateHandlers == null) {
return false;
}
return this.mUpdateHandlers.removeAll(pUpdateHandlerMatcher);
}
+ @Override
+ public int getUpdateHandlerCount() {
+ if (this.mUpdateHandlers == null) {
+ return 0;
+ }
+ return this.mUpdateHandlers.size();
+ }
+
@Override
public void clearUpdateHandlers() {
- if(this.mUpdateHandlers == null) {
+ if (this.mUpdateHandlers == null) {
return;
}
this.mUpdateHandlers.clear();
@@ -845,7 +1038,7 @@ public void clearUpdateHandlers() {
@Override
public void registerEntityModifier(final IEntityModifier pEntityModifier) {
- if(this.mEntityModifiers == null) {
+ if (this.mEntityModifiers == null) {
this.allocateEntityModifiers();
}
this.mEntityModifiers.add(pEntityModifier);
@@ -853,7 +1046,7 @@ public void registerEntityModifier(final IEntityModifier pEntityModifier) {
@Override
public boolean unregisterEntityModifier(final IEntityModifier pEntityModifier) {
- if(this.mEntityModifiers == null) {
+ if (this.mEntityModifiers == null) {
return false;
}
return this.mEntityModifiers.remove(pEntityModifier);
@@ -861,15 +1054,30 @@ public boolean unregisterEntityModifier(final IEntityModifier pEntityModifier) {
@Override
public boolean unregisterEntityModifiers(final IEntityModifierMatcher pEntityModifierMatcher) {
- if(this.mEntityModifiers == null) {
+ if (this.mEntityModifiers == null) {
return false;
}
return this.mEntityModifiers.removeAll(pEntityModifierMatcher);
}
+ @Override
+ public int getEntityModifierCount() {
+ if (this.mEntityModifiers == null) {
+ return 0;
+ }
+ return this.mEntityModifiers.size();
+ }
+
+ @Override
+ public void resetEntityModifiers() {
+ if (this.mEntityModifiers != null) {
+ this.mEntityModifiers.reset();
+ }
+ }
+
@Override
public void clearEntityModifiers() {
- if(this.mEntityModifiers == null) {
+ if (this.mEntityModifiers == null) {
return;
}
this.mEntityModifiers.clear();
@@ -877,30 +1085,30 @@ public void clearEntityModifiers() {
@Override
public float[] getSceneCenterCoordinates() {
- return this.convertLocalToSceneCoordinates(0, 0);
+ return this.convertLocalCoordinatesToSceneCoordinates(this.mWidth * 0.5f, this.mHeight * 0.5f);
}
@Override
public float[] getSceneCenterCoordinates(final float[] pReuse) {
- return this.convertLocalToSceneCoordinates(0, 0, pReuse);
+ return this.convertLocalCoordinatesToSceneCoordinates(this.mWidth * 0.5f, this.mHeight * 0.5f, pReuse);
}
@Override
public Transformation getLocalToParentTransformation() {
- if(this.mLocalToParentTransformation == null) {
+ if (this.mLocalToParentTransformation == null) {
this.mLocalToParentTransformation = new Transformation();
}
final Transformation localToParentTransformation = this.mLocalToParentTransformation;
- if(this.mLocalToParentTransformationDirty) {
+ if (this.mLocalToParentTransformationDirty) {
localToParentTransformation.setToIdentity();
/* Scale. */
final float scaleX = this.mScaleX;
final float scaleY = this.mScaleY;
- if((scaleX != 1) || (scaleY != 1)) {
- final float scaleCenterX = this.mScaleCenterX;
- final float scaleCenterY = this.mScaleCenterY;
+ if ((scaleX != 1) || (scaleY != 1)) {
+ final float scaleCenterX = this.mLocalScaleCenterX;
+ final float scaleCenterY = this.mLocalScaleCenterY;
/* TODO Check if it is worth to check for scaleCenterX == 0 && scaleCenterY == 0 as the two postTranslate can be saved.
* The same obviously applies for all similar occurrences of this pattern in this class. */
@@ -913,9 +1121,9 @@ public Transformation getLocalToParentTransformation() {
/* Skew. */
final float skewX = this.mSkewX;
final float skewY = this.mSkewY;
- if((skewX != 0) || (skewY != 0)) {
- final float skewCenterX = this.mSkewCenterX;
- final float skewCenterY = this.mSkewCenterY;
+ if ((skewX != 0) || (skewY != 0)) {
+ final float skewCenterX = this.mLocalSkewCenterX;
+ final float skewCenterY = this.mLocalSkewCenterY;
localToParentTransformation.postTranslate(-skewCenterX, -skewCenterY);
localToParentTransformation.postSkew(skewX, skewY);
@@ -924,18 +1132,21 @@ public Transformation getLocalToParentTransformation() {
/* Rotation. */
final float rotation = this.mRotation;
- if(rotation != 0) {
- final float rotationCenterX = this.mRotationCenterX;
- final float rotationCenterY = this.mRotationCenterY;
+ if (rotation != 0) {
+ final float rotationCenterX = this.mLocalRotationCenterX;
+ final float rotationCenterY = this.mLocalRotationCenterY;
localToParentTransformation.postTranslate(-rotationCenterX, -rotationCenterY);
- localToParentTransformation.postRotate(rotation);
+ localToParentTransformation.postRotate(-rotation);
localToParentTransformation.postTranslate(rotationCenterX, rotationCenterY);
}
/* Translation. */
localToParentTransformation.postTranslate(this.mX, this.mY);
+ /* Offset. */
+ localToParentTransformation.postTranslate(-this.mLocalOffsetCenterX, -this.mLocalOffsetCenterY);
+
this.mLocalToParentTransformationDirty = false;
}
return localToParentTransformation;
@@ -943,50 +1154,53 @@ public Transformation getLocalToParentTransformation() {
@Override
public Transformation getParentToLocalTransformation() {
- if(this.mParentToLocalTransformation == null) {
+ if (this.mParentToLocalTransformation == null) {
this.mParentToLocalTransformation = new Transformation();
}
final Transformation parentToLocalTransformation = this.mParentToLocalTransformation;
- if(this.mParentToLocalTransformationDirty) {
+ if (this.mParentToLocalTransformationDirty) {
parentToLocalTransformation.setToIdentity();
+ /* Offset. */
+ parentToLocalTransformation.postTranslate(this.mLocalOffsetCenterX, this.mLocalOffsetCenterY);
+
/* Translation. */
parentToLocalTransformation.postTranslate(-this.mX, -this.mY);
/* Rotation. */
final float rotation = this.mRotation;
- if(rotation != 0) {
- final float rotationCenterX = this.mRotationCenterX;
- final float rotationCenterY = this.mRotationCenterY;
+ if (rotation != 0) {
+ final float localRotationCenterX = this.mLocalRotationCenterX;
+ final float localRotationCenterY = this.mLocalRotationCenterY;
- parentToLocalTransformation.postTranslate(-rotationCenterX, -rotationCenterY);
- parentToLocalTransformation.postRotate(-rotation);
- parentToLocalTransformation.postTranslate(rotationCenterX, rotationCenterY);
+ parentToLocalTransformation.postTranslate(-localRotationCenterX, -localRotationCenterY);
+ parentToLocalTransformation.postRotate(rotation);
+ parentToLocalTransformation.postTranslate(localRotationCenterX, localRotationCenterY);
}
/* Skew. */
final float skewX = this.mSkewX;
final float skewY = this.mSkewY;
- if((skewX != 0) || (skewY != 0)) {
- final float skewCenterX = this.mSkewCenterX;
- final float skewCenterY = this.mSkewCenterY;
+ if ((skewX != 0) || (skewY != 0)) {
+ final float localSkewCenterX = this.mLocalSkewCenterX;
+ final float localSkewCenterY = this.mLocalSkewCenterY;
- parentToLocalTransformation.postTranslate(-skewCenterX, -skewCenterY);
+ parentToLocalTransformation.postTranslate(-localSkewCenterX, -localSkewCenterY);
parentToLocalTransformation.postSkew(-skewX, -skewY);
- parentToLocalTransformation.postTranslate(skewCenterX, skewCenterY);
+ parentToLocalTransformation.postTranslate(localSkewCenterX, localSkewCenterY);
}
/* Scale. */
final float scaleX = this.mScaleX;
final float scaleY = this.mScaleY;
- if((scaleX != 1) || (scaleY != 1)) {
- final float scaleCenterX = this.mScaleCenterX;
- final float scaleCenterY = this.mScaleCenterY;
+ if ((scaleX != 1) || (scaleY != 1)) {
+ final float localScaleCenterX = this.mLocalScaleCenterX;
+ final float localScaleCenterY = this.mLocalScaleCenterY;
- parentToLocalTransformation.postTranslate(-scaleCenterX, -scaleCenterY);
+ parentToLocalTransformation.postTranslate(-localScaleCenterX, -localScaleCenterY);
parentToLocalTransformation.postScale(1 / scaleX, 1 / scaleY); // TODO Division could be replaced by a multiplication of 'scale(X/Y)Inverse'...
- parentToLocalTransformation.postTranslate(scaleCenterX, scaleCenterY);
+ parentToLocalTransformation.postTranslate(localScaleCenterX, localScaleCenterY);
}
this.mParentToLocalTransformationDirty = false;
@@ -996,7 +1210,7 @@ public Transformation getParentToLocalTransformation() {
@Override
public Transformation getLocalToSceneTransformation() {
- if(this.mLocalToSceneTransformation == null) {
+ if (this.mLocalToSceneTransformation == null) {
this.mLocalToSceneTransformation = new Transformation();
}
@@ -1005,7 +1219,7 @@ public Transformation getLocalToSceneTransformation() {
localToSceneTransformation.setTo(this.getLocalToParentTransformation());
final IEntity parent = this.mParent;
- if(parent != null) {
+ if (parent != null) {
localToSceneTransformation.postConcat(parent.getLocalToSceneTransformation());
}
@@ -1014,7 +1228,7 @@ public Transformation getLocalToSceneTransformation() {
@Override
public Transformation getSceneToLocalTransformation() {
- if(this.mSceneToLocalTransformation == null) {
+ if (this.mSceneToLocalTransformation == null) {
this.mSceneToLocalTransformation = new Transformation();
}
@@ -1023,26 +1237,84 @@ public Transformation getSceneToLocalTransformation() {
sceneToLocalTransformation.setTo(this.getParentToLocalTransformation());
final IEntity parent = this.mParent;
- if(parent != null) {
+ if (parent != null) {
sceneToLocalTransformation.preConcat(parent.getSceneToLocalTransformation());
}
return sceneToLocalTransformation;
}
- /* (non-Javadoc)
- * @see org.andengine.entity.IEntity#convertLocalToSceneCoordinates(float, float)
- */
@Override
- public float[] convertLocalToSceneCoordinates(final float pX, final float pY) {
- return this.convertLocalToSceneCoordinates(pX, pY, Entity.VERTICES_LOCAL_TO_SCENE_TMP);
+ public float[] convertLocalCoordinatesToParentCoordinates(final float pX, final float pY) {
+ return this.convertLocalCoordinatesToParentCoordinates(pX, pY, Entity.VERTICES_LOCAL_TO_PARENT_TMP);
+ }
+
+ @Override
+ public float[] convertLocalCoordinatesToParentCoordinates(final float pX, final float pY, final float[] pReuse) {
+ final Transformation localToParentTransformation = this.getLocalToParentTransformation();
+
+ pReuse[Constants.VERTEX_INDEX_X] = pX;
+ pReuse[Constants.VERTEX_INDEX_Y] = pY;
+
+ localToParentTransformation.transform(pReuse);
+
+ return pReuse;
+ }
+
+ @Override
+ public float[] convertLocalCoordinatesToParentCoordinates(final float[] pCoordinates) {
+ return this.convertLocalCoordinatesToParentCoordinates(pCoordinates, Entity.VERTICES_LOCAL_TO_PARENT_TMP);
+ }
+
+ @Override
+ public float[] convertLocalCoordinatesToParentCoordinates(final float[] pCoordinates, final float[] pReuse) {
+ final Transformation localToParentTransformation = this.getLocalToParentTransformation();
+
+ pReuse[Constants.VERTEX_INDEX_X] = pCoordinates[Constants.VERTEX_INDEX_X];
+ pReuse[Constants.VERTEX_INDEX_Y] = pCoordinates[Constants.VERTEX_INDEX_Y];
+
+ localToParentTransformation.transform(pReuse);
+
+ return pReuse;
+ }
+
+ @Override
+ public float[] convertParentCoordinatesToLocalCoordinates(final float pX, final float pY) {
+ return this.convertParentCoordinatesToLocalCoordinates(pX, pY, Entity.VERTICES_PARENT_TO_LOCAL_TMP);
+ }
+
+ @Override
+ public float[] convertParentCoordinatesToLocalCoordinates(final float pX, final float pY, final float[] pReuse) {
+ pReuse[Constants.VERTEX_INDEX_X] = pX;
+ pReuse[Constants.VERTEX_INDEX_Y] = pY;
+
+ this.getParentToLocalTransformation().transform(pReuse);
+
+ return pReuse;
+ }
+
+ @Override
+ public float[] convertParentCoordinatesToLocalCoordinates(final float[] pCoordinates) {
+ return this.convertParentCoordinatesToLocalCoordinates(pCoordinates, Entity.VERTICES_PARENT_TO_LOCAL_TMP);
+ }
+
+ @Override
+ public float[] convertParentCoordinatesToLocalCoordinates(final float[] pCoordinates, final float[] pReuse) {
+ pReuse[Constants.VERTEX_INDEX_X] = pCoordinates[Constants.VERTEX_INDEX_X];
+ pReuse[Constants.VERTEX_INDEX_Y] = pCoordinates[Constants.VERTEX_INDEX_Y];
+
+ this.getParentToLocalTransformation().transform(pReuse);
+
+ return pReuse;
+ }
+
+ @Override
+ public float[] convertLocalCoordinatesToSceneCoordinates(final float pX, final float pY) {
+ return this.convertLocalCoordinatesToSceneCoordinates(pX, pY, Entity.VERTICES_LOCAL_TO_SCENE_TMP);
}
- /* (non-Javadoc)
- * @see org.andengine.entity.IEntity#convertLocalToSceneCoordinates(float, float, float[])
- */
@Override
- public float[] convertLocalToSceneCoordinates(final float pX, final float pY, final float[] pReuse) {
+ public float[] convertLocalCoordinatesToSceneCoordinates(final float pX, final float pY, final float[] pReuse) {
final Transformation localToSceneTransformation = this.getLocalToSceneTransformation();
pReuse[Constants.VERTEX_INDEX_X] = pX;
@@ -1053,19 +1325,13 @@ public float[] convertLocalToSceneCoordinates(final float pX, final float pY, fi
return pReuse;
}
- /* (non-Javadoc)
- * @see org.andengine.entity.IEntity#convertLocalToSceneCoordinates(float[])
- */
@Override
- public float[] convertLocalToSceneCoordinates(final float[] pCoordinates) {
- return this.convertSceneToLocalCoordinates(pCoordinates, Entity.VERTICES_LOCAL_TO_SCENE_TMP);
+ public float[] convertLocalCoordinatesToSceneCoordinates(final float[] pCoordinates) {
+ return this.convertLocalCoordinatesToSceneCoordinates(pCoordinates, Entity.VERTICES_LOCAL_TO_SCENE_TMP);
}
- /* (non-Javadoc)
- * @see org.andengine.entity.IEntity#convertLocalToSceneCoordinates(float[], float[])
- */
@Override
- public float[] convertLocalToSceneCoordinates(final float[] pCoordinates, final float[] pReuse) {
+ public float[] convertLocalCoordinatesToSceneCoordinates(final float[] pCoordinates, final float[] pReuse) {
final Transformation localToSceneTransformation = this.getLocalToSceneTransformation();
pReuse[Constants.VERTEX_INDEX_X] = pCoordinates[Constants.VERTEX_INDEX_X];
@@ -1076,19 +1342,13 @@ public float[] convertLocalToSceneCoordinates(final float[] pCoordinates, final
return pReuse;
}
- /* (non-Javadoc)
- * @see org.andengine.entity.IEntity#convertSceneToLocalCoordinates(float, float)
- */
@Override
- public float[] convertSceneToLocalCoordinates(final float pX, final float pY) {
- return this.convertSceneToLocalCoordinates(pX, pY, Entity.VERTICES_SCENE_TO_LOCAL_TMP);
+ public float[] convertSceneCoordinatesToLocalCoordinates(final float pX, final float pY) {
+ return this.convertSceneCoordinatesToLocalCoordinates(pX, pY, Entity.VERTICES_SCENE_TO_LOCAL_TMP);
}
- /* (non-Javadoc)
- * @see org.andengine.entity.IEntity#convertSceneToLocalCoordinates(float, float, float[])
- */
@Override
- public float[] convertSceneToLocalCoordinates(final float pX, final float pY, final float[] pReuse) {
+ public float[] convertSceneCoordinatesToLocalCoordinates(final float pX, final float pY, final float[] pReuse) {
pReuse[Constants.VERTEX_INDEX_X] = pX;
pReuse[Constants.VERTEX_INDEX_Y] = pY;
@@ -1097,19 +1357,13 @@ public float[] convertSceneToLocalCoordinates(final float pX, final float pY, fi
return pReuse;
}
- /* (non-Javadoc)
- * @see org.andengine.entity.IEntity#convertSceneToLocalCoordinates(float[])
- */
@Override
- public float[] convertSceneToLocalCoordinates(final float[] pCoordinates) {
- return this.convertSceneToLocalCoordinates(pCoordinates, Entity.VERTICES_SCENE_TO_LOCAL_TMP);
+ public float[] convertSceneCoordinatesToLocalCoordinates(final float[] pCoordinates) {
+ return this.convertSceneCoordinatesToLocalCoordinates(pCoordinates, Entity.VERTICES_SCENE_TO_LOCAL_TMP);
}
- /* (non-Javadoc)
- * @see org.andengine.entity.IEntity#convertSceneToLocalCoordinates(float[], float[])
- */
@Override
- public float[] convertSceneToLocalCoordinates(final float[] pCoordinates, final float[] pReuse) {
+ public float[] convertSceneCoordinatesToLocalCoordinates(final float[] pCoordinates, final float[] pReuse) {
pReuse[Constants.VERTEX_INDEX_X] = pCoordinates[Constants.VERTEX_INDEX_X];
pReuse[Constants.VERTEX_INDEX_Y] = pCoordinates[Constants.VERTEX_INDEX_Y];
@@ -1140,14 +1394,14 @@ public void setUserData(final Object pUserData) {
@Override
public final void onDraw(final GLState pGLState, final Camera pCamera) {
- if(this.mVisible && !(this.mCullingEnabled && this.isCulled(pCamera))) {
+ if (this.mVisible && !(this.mCullingEnabled && this.isCulled(pCamera))) {
this.onManagedDraw(pGLState, pCamera);
}
}
@Override
public final void onUpdate(final float pSecondsElapsed) {
- if(!this.mIgnoreUpdate) {
+ if (!this.mIgnoreUpdate) {
this.onManagedUpdate(pSecondsElapsed);
}
}
@@ -1166,23 +1420,26 @@ public void reset() {
this.mSkewX = 0;
this.mSkewY = 0;
+ this.resetRotationCenter();
+ this.resetSkewCenter();
+ this.resetScaleCenter();
+
this.mColor.reset();
- if(this.mEntityModifiers != null) {
- this.mEntityModifiers.reset();
- }
+ this.resetEntityModifiers();
- if(this.mChildren != null) {
- final SmartList entities = this.mChildren;
- for(int i = entities.size() - 1; i >= 0; i--) {
- entities.get(i).reset();
+ if (this.mChildren != null) {
+ final SmartList children = this.mChildren;
+ for (int i = children.size() - 1; i >= 0; i--) {
+ final IEntity child = children.get(i);
+ child.reset();
}
}
}
@Override
public void dispose() {
- if(!this.mDisposed) {
+ if (!this.mDisposed) {
this.mDisposed = true;
} else {
throw new AlreadyDisposedException();
@@ -1193,7 +1450,7 @@ public void dispose() {
protected void finalize() throws Throwable {
super.finalize();
- if(!this.mDisposed) {
+ if (!this.mDisposed) {
this.dispose();
}
}
@@ -1209,16 +1466,21 @@ public String toString() {
public void toString(final StringBuilder pStringBuilder) {
pStringBuilder.append(this.getClass().getSimpleName());
- if((this.mChildren != null) && (this.mChildren.size() > 0)) {
+ if ((this.mChildren != null) && (this.mChildren.size() > 0)) {
+ final SmartList children = this.mChildren;
+
pStringBuilder.append(" [");
- final SmartList entities = this.mChildren;
- for(int i = 0; i < entities.size(); i++) {
- entities.get(i).toString(pStringBuilder);
- if(i < (entities.size() - 1)) {
+
+ final int childCount = children.size();
+ for (int i = 0; i < childCount; i++) {
+ final IEntity child = children.get(i);
+ child.toString(pStringBuilder);
+
+ if (i < (childCount - 1)) {
pStringBuilder.append(", ");
}
}
- pStringBuilder.append("]");
+ pStringBuilder.append(']');
}
}
@@ -1263,6 +1525,9 @@ private void allocateUpdateHandlers() {
}
protected void onApplyTransformations(final GLState pGLState) {
+ /* Offset. */
+ this.applyOffset(pGLState);
+
/* Translation. */
this.applyTranslation(pGLState);
@@ -1276,6 +1541,10 @@ protected void onApplyTransformations(final GLState pGLState) {
this.applyScale(pGLState);
}
+ protected void applyOffset(final GLState pGLState) {
+ pGLState.translateModelViewGLMatrixf(-this.mLocalOffsetCenterX, -this.mLocalOffsetCenterY, 0);
+ }
+
protected void applyTranslation(final GLState pGLState) {
pGLState.translateModelViewGLMatrixf(this.mX, this.mY, 0);
}
@@ -1283,13 +1552,13 @@ protected void applyTranslation(final GLState pGLState) {
protected void applyRotation(final GLState pGLState) {
final float rotation = this.mRotation;
- if(rotation != 0) {
- final float rotationCenterX = this.mRotationCenterX;
- final float rotationCenterY = this.mRotationCenterY;
+ if (rotation != 0) {
+ final float localRotationCenterX = this.mLocalRotationCenterX;
+ final float localRotationCenterY = this.mLocalRotationCenterY;
- pGLState.translateModelViewGLMatrixf(rotationCenterX, rotationCenterY, 0);
- pGLState.rotateModelViewGLMatrixf(rotation, 0, 0, 1);
- pGLState.translateModelViewGLMatrixf(-rotationCenterX, -rotationCenterY, 0);
+ pGLState.translateModelViewGLMatrixf(localRotationCenterX, localRotationCenterY, 0);
+ pGLState.rotateModelViewGLMatrixf(-rotation, 0, 0, 1);
+ pGLState.translateModelViewGLMatrixf(-localRotationCenterX, -localRotationCenterY, 0);
/* TODO There is a special, but very likely case when mRotationCenter and mScaleCenter are the same.
* In that case the last glTranslatef of the rotation and the first glTranslatef of the scale is superfluous.
@@ -1301,13 +1570,13 @@ protected void applySkew(final GLState pGLState) {
final float skewX = this.mSkewX;
final float skewY = this.mSkewY;
- if((skewX != 0) || (skewY != 0)) {
- final float skewCenterX = this.mSkewCenterX;
- final float skewCenterY = this.mSkewCenterY;
+ if ((skewX != 0) || (skewY != 0)) {
+ final float localSkewCenterX = this.mLocalSkewCenterX;
+ final float localSkewCenterY = this.mLocalSkewCenterY;
- pGLState.translateModelViewGLMatrixf(skewCenterX, skewCenterY, 0);
+ pGLState.translateModelViewGLMatrixf(localSkewCenterX, localSkewCenterY, 0);
pGLState.skewModelViewGLMatrixf(skewX, skewY);
- pGLState.translateModelViewGLMatrixf(-skewCenterX, -skewCenterY, 0);
+ pGLState.translateModelViewGLMatrixf(-localSkewCenterX, -localSkewCenterY, 0);
}
}
@@ -1315,13 +1584,13 @@ protected void applyScale(final GLState pGLState) {
final float scaleX = this.mScaleX;
final float scaleY = this.mScaleY;
- if((scaleX != 1) || (scaleY != 1)) {
- final float scaleCenterX = this.mScaleCenterX;
- final float scaleCenterY = this.mScaleCenterY;
+ if ((scaleX != 1) || (scaleY != 1)) {
+ final float localScaleCenterX = this.mLocalScaleCenterX;
+ final float localScaleCenterY = this.mLocalScaleCenterY;
- pGLState.translateModelViewGLMatrixf(scaleCenterX, scaleCenterY, 0);
+ pGLState.translateModelViewGLMatrixf(localScaleCenterX, localScaleCenterY, 0);
pGLState.scaleModelViewGLMatrixf(scaleX, scaleY, 1);
- pGLState.translateModelViewGLMatrixf(-scaleCenterX, -scaleCenterY, 0);
+ pGLState.translateModelViewGLMatrixf(-localScaleCenterX, -localScaleCenterY, 0);
}
}
@@ -1331,13 +1600,13 @@ protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
this.onApplyTransformations(pGLState);
final SmartList children = this.mChildren;
- if((children == null) || !this.mChildrenVisible) {
+ if ((children == null) || !this.mChildrenVisible) {
/* Draw only self. */
this.preDraw(pGLState, pCamera);
this.draw(pGLState, pCamera);
this.postDraw(pGLState, pCamera);
} else {
- if(this.mChildrenSortPending) {
+ if (this.mChildrenSortPending) {
ZIndexSorter.getInstance().sort(this.mChildren);
this.mChildrenSortPending = false;
}
@@ -1346,9 +1615,9 @@ protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
int i = 0;
{ /* Draw children behind this Entity. */
- for(; i < childCount; i++) {
+ for (; i < childCount; i++) {
final IEntity child = children.get(i);
- if(child.getZIndex() < 0) {
+ if (child.getZIndex() < 0) {
child.onDraw(pGLState, pCamera);
} else {
break;
@@ -1362,7 +1631,7 @@ protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
this.postDraw(pGLState, pCamera);
{ /* Draw children in front of this Entity. */
- for(; i < childCount; i++) {
+ for (; i < childCount; i++) {
children.get(i).onDraw(pGLState, pCamera);
}
}
@@ -1372,28 +1641,112 @@ protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
}
protected void onManagedUpdate(final float pSecondsElapsed) {
- if(this.mEntityModifiers != null) {
+ if (this.mEntityModifiers != null) {
this.mEntityModifiers.onUpdate(pSecondsElapsed);
}
- if(this.mUpdateHandlers != null) {
+ if (this.mUpdateHandlers != null) {
this.mUpdateHandlers.onUpdate(pSecondsElapsed);
}
- if((this.mChildren != null) && !this.mChildrenIgnoreUpdate) {
- final SmartList entities = this.mChildren;
- final int entityCount = entities.size();
- for(int i = 0; i < entityCount; i++) {
- entities.get(i).onUpdate(pSecondsElapsed);
+ if ((this.mChildren != null) && !this.mChildrenIgnoreUpdate) {
+ final SmartList children = this.mChildren;
+ final int entityCount = children.size();
+ for (int i = 0; i < entityCount; i++) {
+ final IEntity child = children.get(i);
+ child.onUpdate(pSecondsElapsed);
}
}
}
+ protected void updateLocalCenters() {
+ this.updateLocalCenterXs();
+ this.updateLocalCenterYs();
+ }
+
+ protected void updateLocalCenterXs() {
+ this.updateLocalOffsetCenterX();
+ this.updateLocalRotationCenterX();
+ this.updateLocalScaleCenterX();
+ this.updateLocalSkewCenterX();
+ }
+
+ protected void updateLocalCenterYs() {
+ this.updateLocalOffsetCenterY();
+ this.updateLocalRotationCenterY();
+ this.updateLocalScaleCenterY();
+ this.updateLocalSkewCenterY();
+ }
+
+ protected void updateLocalOffsetCenter() {
+ this.updateLocalOffsetCenterX();
+ this.updateLocalOffsetCenterY();
+ }
+
+ protected void updateLocalOffsetCenterX() {
+ this.mLocalOffsetCenterX = this.mOffsetCenterX * this.mWidth;
+ }
+
+ protected void updateLocalOffsetCenterY() {
+ this.mLocalOffsetCenterY = this.mOffsetCenterY * this.mHeight;
+ }
+
+ protected void updateLocalRotationCenter() {
+ this.updateLocalRotationCenterX();
+ this.updateLocalRotationCenterY();
+ }
+
+ protected void updateLocalRotationCenterX() {
+ this.mLocalRotationCenterX = this.mRotationCenterX * this.mWidth;
+ }
+
+ protected void updateLocalRotationCenterY() {
+ this.mLocalRotationCenterY = this.mRotationCenterY * this.mHeight;
+ }
+
+ protected void updateLocalScaleCenter() {
+ this.updateLocalScaleCenterX();
+ this.updateLocalScaleCenterY();
+ }
+
+ protected void updateLocalScaleCenterX() {
+ this.mLocalScaleCenterX = this.mScaleCenterX * this.mWidth;
+ }
+
+ protected void updateLocalScaleCenterY() {
+ this.mLocalScaleCenterY = this.mScaleCenterY * this.mHeight;
+ }
+
+ protected void updateLocalSkewCenter() {
+ this.updateLocalSkewCenterX();
+ this.updateLocalSkewCenterY();
+ }
+
+ protected void updateLocalSkewCenterX() {
+ this.mLocalSkewCenterX = this.mSkewCenterX * this.mWidth;
+ }
+
+ protected void updateLocalSkewCenterY() {
+ this.mLocalSkewCenterY = this.mSkewCenterY * this.mHeight;
+ }
+
+ public void resetRotationCenter() {
+ this.setRotationCenter(IEntity.ROTATION_CENTER_X_DEFAULT, IEntity.ROTATION_CENTER_Y_DEFAULT);
+ }
+
+ public void resetScaleCenter() {
+ this.setScaleCenter(IEntity.SCALE_CENTER_X_DEFAULT, IEntity.SCALE_CENTER_Y_DEFAULT);
+ }
+
+ public void resetSkewCenter() {
+ this.setSkewCenter(IEntity.SKEW_CENTER_X_DEFAULT, IEntity.SKEW_CENTER_Y_DEFAULT);
+ }
+
private void assertEntityHasNoParent(final IEntity pEntity) throws IllegalStateException {
- if(pEntity.hasParent()) {
+ if (pEntity.hasParent()) {
final String entityClassName = pEntity.getClass().getSimpleName();
final String currentParentClassName = pEntity.getParent().getClass().getSimpleName();
final String newParentClassName = this.getClass().getSimpleName();
- throw new IllegalStateException("pEntity '" + entityClassName +"' already has a parent: '" + currentParentClassName + "'. New parent: '" + newParentClassName + "'!");
+ throw new IllegalStateException("pEntity '" + entityClassName + "' already has a parent: '" + currentParentClassName + "'. New parent: '" + newParentClassName + "'!");
}
}
diff --git a/src/org/andengine/entity/IEntity.java b/src/org/andengine/entity/IEntity.java
index 1e3fa1919..ab8b2779c 100644
--- a/src/org/andengine/entity/IEntity.java
+++ b/src/org/andengine/entity/IEntity.java
@@ -11,25 +11,44 @@
import org.andengine.engine.handler.runnable.RunnableHandler;
import org.andengine.entity.modifier.IEntityModifier;
import org.andengine.entity.modifier.IEntityModifier.IEntityModifierMatcher;
+import org.andengine.entity.scene.ITouchArea;
import org.andengine.entity.scene.Scene;
import org.andengine.util.IDisposable;
+import org.andengine.util.adt.color.Color;
import org.andengine.util.adt.transformation.Transformation;
-import org.andengine.util.color.Color;
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 11:20:25 - 08.03.2010
*/
-public interface IEntity extends IDrawHandler, IUpdateHandler, IDisposable {
+public interface IEntity extends IDrawHandler, IUpdateHandler, IDisposable, ITouchArea {
// ===========================================================
// Constants
// ===========================================================
- public static final int TAG_INVALID = Integer.MIN_VALUE;
+ public static final int TAG_DEFAULT = 0;
+ public static final int ZINDEX_DEFAULT = 0;
+
+ public static final float OFFSET_CENTER_X_DEFAULT = 0.5f;
+ public static final float OFFSET_CENTER_Y_DEFAULT = 0.5f;
+
+ public static final float ROTATION_DEFAULT = 0;
+ public static final float ROTATION_CENTER_X_DEFAULT = 0.5f;
+ public static final float ROTATION_CENTER_Y_DEFAULT = 0.5f;
+
+ public static final float SCALE_X_DEFAULT = 1;
+ public static final float SCALE_Y_DEFAULT = 1;
+ public static final float SCALE_CENTER_X_DEFAULT = 0.5f;
+ public static final float SCALE_CENTER_Y_DEFAULT = 0.5f;
+
+ public static final float SKEW_X_DEFAULT = 0;
+ public static final float SKEW_Y_DEFAULT = 0;
+ public static final float SKEW_CENTER_X_DEFAULT = 0.5f;
+ public static final float SKEW_CENTER_Y_DEFAULT = 0.5f;
// ===========================================================
// Methods
@@ -57,6 +76,8 @@ public interface IEntity extends IDrawHandler, IUpdateHandler, IDisposable {
public IEntity getParent();
public void setParent(final IEntity pEntity);
+ public IEntity getRootEntity();
+
public float getX();
public float getY();
public void setX(final float pX);
@@ -65,6 +86,32 @@ public interface IEntity extends IDrawHandler, IUpdateHandler, IDisposable {
public void setPosition(final IEntity pOtherEntity);
public void setPosition(final float pX, final float pY);
+ public float getWidth();
+ public float getHeight();
+
+ /**
+ * It is very likely you do NOT want to use this method!
+ * @return
+ */
+ @Deprecated
+ public float getWidthScaled();
+ /**
+ * It is very likely you do NOT want to use this method!
+ * @return
+ */
+ @Deprecated
+ public float getHeightScaled();
+
+ public void setHeight(final float pHeight);
+ public void setWidth(final float pWidth);
+ public void setSize(final float pWidth, final float pHeight);
+
+ public float getOffsetCenterX();
+ public float getOffsetCenterY();
+ public void setOffsetCenterX(final float pOffsetCenterX);
+ public void setOffsetCenterY(final float pOffsetCenterY);
+ public void setOffsetCenter(final float pOffsetCenterX, final float pOffsetCenterY);
+
public boolean isRotated();
public float getRotation();
public void setRotation(final float pRotation);
@@ -103,7 +150,11 @@ public interface IEntity extends IDrawHandler, IUpdateHandler, IDisposable {
public void setSkewCenterY(final float pSkewCenterY);
public void setSkewCenter(final float pSkewCenterX, final float pSkewCenterY);
- public boolean isRotatedOrScaledOrSkewed();
+ public boolean isRotatedOrScaledOrSkewed(); // TODO What about the new offset?
+
+ public void setAnchorCenterX(final float pAnchorCenterX);
+ public void setAnchorCenterY(final float pAnchorCenterY);
+ public void setAnchorCenter(final float pAnchorCenterX, final float pAnchorCenterY);
public float getRed();
public float getGreen();
@@ -116,6 +167,7 @@ public interface IEntity extends IDrawHandler, IUpdateHandler, IDisposable {
public void setBlue(final float pBlue);
public void setAlpha(final float pAlpha);
public void setColor(final Color pColor);
+ public void setColor(final int pARGBPackedInt);
public void setColor(final float pRed, final float pGreen, final float pBlue);
public void setColor(final float pRed, final float pGreen, final float pBlue, final float pAlpha);
@@ -135,50 +187,100 @@ public interface IEntity extends IDrawHandler, IUpdateHandler, IDisposable {
* @param pY
* @return a shared(!) float[] of length 2.
*/
- public float[] convertLocalToSceneCoordinates(final float pX, final float pY);
+ public float[] convertLocalCoordinatesToParentCoordinates(final float pX, final float pY);
/**
* @param pX
* @param pY
* @param pReuse must be of length 2.
* @return pReuse as a convenience.
*/
- public float[] convertLocalToSceneCoordinates(final float pX, final float pY, final float[] pReuse);
+ public float[] convertLocalCoordinatesToParentCoordinates(final float pX, final float pY, final float[] pReuse);
/**
* @param pCoordinates must be of length 2.
* @return a shared(!) float[] of length 2.
*/
- public float[] convertLocalToSceneCoordinates(final float[] pCoordinates);
+ public float[] convertLocalCoordinatesToParentCoordinates(final float[] pCoordinates);
/**
* @param pCoordinates must be of length 2.
* @param pReuse must be of length 2.
* @return pReuse as a convenience.
*/
- public float[] convertLocalToSceneCoordinates(final float[] pCoordinates, final float[] pReuse);
+ public float[] convertLocalCoordinatesToParentCoordinates(final float[] pCoordinates, final float[] pReuse);
/**
* @param pX
* @param pY
* @return a shared(!) float[] of length 2.
*/
- public float[] convertSceneToLocalCoordinates(final float pX, final float pY);
+ public float[] convertParentCoordinatesToLocalCoordinates(final float pX, final float pY);
/**
* @param pX
* @param pY
* @param pReuse must be of length 2.
* @return pReuse as a convenience.
*/
- public float[] convertSceneToLocalCoordinates(final float pX, final float pY, final float[] pReuse);
+ public float[] convertParentCoordinatesToLocalCoordinates(final float pX, final float pY, final float[] pReuse);
/**
* @param pCoordinates must be of length 2.
* @return a shared(!) float[] of length 2.
*/
- public float[] convertSceneToLocalCoordinates(final float[] pCoordinates);
+ public float[] convertParentCoordinatesToLocalCoordinates(final float[] pCoordinates);
/**
* @param pCoordinates must be of length 2.
* @param pReuse must be of length 2.
* @return pReuse as a convenience.
*/
- public float[] convertSceneToLocalCoordinates(final float[] pCoordinates, final float[] pReuse);
+ public float[] convertParentCoordinatesToLocalCoordinates(final float[] pCoordinates, final float[] pReuse);
+
+ /**
+ * @param pX
+ * @param pY
+ * @return a shared(!) float[] of length 2.
+ */
+ public float[] convertLocalCoordinatesToSceneCoordinates(final float pX, final float pY);
+ /**
+ * @param pX
+ * @param pY
+ * @param pReuse must be of length 2.
+ * @return pReuse as a convenience.
+ */
+ public float[] convertLocalCoordinatesToSceneCoordinates(final float pX, final float pY, final float[] pReuse);
+ /**
+ * @param pCoordinates must be of length 2.
+ * @return a shared(!) float[] of length 2.
+ */
+ public float[] convertLocalCoordinatesToSceneCoordinates(final float[] pCoordinates);
+ /**
+ * @param pCoordinates must be of length 2.
+ * @param pReuse must be of length 2.
+ * @return pReuse as a convenience.
+ */
+ public float[] convertLocalCoordinatesToSceneCoordinates(final float[] pCoordinates, final float[] pReuse);
+
+ /**
+ * @param pX
+ * @param pY
+ * @return a shared(!) float[] of length 2.
+ */
+ public float[] convertSceneCoordinatesToLocalCoordinates(final float pX, final float pY);
+ /**
+ * @param pX
+ * @param pY
+ * @param pReuse must be of length 2.
+ * @return pReuse as a convenience.
+ */
+ public float[] convertSceneCoordinatesToLocalCoordinates(final float pX, final float pY, final float[] pReuse);
+ /**
+ * @param pCoordinates must be of length 2.
+ * @return a shared(!) float[] of length 2.
+ */
+ public float[] convertSceneCoordinatesToLocalCoordinates(final float[] pCoordinates);
+ /**
+ * @param pCoordinates must be of length 2.
+ * @param pReuse must be of length 2.
+ * @return pReuse as a convenience.
+ */
+ public float[] convertSceneCoordinatesToLocalCoordinates(final float[] pCoordinates, final float[] pReuse);
public Transformation getLocalToSceneTransformation();
public Transformation getSceneToLocalTransformation();
@@ -241,9 +343,9 @@ public interface IEntity extends IDrawHandler, IUpdateHandler, IDisposable {
public void sortChildren();
/**
* Sorts the {@link IEntity}s based on their ZIndex. Sort is stable.
- * In contrast to {@link IEntity#sortChildren()} this method is particularly useful to avoid multiple sorts per frame.
+ * In contrast to {@link #sortChildren()} this method is particularly useful to avoid multiple sorts per frame.
* @param pImmediate if true, the sorting is executed immediately.
- * If false the sorting is executed before the next (visible) drawing of the children of this {@link IEntity}.
+ * If false the sorting is executed before the next (visible) drawing of the children of this {@link IEntity}.
*/
public void sortChildren(final boolean pImmediate);
/**
@@ -295,23 +397,28 @@ public interface IEntity extends IDrawHandler, IUpdateHandler, IDisposable {
public void registerUpdateHandler(final IUpdateHandler pUpdateHandler);
public boolean unregisterUpdateHandler(final IUpdateHandler pUpdateHandler);
public boolean unregisterUpdateHandlers(final IUpdateHandlerMatcher pUpdateHandlerMatcher);
+ public int getUpdateHandlerCount();
public void clearUpdateHandlers();
public void registerEntityModifier(final IEntityModifier pEntityModifier);
public boolean unregisterEntityModifier(final IEntityModifier pEntityModifier);
public boolean unregisterEntityModifiers(final IEntityModifierMatcher pEntityModifierMatcher);
+ public int getEntityModifierCount();
+ public void resetEntityModifiers();
public void clearEntityModifiers();
public boolean isCullingEnabled();
public void setCullingEnabled(final boolean pCullingEnabled);
/**
- * Will only be performed if {@link IEntity#isCullingEnabled()} is true.
+ * Will only be performed if {@link #isCullingEnabled()} is true.
*
* @param pCamera the currently active camera to perform culling checks against.
* @return true when this object is visible by the {@link Camera}, false otherwise.
*/
public boolean isCulled(final Camera pCamera);
+ public boolean collidesWith(final IEntity pOtherEntity);
+
public void setUserData(final Object pUserData);
public Object getUserData();
diff --git a/src/org/andengine/entity/IEntityComparator.java b/src/org/andengine/entity/IEntityComparator.java
index ee8b5b444..6982da43b 100644
--- a/src/org/andengine/entity/IEntityComparator.java
+++ b/src/org/andengine/entity/IEntityComparator.java
@@ -3,7 +3,7 @@
import java.util.Comparator;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 14:02:56 - 10.04.2012
diff --git a/src/org/andengine/entity/IEntityFactory.java b/src/org/andengine/entity/IEntityFactory.java
index 02072e318..538081715 100644
--- a/src/org/andengine/entity/IEntityFactory.java
+++ b/src/org/andengine/entity/IEntityFactory.java
@@ -2,12 +2,12 @@
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 20:04:41 - 19.11.2011
*/
-public interface IEntityFactory {
+public interface IEntityFactory {
// ===========================================================
// Constants
// ===========================================================
diff --git a/src/org/andengine/entity/IEntityMatcher.java b/src/org/andengine/entity/IEntityMatcher.java
index 11cf25865..41477c68e 100644
--- a/src/org/andengine/entity/IEntityMatcher.java
+++ b/src/org/andengine/entity/IEntityMatcher.java
@@ -3,7 +3,7 @@
import org.andengine.util.IMatcher;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 20:06:28 - 26.03.2012
diff --git a/src/org/andengine/entity/IEntityParameterCallable.java b/src/org/andengine/entity/IEntityParameterCallable.java
index 7a5d08808..325fe32dc 100644
--- a/src/org/andengine/entity/IEntityParameterCallable.java
+++ b/src/org/andengine/entity/IEntityParameterCallable.java
@@ -3,7 +3,7 @@
import org.andengine.util.call.ParameterCallable;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 20:06:53 - 26.03.2012
diff --git a/src/org/andengine/entity/TagEntityMatcher.java b/src/org/andengine/entity/TagEntityMatcher.java
index 7d516a5ef..c18ad601a 100644
--- a/src/org/andengine/entity/TagEntityMatcher.java
+++ b/src/org/andengine/entity/TagEntityMatcher.java
@@ -1,7 +1,7 @@
package org.andengine.entity;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 15:49:11 - 01.05.2012
diff --git a/src/org/andengine/entity/ZIndexSorter.java b/src/org/andengine/entity/ZIndexSorter.java
index 33d5e8972..031ac78f9 100644
--- a/src/org/andengine/entity/ZIndexSorter.java
+++ b/src/org/andengine/entity/ZIndexSorter.java
@@ -7,8 +7,8 @@
import org.andengine.util.algorithm.sort.InsertionSorter;
/**
- * (c) Nicolas Gramlich 2010
- * (c) Zynga 2011
+ * (c) 2010 Nicolas Gramlich
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 12:08:56 - 06.08.2010
@@ -40,7 +40,7 @@ private ZIndexSorter() {
}
public static ZIndexSorter getInstance() {
- if(INSTANCE == null) {
+ if (INSTANCE == null) {
INSTANCE = new ZIndexSorter();
}
return INSTANCE;
diff --git a/src/org/andengine/entity/clip/ClipEntity.java b/src/org/andengine/entity/clip/ClipEntity.java
new file mode 100644
index 000000000..d8aa4d50f
--- /dev/null
+++ b/src/org/andengine/entity/clip/ClipEntity.java
@@ -0,0 +1,121 @@
+package org.andengine.entity.clip;
+
+import org.andengine.engine.camera.Camera;
+import org.andengine.entity.Entity;
+import org.andengine.opengl.util.GLState;
+import org.andengine.util.Constants;
+import org.andengine.util.math.MathUtils;
+
+/**
+ * A {@link ClipEntity} clips drawing of all its children in a rectangle, which is defined as the axis aligned bounding box around itself.
+ * It can be attached anywhere in the scene graph, which means that it inherits transformations from its parents, which have a direct effect on the clipping area.
+ *
+ * (c) 2012 Zynga Inc.
+ *
+ * @author Nicolas Gramlich
+ * @since 13:53:29 - 10.05.2012
+ */
+public class ClipEntity extends Entity {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ private boolean mClippingEnabled = true;
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ public ClipEntity() {
+ super();
+ }
+
+ public ClipEntity(final float pX, final float pY) {
+ super(pX, pY);
+ }
+
+ public ClipEntity(final float pX, final float pY, final float pWidth, final float pHeight) {
+ super(pX, pY, pWidth, pHeight);
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ public boolean isClippingEnabled() {
+ return this.mClippingEnabled;
+ }
+
+ public void setClippingEnabled(final boolean pClippingEnabled) {
+ this.mClippingEnabled = pClippingEnabled;
+ }
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ @Override
+ protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
+ if (this.mClippingEnabled) {
+ /* Enable scissor test, while remembering previous state. */
+ final boolean wasScissorTestEnabled = pGLState.enableScissorTest();
+
+ final int surfaceHeight = pCamera.getSurfaceHeight();
+
+ /* In order to apply clipping, we need to determine the the axis aligned bounds in OpenGL coordinates. */
+
+ /* Determine clipping coordinates of each corner in surface coordinates. */
+ final float[] lowerLeftSurfaceCoordinates = pCamera.getSurfaceCoordinatesFromSceneCoordinates(this.convertLocalCoordinatesToSceneCoordinates(0, 0));
+ final int lowerLeftX = (int) Math.round(lowerLeftSurfaceCoordinates[Constants.VERTEX_INDEX_X]);
+ final int lowerLeftY = surfaceHeight - (int) Math.round(lowerLeftSurfaceCoordinates[Constants.VERTEX_INDEX_Y]);
+
+ final float[] upperLeftSurfaceCoordinates = pCamera.getSurfaceCoordinatesFromSceneCoordinates(this.convertLocalCoordinatesToSceneCoordinates(0, this.mHeight));
+ final int upperLeftX = (int) Math.round(upperLeftSurfaceCoordinates[Constants.VERTEX_INDEX_X]);
+ final int upperLeftY = surfaceHeight - (int) Math.round(upperLeftSurfaceCoordinates[Constants.VERTEX_INDEX_Y]);
+
+ final float[] upperRightSurfaceCoordinates = pCamera.getSurfaceCoordinatesFromSceneCoordinates(this.convertLocalCoordinatesToSceneCoordinates(this.mWidth, this.mHeight));
+ final int upperRightX = (int) Math.round(upperRightSurfaceCoordinates[Constants.VERTEX_INDEX_X]);
+ final int upperRightY = surfaceHeight - (int) Math.round(upperRightSurfaceCoordinates[Constants.VERTEX_INDEX_Y]);
+
+ final float[] lowerRightSurfaceCoordinates = pCamera.getSurfaceCoordinatesFromSceneCoordinates(this.convertLocalCoordinatesToSceneCoordinates(this.mWidth, 0));
+ final int lowerRightX = (int) Math.round(lowerRightSurfaceCoordinates[Constants.VERTEX_INDEX_X]);
+ final int lowerRightY = surfaceHeight - (int) Math.round(lowerRightSurfaceCoordinates[Constants.VERTEX_INDEX_Y]);
+
+ /* Determine minimum and maximum x clipping coordinates. */
+ final int minClippingX = MathUtils.min(lowerLeftX, upperLeftX, upperRightX, lowerRightX);
+ final int maxClippingX = MathUtils.max(lowerLeftX, upperLeftX, upperRightX, lowerRightX);
+
+ /* Determine minimum and maximum y clipping coordinates. */
+ final int minClippingY = MathUtils.min(lowerLeftY, upperLeftY, upperRightY, lowerRightY);
+ final int maxClippingY = MathUtils.max(lowerLeftY, upperLeftY, upperRightY, lowerRightY);
+
+ /* Determine clipping width and height. */
+ final int clippingWidth = maxClippingX - minClippingX;
+ final int clippingHeight = maxClippingY - minClippingY;
+
+ /* Finally apply the clipping. */
+ pGLState.glPushScissor(minClippingX, minClippingY, clippingWidth, clippingHeight);
+
+ /* Draw children, etc... */
+ super.onManagedDraw(pGLState, pCamera);
+
+ /* Revert scissor test to previous state. */
+ pGLState.glPopScissor();
+ pGLState.setScissorTestEnabled(wasScissorTestEnabled);
+ } else {
+ super.onManagedDraw(pGLState, pCamera);
+ }
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
diff --git a/src/org/andengine/entity/modifier/AlphaModifier.java b/src/org/andengine/entity/modifier/AlphaModifier.java
index ce905b317..f25a37c22 100644
--- a/src/org/andengine/entity/modifier/AlphaModifier.java
+++ b/src/org/andengine/entity/modifier/AlphaModifier.java
@@ -5,9 +5,9 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 23:13:01 - 19.03.2010
*/
@@ -45,7 +45,7 @@ protected AlphaModifier(final AlphaModifier pAlphaModifier) {
}
@Override
- public AlphaModifier deepCopy(){
+ public AlphaModifier deepCopy() {
return new AlphaModifier(this);
}
diff --git a/src/org/andengine/entity/modifier/CardinalSplineMoveModifier.java b/src/org/andengine/entity/modifier/CardinalSplineMoveModifier.java
index c0c6e977d..09fd5f2f5 100644
--- a/src/org/andengine/entity/modifier/CardinalSplineMoveModifier.java
+++ b/src/org/andengine/entity/modifier/CardinalSplineMoveModifier.java
@@ -7,12 +7,13 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 11:47:24 - 20.03.2012
- * @see {@link http://en.wikipedia.org/wiki/Cubic_Hermite_spline#Cardinal_spline}
- * @see {@link http://algorithmist.wordpress.com/2009/10/06/cardinal-splines-part-4/}
+ *
+ * @see en.wikipedia.org/wiki/Cubic_Hermite_spline#Cardinal_spline
+ * @see algorithmist.wordpress.com/2009/10/06/cardinal-splines-part-4/
*/
public class CardinalSplineMoveModifier extends DurationEntityModifier {
// ===========================================================
@@ -84,7 +85,7 @@ protected void onManagedUpdate(final float pSecondsElapsed, final IEntity pEntit
/* Calculate active control point. */
final int p;
- if(percentageDone == 1) {
+ if (percentageDone == 1) {
p = this.mControlSegmentCount;
} else {
p = (int) (percentageDone / this.mControlSegmentCountInverse);
@@ -192,7 +193,7 @@ public static class CardinalSplineMoveModifierConfig {
* @param pTension [-1, 1]
*/
public CardinalSplineMoveModifierConfig(final int pControlPointCount, final float pTension) {
- if(pControlPointCount < CardinalSplineMoveModifierConfig.CONTROLPOINT_COUNT_MINIMUM) {
+ if (pControlPointCount < CardinalSplineMoveModifierConfig.CONTROLPOINT_COUNT_MINIMUM) {
throw new IllegalArgumentException("A " + CardinalSplineMoveModifierConfig.class.getSimpleName() + " needs at least " + CardinalSplineMoveModifierConfig.CONTROLPOINT_COUNT_MINIMUM + " control points.");
}
diff --git a/src/org/andengine/entity/modifier/CatmullRomSplineMoveModifier.java b/src/org/andengine/entity/modifier/CatmullRomSplineMoveModifier.java
index afc63f38b..f7c4da57c 100644
--- a/src/org/andengine/entity/modifier/CatmullRomSplineMoveModifier.java
+++ b/src/org/andengine/entity/modifier/CatmullRomSplineMoveModifier.java
@@ -3,7 +3,7 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 11:51:22 - 21.03.2012
@@ -53,7 +53,7 @@ public CatmullRomSplineMoveModifier(final float pDuration, final CatmullRomMoveM
// Inner and Anonymous Classes
// ===========================================================
- public class CatmullRomMoveModifierConfig extends CardinalSplineMoveModifierConfig {
+ public static class CatmullRomMoveModifierConfig extends CardinalSplineMoveModifierConfig {
// ===========================================================
// Constants
// ===========================================================
diff --git a/src/org/andengine/entity/modifier/ColorModifier.java b/src/org/andengine/entity/modifier/ColorModifier.java
index e230dcf76..e482502e3 100644
--- a/src/org/andengine/entity/modifier/ColorModifier.java
+++ b/src/org/andengine/entity/modifier/ColorModifier.java
@@ -1,14 +1,14 @@
package org.andengine.entity.modifier;
import org.andengine.entity.IEntity;
-import org.andengine.util.color.Color;
+import org.andengine.util.adt.color.Color;
import org.andengine.util.modifier.ease.EaseLinear;
import org.andengine.util.modifier.ease.IEaseFunction;
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:39:50 - 29.06.2010
*/
@@ -62,7 +62,7 @@ protected ColorModifier(final ColorModifier pColorModifier) {
}
@Override
- public ColorModifier deepCopy(){
+ public ColorModifier deepCopy() {
return new ColorModifier(this);
}
diff --git a/src/org/andengine/entity/modifier/CubicBezierCurveMoveModifier.java b/src/org/andengine/entity/modifier/CubicBezierCurveMoveModifier.java
index 343b74458..4a6542d4c 100644
--- a/src/org/andengine/entity/modifier/CubicBezierCurveMoveModifier.java
+++ b/src/org/andengine/entity/modifier/CubicBezierCurveMoveModifier.java
@@ -7,7 +7,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Pawel Plewa
* @author Nicolas Gramlich
* @since 23:24:26 - 16.07.2011
@@ -126,7 +126,7 @@ public CubicBezierCurveMoveModifier deepCopy() {
@Override
protected void onManagedInitialize(final IEntity pEntity) {
-
+
}
@Override
diff --git a/src/org/andengine/entity/modifier/DelayModifier.java b/src/org/andengine/entity/modifier/DelayModifier.java
index 8366fed65..f66c61138 100644
--- a/src/org/andengine/entity/modifier/DelayModifier.java
+++ b/src/org/andengine/entity/modifier/DelayModifier.java
@@ -3,9 +3,9 @@
import org.andengine.entity.IEntity;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 22:55:13 - 19.03.2010
*/
@@ -35,7 +35,7 @@ protected DelayModifier(final DelayModifier pDelayModifier) {
}
@Override
- public DelayModifier deepCopy(){
+ public DelayModifier deepCopy() {
return new DelayModifier(this);
}
diff --git a/src/org/andengine/entity/modifier/DoubleValueChangeEntityModifier.java b/src/org/andengine/entity/modifier/DoubleValueChangeEntityModifier.java
index 45225ce83..b17ff5656 100644
--- a/src/org/andengine/entity/modifier/DoubleValueChangeEntityModifier.java
+++ b/src/org/andengine/entity/modifier/DoubleValueChangeEntityModifier.java
@@ -4,7 +4,7 @@
import org.andengine.util.modifier.BaseDoubleValueChangeModifier;
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 14:27:48 - 10.08.2011
diff --git a/src/org/andengine/entity/modifier/DoubleValueSpanEntityModifier.java b/src/org/andengine/entity/modifier/DoubleValueSpanEntityModifier.java
index 6158e9fdd..a5b87712d 100644
--- a/src/org/andengine/entity/modifier/DoubleValueSpanEntityModifier.java
+++ b/src/org/andengine/entity/modifier/DoubleValueSpanEntityModifier.java
@@ -5,9 +5,9 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 23:29:22 - 19.03.2010
*/
diff --git a/src/org/andengine/entity/modifier/DurationEntityModifier.java b/src/org/andengine/entity/modifier/DurationEntityModifier.java
index bf751878a..01f3ef530 100644
--- a/src/org/andengine/entity/modifier/DurationEntityModifier.java
+++ b/src/org/andengine/entity/modifier/DurationEntityModifier.java
@@ -4,9 +4,9 @@
import org.andengine.util.modifier.BaseDurationModifier;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 16:10:42 - 19.03.2010
*/
diff --git a/src/org/andengine/entity/modifier/EntityModifier.java b/src/org/andengine/entity/modifier/EntityModifier.java
index 1953a6722..fc8d7c80a 100644
--- a/src/org/andengine/entity/modifier/EntityModifier.java
+++ b/src/org/andengine/entity/modifier/EntityModifier.java
@@ -4,9 +4,9 @@
import org.andengine.util.modifier.BaseModifier;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 10:53:16 - 03.09.2010
*/
diff --git a/src/org/andengine/entity/modifier/EntityModifierList.java b/src/org/andengine/entity/modifier/EntityModifierList.java
index 1af8dcd9a..70bafd2eb 100644
--- a/src/org/andengine/entity/modifier/EntityModifierList.java
+++ b/src/org/andengine/entity/modifier/EntityModifierList.java
@@ -4,9 +4,9 @@
import org.andengine.util.modifier.ModifierList;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 14:19:18 - 24.12.2010
*/
diff --git a/src/org/andengine/entity/modifier/FadeInModifier.java b/src/org/andengine/entity/modifier/FadeInModifier.java
index 40c98e579..6c40b4e22 100644
--- a/src/org/andengine/entity/modifier/FadeInModifier.java
+++ b/src/org/andengine/entity/modifier/FadeInModifier.java
@@ -5,9 +5,9 @@
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 19:03:12 - 08.06.2010
*/
diff --git a/src/org/andengine/entity/modifier/FadeOutModifier.java b/src/org/andengine/entity/modifier/FadeOutModifier.java
index e89a9fb14..e325875ae 100644
--- a/src/org/andengine/entity/modifier/FadeOutModifier.java
+++ b/src/org/andengine/entity/modifier/FadeOutModifier.java
@@ -5,9 +5,9 @@
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 19:03:12 - 08.06.2010
*/
diff --git a/src/org/andengine/entity/modifier/IEntityModifier.java b/src/org/andengine/entity/modifier/IEntityModifier.java
index d7167d180..3ac327a21 100644
--- a/src/org/andengine/entity/modifier/IEntityModifier.java
+++ b/src/org/andengine/entity/modifier/IEntityModifier.java
@@ -5,9 +5,9 @@
import org.andengine.util.modifier.IModifier;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 11:17:50 - 19.03.2010
*/
@@ -19,7 +19,7 @@ public interface IEntityModifier extends IModifier {
// ===========================================================
// Methods
// ===========================================================
-
+
@Override
public IEntityModifier deepCopy() throws DeepCopyNotSupportedException;
@@ -27,7 +27,7 @@ public interface IEntityModifier extends IModifier {
// Inner and Anonymous Classes
// ===========================================================
- public static interface IEntityModifierListener extends IModifierListener{
+ public static interface IEntityModifierListener extends IModifierListener {
// ===========================================================
// Constants
// ===========================================================
@@ -36,7 +36,7 @@ public static interface IEntityModifierListener extends IModifierListener> {
// ===========================================================
// Constants
diff --git a/src/org/andengine/entity/modifier/JumpModifier.java b/src/org/andengine/entity/modifier/JumpModifier.java
index a98f444dd..96d732bd7 100644
--- a/src/org/andengine/entity/modifier/JumpModifier.java
+++ b/src/org/andengine/entity/modifier/JumpModifier.java
@@ -5,7 +5,7 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 12:12:55 - 11.01.2012
@@ -57,7 +57,7 @@ public JumpModifier(final float pDuration, final float pFromX, final float pToX,
}
public JumpModifier(final float pDuration, final float pFromX, final float pToX, final float pFromY, final float pToY, final float pJumpHeight, final int pJumpCount, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) {
- super(pDuration, pFromX, pToX, pFromY, pToY, pEntityModifierListener, pEaseFunction);
+ super(pDuration, pFromX, pFromY, pToX, pToY, pEntityModifierListener, pEaseFunction);
this.mJumpHeight = pJumpHeight;
this.mJumpCount = pJumpCount;
diff --git a/src/org/andengine/entity/modifier/LoopEntityModifier.java b/src/org/andengine/entity/modifier/LoopEntityModifier.java
index 1f5fde527..6eb8638e4 100644
--- a/src/org/andengine/entity/modifier/LoopEntityModifier.java
+++ b/src/org/andengine/entity/modifier/LoopEntityModifier.java
@@ -4,9 +4,9 @@
import org.andengine.util.modifier.LoopModifier;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 12:42:13 - 03.09.2010
*/
diff --git a/src/org/andengine/entity/modifier/MoveByModifier.java b/src/org/andengine/entity/modifier/MoveByModifier.java
index 571d8a7b5..535fd1ee3 100644
--- a/src/org/andengine/entity/modifier/MoveByModifier.java
+++ b/src/org/andengine/entity/modifier/MoveByModifier.java
@@ -4,7 +4,7 @@
/**
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 14:15:52 - 10.08.2011
*/
@@ -34,7 +34,7 @@ protected MoveByModifier(final DoubleValueChangeEntityModifier pDoubleValueChang
}
@Override
- public MoveByModifier deepCopy(){
+ public MoveByModifier deepCopy() {
return new MoveByModifier(this);
}
diff --git a/src/org/andengine/entity/modifier/MoveModifier.java b/src/org/andengine/entity/modifier/MoveModifier.java
index 6cd19afc0..f4abbb4e9 100644
--- a/src/org/andengine/entity/modifier/MoveModifier.java
+++ b/src/org/andengine/entity/modifier/MoveModifier.java
@@ -5,9 +5,9 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 16:12:52 - 19.03.2010
*/
@@ -24,19 +24,19 @@ public class MoveModifier extends DoubleValueSpanEntityModifier {
// Constructors
// ===========================================================
- public MoveModifier(final float pDuration, final float pFromX, final float pToX, final float pFromY, final float pToY) {
- this(pDuration, pFromX, pToX, pFromY, pToY, null, EaseLinear.getInstance());
+ public MoveModifier(final float pDuration, final float pFromX, final float pFromY, final float pToX, final float pToY) {
+ this(pDuration, pFromX, pFromY, pToX, pToY, null, EaseLinear.getInstance());
}
- public MoveModifier(final float pDuration, final float pFromX, final float pToX, final float pFromY, final float pToY, final IEaseFunction pEaseFunction) {
- this(pDuration, pFromX, pToX, pFromY, pToY, null, pEaseFunction);
+ public MoveModifier(final float pDuration, final float pFromX, final float pFromY, final float pToX, final float pToY, final IEaseFunction pEaseFunction) {
+ this(pDuration, pFromX, pFromY, pToX, pToY, null, pEaseFunction);
}
- public MoveModifier(final float pDuration, final float pFromX, final float pToX, final float pFromY, final float pToY, final IEntityModifierListener pEntityModifierListener) {
+ public MoveModifier(final float pDuration, final float pFromX, final float pFromY, final float pToX, final float pToY, final IEntityModifierListener pEntityModifierListener) {
super(pDuration, pFromX, pToX, pFromY, pToY, pEntityModifierListener, EaseLinear.getInstance());
}
- public MoveModifier(final float pDuration, final float pFromX, final float pToX, final float pFromY, final float pToY, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) {
+ public MoveModifier(final float pDuration, final float pFromX, final float pFromY, final float pToX, final float pToY, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) {
super(pDuration, pFromX, pToX, pFromY, pToY, pEntityModifierListener, pEaseFunction);
}
@@ -45,7 +45,7 @@ protected MoveModifier(final MoveModifier pMoveModifier) {
}
@Override
- public MoveModifier deepCopy(){
+ public MoveModifier deepCopy() {
return new MoveModifier(this);
}
diff --git a/src/org/andengine/entity/modifier/MoveXModifier.java b/src/org/andengine/entity/modifier/MoveXModifier.java
index ac56db7cb..ba0390b56 100644
--- a/src/org/andengine/entity/modifier/MoveXModifier.java
+++ b/src/org/andengine/entity/modifier/MoveXModifier.java
@@ -5,9 +5,9 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 12:03:22 - 30.08.2010
*/
@@ -45,7 +45,7 @@ protected MoveXModifier(final MoveXModifier pMoveXModifier) {
}
@Override
- public MoveXModifier deepCopy(){
+ public MoveXModifier deepCopy() {
return new MoveXModifier(this);
}
diff --git a/src/org/andengine/entity/modifier/MoveYModifier.java b/src/org/andengine/entity/modifier/MoveYModifier.java
index 11ad53887..06ba983eb 100644
--- a/src/org/andengine/entity/modifier/MoveYModifier.java
+++ b/src/org/andengine/entity/modifier/MoveYModifier.java
@@ -5,9 +5,9 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 12:04:21 - 30.08.2010
*/
@@ -45,7 +45,7 @@ protected MoveYModifier(final MoveYModifier pMoveYModifier) {
}
@Override
- public MoveYModifier deepCopy(){
+ public MoveYModifier deepCopy() {
return new MoveYModifier(this);
}
diff --git a/src/org/andengine/entity/modifier/ParallelEntityModifier.java b/src/org/andengine/entity/modifier/ParallelEntityModifier.java
index 5b9a25521..d0dc539dd 100644
--- a/src/org/andengine/entity/modifier/ParallelEntityModifier.java
+++ b/src/org/andengine/entity/modifier/ParallelEntityModifier.java
@@ -4,9 +4,9 @@
import org.andengine.util.modifier.ParallelModifier;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 12:40:31 - 03.09.2010
*/
diff --git a/src/org/andengine/entity/modifier/PathModifier.java b/src/org/andengine/entity/modifier/PathModifier.java
index 453f7e0b1..6845a0220 100644
--- a/src/org/andengine/entity/modifier/PathModifier.java
+++ b/src/org/andengine/entity/modifier/PathModifier.java
@@ -7,12 +7,10 @@
import org.andengine.util.modifier.ease.EaseLinear;
import org.andengine.util.modifier.ease.IEaseFunction;
-import android.util.FloatMath;
-
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 16:50:02 - 16.06.2010
*/
@@ -82,9 +80,9 @@ public PathModifier(final float pDuration, final Path pPath, final IEntityModifi
final float velocity = pPath.getLength() / pDuration;
final int modifierCount = moveModifiers.length;
- for(int i = 0; i < modifierCount; i++) {
+ for (int i = 0; i < modifierCount; i++) {
final float duration = pPath.getSegmentLength(i) / velocity;
- moveModifiers[i] = new MoveModifier(duration, coordinatesX[i], coordinatesX[i + 1], coordinatesY[i], coordinatesY[i + 1], null, pEaseFunction);
+ moveModifiers[i] = new MoveModifier(duration, coordinatesX[i], coordinatesY[i], coordinatesX[i + 1], coordinatesY[i + 1], null, pEaseFunction);
}
/* Create a new SequenceModifier and register the listeners that
@@ -93,14 +91,14 @@ public PathModifier(final float pDuration, final Path pPath, final IEntityModifi
new ISubSequenceModifierListener() {
@Override
public void onSubSequenceStarted(final IModifier pModifier, final IEntity pEntity, final int pIndex) {
- if(PathModifier.this.mPathModifierListener != null) {
+ if (PathModifier.this.mPathModifierListener != null) {
PathModifier.this.mPathModifierListener.onPathWaypointStarted(PathModifier.this, pEntity, pIndex);
}
}
@Override
public void onSubSequenceFinished(final IModifier pEntityModifier, final IEntity pEntity, final int pIndex) {
- if(PathModifier.this.mPathModifierListener != null) {
+ if (PathModifier.this.mPathModifierListener != null) {
PathModifier.this.mPathModifierListener.onPathWaypointFinished(PathModifier.this, pEntity, pIndex);
}
}
@@ -109,7 +107,7 @@ public void onSubSequenceFinished(final IModifier pEntityModifier, fina
@Override
public void onModifierStarted(final IModifier pModifier, final IEntity pEntity) {
PathModifier.this.onModifierStarted(pEntity);
- if(PathModifier.this.mPathModifierListener != null) {
+ if (PathModifier.this.mPathModifierListener != null) {
PathModifier.this.mPathModifierListener.onPathStarted(PathModifier.this, pEntity);
}
}
@@ -117,7 +115,7 @@ public void onModifierStarted(final IModifier pModifier, final IEntity
@Override
public void onModifierFinished(final IModifier pEntityModifier, final IEntity pEntity) {
PathModifier.this.onModifierFinished(pEntity);
- if(PathModifier.this.mPathModifierListener != null) {
+ if (PathModifier.this.mPathModifierListener != null) {
PathModifier.this.mPathModifierListener.onPathFinished(PathModifier.this, pEntity);
}
}
@@ -217,7 +215,7 @@ public static class Path {
private final float[] mYs;
private int mIndex;
- private boolean mLengthChanged = false;
+ private boolean mLengthChanged;
private float mLength;
// ===========================================================
@@ -276,6 +274,18 @@ public Path to(final float pX, final float pY) {
return this;
}
+ public Path to(final int pIndex) {
+ return this.to(this.getX(pIndex), this.getY(pIndex));
+ }
+
+ private float getX(final int pIndex) {
+ return this.mXs[pIndex];
+ }
+
+ private float getY(final int pIndex) {
+ return this.mYs[pIndex];
+ }
+
public float[] getCoordinatesX() {
return this.mXs;
}
@@ -289,7 +299,7 @@ public int getSize() {
}
public float getLength() {
- if(this.mLengthChanged) {
+ if (this.mLengthChanged) {
this.updateLength();
}
return this.mLength;
@@ -304,7 +314,7 @@ public float getSegmentLength(final int pSegmentIndex) {
final float dx = coordinatesX[pSegmentIndex] - coordinatesX[nextSegmentIndex];
final float dy = coordinatesY[pSegmentIndex] - coordinatesY[nextSegmentIndex];
- return FloatMath.sqrt(dx * dx + dy * dy);
+ return (float) Math.sqrt(dx * dx + dy * dy);
}
// ===========================================================
@@ -318,7 +328,7 @@ public float getSegmentLength(final int pSegmentIndex) {
private void updateLength() {
float length = 0.0f;
- for(int i = this.mIndex - 2; i >= 0; i--) {
+ for (int i = this.mIndex - 2; i >= 0; i--) {
length += this.getSegmentLength(i);
}
this.mLength = length;
diff --git a/src/org/andengine/entity/modifier/QuadraticBezierCurveMoveModifier.java b/src/org/andengine/entity/modifier/QuadraticBezierCurveMoveModifier.java
index be9f6fa69..d3a236a3f 100644
--- a/src/org/andengine/entity/modifier/QuadraticBezierCurveMoveModifier.java
+++ b/src/org/andengine/entity/modifier/QuadraticBezierCurveMoveModifier.java
@@ -7,7 +7,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 23:24:26 - 16.07.2011
*/
@@ -121,8 +121,8 @@ protected void onManagedUpdate(final float pSecondsElapsed, final IEntity pEntit
final float percentageDone = this.mEaseFunction.getPercentage(this.getSecondsElapsed(), this.mDuration);
final float u = 1 - percentageDone;
- final float tt = percentageDone*percentageDone;
- final float uu = u*u;
+ final float tt = percentageDone * percentageDone;
+ final float uu = u * u;
final float ut2 = 2 * u * percentageDone;
diff --git a/src/org/andengine/entity/modifier/RotationAtModifier.java b/src/org/andengine/entity/modifier/RotationAtModifier.java
index 6d3c960aa..5c3d12a31 100644
--- a/src/org/andengine/entity/modifier/RotationAtModifier.java
+++ b/src/org/andengine/entity/modifier/RotationAtModifier.java
@@ -6,9 +6,9 @@
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 21:59:38 - 06.07.2010
*/
@@ -55,7 +55,7 @@ protected RotationAtModifier(final RotationAtModifier pRotationAtModifier) {
}
@Override
- public RotationAtModifier deepCopy(){
+ public RotationAtModifier deepCopy() {
return new RotationAtModifier(this);
}
diff --git a/src/org/andengine/entity/modifier/RotationByModifier.java b/src/org/andengine/entity/modifier/RotationByModifier.java
index 663c3eaca..c07446081 100644
--- a/src/org/andengine/entity/modifier/RotationByModifier.java
+++ b/src/org/andengine/entity/modifier/RotationByModifier.java
@@ -3,9 +3,9 @@
import org.andengine.entity.IEntity;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 16:12:52 - 19.03.2010
*/
@@ -35,7 +35,7 @@ protected RotationByModifier(final RotationByModifier pRotationByModifier) {
}
@Override
- public RotationByModifier deepCopy(){
+ public RotationByModifier deepCopy() {
return new RotationByModifier(this);
}
diff --git a/src/org/andengine/entity/modifier/RotationModifier.java b/src/org/andengine/entity/modifier/RotationModifier.java
index 27201a59d..59a89c1ac 100644
--- a/src/org/andengine/entity/modifier/RotationModifier.java
+++ b/src/org/andengine/entity/modifier/RotationModifier.java
@@ -5,9 +5,9 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 16:12:52 - 19.03.2010
*/
@@ -45,7 +45,7 @@ protected RotationModifier(final RotationModifier pRotationModifier) {
}
@Override
- public RotationModifier deepCopy(){
+ public RotationModifier deepCopy() {
return new RotationModifier(this);
}
diff --git a/src/org/andengine/entity/modifier/ScaleAtModifier.java b/src/org/andengine/entity/modifier/ScaleAtModifier.java
index 1620a4e90..4bc3953ae 100644
--- a/src/org/andengine/entity/modifier/ScaleAtModifier.java
+++ b/src/org/andengine/entity/modifier/ScaleAtModifier.java
@@ -6,9 +6,9 @@
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 21:53:30 - 06.07.2010
*/
@@ -71,7 +71,7 @@ protected ScaleAtModifier(final ScaleAtModifier pScaleAtModifier) {
}
@Override
- public ScaleAtModifier deepCopy(){
+ public ScaleAtModifier deepCopy() {
return new ScaleAtModifier(this);
}
diff --git a/src/org/andengine/entity/modifier/ScaleModifier.java b/src/org/andengine/entity/modifier/ScaleModifier.java
index acd2c3cf1..bb52d3ce8 100644
--- a/src/org/andengine/entity/modifier/ScaleModifier.java
+++ b/src/org/andengine/entity/modifier/ScaleModifier.java
@@ -5,9 +5,9 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 23:37:53 - 19.03.2010
*/
@@ -61,7 +61,7 @@ protected ScaleModifier(final ScaleModifier pScaleModifier) {
}
@Override
- public ScaleModifier deepCopy(){
+ public ScaleModifier deepCopy() {
return new ScaleModifier(this);
}
diff --git a/src/org/andengine/entity/modifier/SequenceEntityModifier.java b/src/org/andengine/entity/modifier/SequenceEntityModifier.java
index 416fd7be5..4ed06c5fe 100644
--- a/src/org/andengine/entity/modifier/SequenceEntityModifier.java
+++ b/src/org/andengine/entity/modifier/SequenceEntityModifier.java
@@ -4,9 +4,9 @@
import org.andengine.util.modifier.SequenceModifier;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 12:41:15 - 03.09.2010
*/
diff --git a/src/org/andengine/entity/modifier/SingleValueChangeEntityModifier.java b/src/org/andengine/entity/modifier/SingleValueChangeEntityModifier.java
index dc9dd8023..cdcc35d2a 100644
--- a/src/org/andengine/entity/modifier/SingleValueChangeEntityModifier.java
+++ b/src/org/andengine/entity/modifier/SingleValueChangeEntityModifier.java
@@ -4,9 +4,9 @@
import org.andengine.util.modifier.BaseSingleValueChangeModifier;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:34:35 - 17.06.2010
*/
diff --git a/src/org/andengine/entity/modifier/SingleValueSpanEntityModifier.java b/src/org/andengine/entity/modifier/SingleValueSpanEntityModifier.java
index d18d79d26..bea60d136 100644
--- a/src/org/andengine/entity/modifier/SingleValueSpanEntityModifier.java
+++ b/src/org/andengine/entity/modifier/SingleValueSpanEntityModifier.java
@@ -5,9 +5,9 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 23:29:22 - 19.03.2010
*/
diff --git a/src/org/andengine/entity/modifier/SkewModifier.java b/src/org/andengine/entity/modifier/SkewModifier.java
index f724bcab1..e26603530 100644
--- a/src/org/andengine/entity/modifier/SkewModifier.java
+++ b/src/org/andengine/entity/modifier/SkewModifier.java
@@ -5,7 +5,7 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 10:46:10 - 05.10.2011
@@ -44,7 +44,7 @@ protected SkewModifier(final SkewModifier pSkewXModifier) {
}
@Override
- public SkewModifier deepCopy(){
+ public SkewModifier deepCopy() {
return new SkewModifier(this);
}
diff --git a/src/org/andengine/entity/modifier/SkewXModifier.java b/src/org/andengine/entity/modifier/SkewXModifier.java
index e4269c31e..9011f6f51 100644
--- a/src/org/andengine/entity/modifier/SkewXModifier.java
+++ b/src/org/andengine/entity/modifier/SkewXModifier.java
@@ -5,7 +5,7 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 10:46:10 - 05.10.2011
@@ -44,7 +44,7 @@ protected SkewXModifier(final SkewXModifier pSkewXModifier) {
}
@Override
- public SkewXModifier deepCopy(){
+ public SkewXModifier deepCopy() {
return new SkewXModifier(this);
}
diff --git a/src/org/andengine/entity/modifier/SkewYModifier.java b/src/org/andengine/entity/modifier/SkewYModifier.java
index 85a012964..716cc9869 100644
--- a/src/org/andengine/entity/modifier/SkewYModifier.java
+++ b/src/org/andengine/entity/modifier/SkewYModifier.java
@@ -5,7 +5,7 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 10:48:45 - 05.10.2011
@@ -44,7 +44,7 @@ protected SkewYModifier(final SkewYModifier pSkewYModifier) {
}
@Override
- public SkewYModifier deepCopy(){
+ public SkewYModifier deepCopy() {
return new SkewYModifier(this);
}
diff --git a/src/org/andengine/entity/modifier/TripleValueSpanEntityModifier.java b/src/org/andengine/entity/modifier/TripleValueSpanEntityModifier.java
index 5a72e145e..591777edf 100644
--- a/src/org/andengine/entity/modifier/TripleValueSpanEntityModifier.java
+++ b/src/org/andengine/entity/modifier/TripleValueSpanEntityModifier.java
@@ -5,9 +5,9 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:35:18 - 29.06.2010
*/
diff --git a/src/org/andengine/entity/particle/BatchedPseudoSpriteParticleSystem.java b/src/org/andengine/entity/particle/BatchedPseudoSpriteParticleSystem.java
new file mode 100644
index 000000000..97acf9245
--- /dev/null
+++ b/src/org/andengine/entity/particle/BatchedPseudoSpriteParticleSystem.java
@@ -0,0 +1,87 @@
+package org.andengine.entity.particle;
+
+import org.andengine.engine.camera.Camera;
+import org.andengine.entity.Entity;
+import org.andengine.entity.IEntityFactory;
+import org.andengine.entity.particle.emitter.IParticleEmitter;
+import org.andengine.entity.sprite.batch.SpriteBatch;
+import org.andengine.opengl.texture.region.ITextureRegion;
+import org.andengine.opengl.util.GLState;
+import org.andengine.opengl.vbo.VertexBufferObjectManager;
+import org.andengine.util.adt.color.ColorUtils;
+
+/**
+ * (c) 2012 Zynga Inc.
+ *
+ * @author Nicolas Gramlich
+ * @since 11:39:46 - 10.05.2012
+ */
+public class BatchedPseudoSpriteParticleSystem extends BlendFunctionParticleSystem {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ protected final SpriteBatch mSpriteBatch;
+ private final ITextureRegion mTextureRegion;
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ public BatchedPseudoSpriteParticleSystem(final IParticleEmitter pParticleEmitter, final float pRateMinimum, final float pRateMaximum, final int pParticlesMaximum, final ITextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager) {
+ this(0, 0, pParticleEmitter, pRateMinimum, pRateMaximum, pParticlesMaximum, pTextureRegion, pVertexBufferObjectManager);
+ }
+
+ public BatchedPseudoSpriteParticleSystem(final float pX, final float pY, final IParticleEmitter pParticleEmitter, final float pRateMinimum, final float pRateMaximum, final int pParticlesMaximum, final ITextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager) {
+ super(pX, pY, new IEntityFactory() {
+ @Override
+ public Entity create(final float pX, final float pY) {
+ return new Entity(pX, pY, pTextureRegion.getWidth(), pTextureRegion.getHeight());
+ }
+ }, pParticleEmitter, pRateMinimum, pRateMaximum, pParticlesMaximum);
+
+ this.mTextureRegion = pTextureRegion;
+
+ this.mSpriteBatch = new SpriteBatch(pTextureRegion.getTexture(), pParticlesMaximum, pVertexBufferObjectManager);
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ @Override
+ protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
+ this.mSpriteBatch.setIndex(0);
+
+ final Particle[] particles = this.mParticles;
+ for (int i = this.mParticlesAlive - 1; i >= 0; i--) {
+ final Entity entity = particles[i].getEntity();
+
+ /* In order to support alpha changes of the sprites inside the spritebatch,
+ * we have to 'premultiply' the RGB channels of the sprite with its alpha channel. */
+ final float alpha = entity.getAlpha();
+ final float colorABGRPackedInt = ColorUtils.convertRGBAToABGRPackedFloat(entity.getRed() * alpha, entity.getGreen() * alpha, entity.getBlue() * alpha, alpha);
+
+ this.mSpriteBatch.drawWithoutChecks(this.mTextureRegion, entity, colorABGRPackedInt);
+ }
+ this.mSpriteBatch.submit();
+
+ this.mSpriteBatch.onDraw(pGLState, pCamera);
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
diff --git a/src/org/andengine/entity/particle/BatchedSpriteParticleSystem.java b/src/org/andengine/entity/particle/BatchedSpriteParticleSystem.java
new file mode 100644
index 000000000..33c60749b
--- /dev/null
+++ b/src/org/andengine/entity/particle/BatchedSpriteParticleSystem.java
@@ -0,0 +1,86 @@
+package org.andengine.entity.particle;
+
+import org.andengine.engine.camera.Camera;
+import org.andengine.entity.IEntityFactory;
+import org.andengine.entity.particle.emitter.IParticleEmitter;
+import org.andengine.entity.sprite.Sprite;
+import org.andengine.entity.sprite.UncoloredSprite;
+import org.andengine.entity.sprite.batch.SpriteBatch;
+import org.andengine.opengl.texture.region.ITextureRegion;
+import org.andengine.opengl.util.GLState;
+import org.andengine.opengl.vbo.VertexBufferObjectManager;
+import org.andengine.util.adt.color.ColorUtils;
+
+/**
+ * (c) 2012 Zynga Inc.
+ *
+ * @author Nicolas Gramlich
+ * @since 18:32:29 - 09.05.2012
+ */
+public class BatchedSpriteParticleSystem extends BlendFunctionParticleSystem {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ protected final SpriteBatch mSpriteBatch;
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ public BatchedSpriteParticleSystem(final IParticleEmitter pParticleEmitter, final float pRateMinimum, final float pRateMaximum, final int pParticlesMaximum, final ITextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager) {
+ this(0, 0, pParticleEmitter, pRateMinimum, pRateMaximum, pParticlesMaximum, pTextureRegion, pVertexBufferObjectManager);
+ }
+
+ public BatchedSpriteParticleSystem(final float pX, final float pY, final IParticleEmitter pParticleEmitter, final float pRateMinimum, final float pRateMaximum, final int pParticlesMaximum, final ITextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager) {
+ super(pX, pY, new IEntityFactory() {
+ @Override
+ public UncoloredSprite create(final float pX, final float pY) {
+ /* We can create an uncolored sprite, since */
+ return new UncoloredSprite(pX, pY, pTextureRegion, pVertexBufferObjectManager);
+ }
+ }, pParticleEmitter, pRateMinimum, pRateMaximum, pParticlesMaximum);
+
+ this.mSpriteBatch = new SpriteBatch(pTextureRegion.getTexture(), pParticlesMaximum, pVertexBufferObjectManager);
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ @Override
+ protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
+ this.mSpriteBatch.setIndex(0);
+
+ final Particle[] particles = this.mParticles;
+ for (int i = this.mParticlesAlive - 1; i >= 0; i--) {
+ final Sprite sprite = particles[i].getEntity();
+
+ /* In order to support alpha changes of the sprites inside the spritebatch,
+ * we have to 'premultiply' the RGB channels of the sprite with its alpha channel. */
+ final float alpha = sprite.getAlpha();
+ final float colorABGRPackedInt = ColorUtils.convertRGBAToABGRPackedFloat(sprite.getRed() * alpha, sprite.getGreen() * alpha, sprite.getBlue() * alpha, alpha);
+
+ this.mSpriteBatch.drawWithoutChecks(sprite, colorABGRPackedInt);
+ }
+ this.mSpriteBatch.submit();
+
+ this.mSpriteBatch.onDraw(pGLState, pCamera);
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
diff --git a/src/org/andengine/entity/particle/BlendFunctionParticleSystem.java b/src/org/andengine/entity/particle/BlendFunctionParticleSystem.java
new file mode 100644
index 000000000..4fe4c4278
--- /dev/null
+++ b/src/org/andengine/entity/particle/BlendFunctionParticleSystem.java
@@ -0,0 +1,100 @@
+package org.andengine.entity.particle;
+
+import org.andengine.engine.camera.Camera;
+import org.andengine.entity.IEntity;
+import org.andengine.entity.IEntityFactory;
+import org.andengine.entity.particle.emitter.IParticleEmitter;
+import org.andengine.entity.shape.IShape;
+import org.andengine.opengl.util.GLState;
+
+/**
+ * (c) 2012 Zynga Inc.
+ *
+ * @author Nicolas Gramlich
+ * @since 11:34:32 - 10.05.2012
+ */
+public class BlendFunctionParticleSystem extends ParticleSystem {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ protected boolean mBlendingEnabled = true;
+ protected int mBlendFunctionSource = IShape.BLENDFUNCTION_SOURCE_DEFAULT;
+ protected int mBlendFunctionDestination = IShape.BLENDFUNCTION_DESTINATION_DEFAULT;
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ public BlendFunctionParticleSystem(final IEntityFactory pEntityFactory, final IParticleEmitter pParticleEmitter, final float pRateMinimum, final float pRateMaximum, final int pParticlesMaximum) {
+ super(pEntityFactory, pParticleEmitter, pRateMinimum, pRateMaximum, pParticlesMaximum);
+ }
+
+ public BlendFunctionParticleSystem(final float pX, final float pY, final IEntityFactory pEntityFactory, final IParticleEmitter pParticleEmitter, final float pRateMinimum, final float pRateMaximum, final int pParticlesMaximum) {
+ super(pX, pY, pEntityFactory, pParticleEmitter, pRateMinimum, pRateMaximum, pParticlesMaximum);
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ public boolean isBlendingEnabled() {
+ return this.mBlendingEnabled;
+ }
+
+ public void setBlendingEnabled(final boolean pBlendingEnabled) {
+ this.mBlendingEnabled = pBlendingEnabled;
+ }
+
+ public int getBlendFunctionSource() {
+ return this.mBlendFunctionSource;
+ }
+
+ public void setBlendFunctionSource(final int pBlendFunctionSource) {
+ this.mBlendFunctionSource = pBlendFunctionSource;
+ }
+
+ public int getBlendFunctionDestination() {
+ return this.mBlendFunctionDestination;
+ }
+
+ public void setBlendFunctionDestination(final int pBlendFunctionDestination) {
+ this.mBlendFunctionDestination = pBlendFunctionDestination;
+ }
+
+ public void setBlendFunction(final int pBlendFunctionSource, final int pBlendFunctionDestination) {
+ this.mBlendFunctionSource = pBlendFunctionSource;
+ this.mBlendFunctionDestination = pBlendFunctionDestination;
+ }
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ @Override
+ protected void preDraw(final GLState pGLState, final Camera pCamera) {
+ if (this.mBlendingEnabled) {
+ pGLState.enableBlend();
+ pGLState.blendFunction(this.mBlendFunctionSource, this.mBlendFunctionDestination);
+ }
+ }
+
+ @Override
+ protected void postDraw(final GLState pGLState, final Camera pCamera) {
+ if (this.mBlendingEnabled) {
+ pGLState.disableBlend();
+ }
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
diff --git a/src/org/andengine/entity/particle/Particle.java b/src/org/andengine/entity/particle/Particle.java
index 66bda0532..51318d900 100644
--- a/src/org/andengine/entity/particle/Particle.java
+++ b/src/org/andengine/entity/particle/Particle.java
@@ -8,7 +8,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 19:37:13 - 14.03.2010
*/
@@ -61,7 +61,7 @@ public void setExpireTime(final float pExpireTime) {
}
public boolean isExpired() {
- return this.mExpired ;
+ return this.mExpired;
}
public void setExpired(final boolean pExpired) {
@@ -77,8 +77,8 @@ public PhysicsHandler getPhysicsHandler() {
// ===========================================================
protected void onUpdate(final float pSecondsElapsed) {
- if(!this.mExpired){
- if(this.mExpireTime == Particle.EXPIRETIME_NEVER || this.mLifeTime + pSecondsElapsed < this.mExpireTime) {
+ if (!this.mExpired) {
+ if (this.mExpireTime == Particle.EXPIRETIME_NEVER || this.mLifeTime + pSecondsElapsed < this.mExpireTime) {
/* Particle doesn't expire or didn't expire yet. */
this.mLifeTime += pSecondsElapsed;
this.mEntity.onUpdate(pSecondsElapsed);
@@ -94,7 +94,7 @@ protected void onUpdate(final float pSecondsElapsed) {
}
public void onDraw(final GLState pGLState, final Camera pCamera) {
- if(!this.mExpired) {
+ if (!this.mExpired) {
this.mEntity.onDraw(pGLState, pCamera);
}
}
diff --git a/src/org/andengine/entity/particle/ParticleSystem.java b/src/org/andengine/entity/particle/ParticleSystem.java
index a3576c24d..725b0b946 100644
--- a/src/org/andengine/entity/particle/ParticleSystem.java
+++ b/src/org/andengine/entity/particle/ParticleSystem.java
@@ -4,56 +4,51 @@
import org.andengine.engine.camera.Camera;
import org.andengine.entity.Entity;
+import org.andengine.entity.IEntity;
import org.andengine.entity.IEntityFactory;
import org.andengine.entity.particle.emitter.IParticleEmitter;
import org.andengine.entity.particle.initializer.IParticleInitializer;
import org.andengine.entity.particle.modifier.IParticleModifier;
import org.andengine.opengl.util.GLState;
import org.andengine.util.Constants;
+import org.andengine.util.adt.array.ArrayUtils;
import org.andengine.util.math.MathUtils;
-import android.util.FloatMath;
-
/**
- * TODO Check if SpriteBatch can be used here to improve performance.
- *
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 19:42:27 - 14.03.2010
*/
-public class ParticleSystem extends Entity {
+public class ParticleSystem extends Entity {
// ===========================================================
// Constants
// ===========================================================
- private final float[] POSITION_OFFSET = new float[2];
+ private static final float[] POSITION_OFFSET_CONTAINER = new float[2];
// ===========================================================
// Fields
// ===========================================================
- private final IEntityFactory mEntityFactory;
- private final IParticleEmitter mParticleEmitter;
+ protected final IEntityFactory mEntityFactory;
+ protected final IParticleEmitter mParticleEmitter;
- private final Particle[] mParticles;
+ protected final Particle[] mParticles;
- private final ArrayList> mParticleInitializers = new ArrayList>();
- private final ArrayList> mParticleModifiers = new ArrayList>();
+ protected final ArrayList> mParticleInitializers = new ArrayList>();
+ protected final ArrayList> mParticleModifiers = new ArrayList>();
private final float mRateMinimum;
private final float mRateMaximum;
private boolean mParticlesSpawnEnabled = true;
- private final int mParticlesMaximum;
- private int mParticlesAlive;
+ protected final int mParticlesMaximum;
+ protected int mParticlesAlive;
private float mParticlesDueToSpawn;
- private int mParticleModifierCount;
- private int mParticleInitializerCount;
-
// ===========================================================
// Constructors
// ===========================================================
@@ -68,7 +63,7 @@ public ParticleSystem(final float pX, final float pY, final IEntityFactory pE
this.mEntityFactory = pEntityFactory;
this.mParticleEmitter = pParticleEmitter;
- this.mParticles = (Particle[])new Particle[pParticlesMaximum];
+ this.mParticles = (Particle[]) new Particle[pParticlesMaximum];
this.mRateMinimum = pRateMinimum;
this.mRateMaximum = pRateMaximum;
this.mParticlesMaximum = pParticlesMaximum;
@@ -110,9 +105,8 @@ public void reset() {
@Override
protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
- final Particle[] particles = this.mParticles;
- for(int i = this.mParticlesAlive - 1; i >= 0; i--) {
- particles[i].onDraw(pGLState, pCamera);
+ for (int i = this.mParticlesAlive - 1; i >= 0; i--) {
+ this.mParticles[i].onDraw(pGLState, pCamera);
}
}
@@ -120,54 +114,60 @@ protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
protected void onManagedUpdate(final float pSecondsElapsed) {
super.onManagedUpdate(pSecondsElapsed);
- if(this.isParticlesSpawnEnabled()) {
+ if (this.isParticlesSpawnEnabled()) {
this.spawnParticles(pSecondsElapsed);
}
- final Particle[] particles = this.mParticles;
-
- final ArrayList> particleModifiers = this.mParticleModifiers;
- final int particleModifierCountMinusOne = this.mParticleModifierCount - 1;
-
- for(int i = this.mParticlesAlive - 1; i >= 0; i--) {
- final Particle particle = particles[i];
+ final int particleModifierCountMinusOne = this.mParticleModifiers.size() - 1;
+ for (int i = this.mParticlesAlive - 1; i >= 0; i--) {
+ final Particle particle = this.mParticles[i];
/* Apply all particleModifiers */
- for(int j = particleModifierCountMinusOne; j >= 0; j--) {
- particleModifiers.get(j).onUpdateParticle(particle);
+ for (int j = particleModifierCountMinusOne; j >= 0; j--) {
+ this.mParticleModifiers.get(j).onUpdateParticle(particle);
}
particle.onUpdate(pSecondsElapsed);
- if(particle.mExpired){
+ if (particle.mExpired) {
this.mParticlesAlive--;
- final int particlesAlive = this.mParticlesAlive;
- particles[i] = particles[particlesAlive];
- particles[particlesAlive] = particle;
+
+ this.moveParticleToEnd(i);
}
}
}
+ protected void moveParticleToEnd(final int pIndex) {
+ final Particle particle = this.mParticles[pIndex];
+
+ final int particlesToCopy = this.mParticlesAlive - pIndex;
+ if (particlesToCopy > 0) {
+ System.arraycopy(this.mParticles, pIndex + 1, this.mParticles, pIndex, particlesToCopy);
+ }
+ this.mParticles[this.mParticlesAlive] = particle;
+
+ /* This mode of swapping particles is faster than copying tons of array elements,
+ * but it doesn't respect the 'lifetime' of the particles. */
+// particles[i] = particles[this.mParticlesAlive];
+// particles[this.mParticlesAlive] = particle;
+ }
+
// ===========================================================
// Methods
// ===========================================================
public void addParticleModifier(final IParticleModifier pParticleModifier) {
this.mParticleModifiers.add(pParticleModifier);
- this.mParticleModifierCount++;
}
public void removeParticleModifier(final IParticleModifier pParticleModifier) {
- this.mParticleModifierCount--;
this.mParticleModifiers.remove(pParticleModifier);
}
public void addParticleInitializer(final IParticleInitializer pParticleInitializer) {
this.mParticleInitializers.add(pParticleInitializer);
- this.mParticleInitializerCount++;
}
public void removeParticleInitializer(final IParticleInitializer pParticleInitializer) {
- this.mParticleInitializerCount--;
this.mParticleInitializers.remove(pParticleInitializer);
}
@@ -177,30 +177,27 @@ private void spawnParticles(final float pSecondsElapsed) {
this.mParticlesDueToSpawn += newParticlesThisFrame;
- final int particlesToSpawnThisFrame = Math.min(this.mParticlesMaximum - this.mParticlesAlive, (int)FloatMath.floor(this.mParticlesDueToSpawn));
+ final int particlesToSpawnThisFrame = Math.min(this.mParticlesMaximum - this.mParticlesAlive, (int) Math.floor(this.mParticlesDueToSpawn));
this.mParticlesDueToSpawn -= particlesToSpawnThisFrame;
- for(int i = 0; i < particlesToSpawnThisFrame; i++){
+ for (int i = 0; i < particlesToSpawnThisFrame; i++) {
this.spawnParticle();
}
}
private void spawnParticle() {
- final Particle[] particles = this.mParticles;
-
- final int particlesAlive = this.mParticlesAlive;
- if(particlesAlive < this.mParticlesMaximum){
- Particle particle = particles[particlesAlive];
+ if (this.mParticlesAlive < this.mParticlesMaximum) {
+ Particle particle = this.mParticles[this.mParticlesAlive];
/* New particle needs to be created. */
- this.mParticleEmitter.getPositionOffset(this.POSITION_OFFSET);
+ this.mParticleEmitter.getPositionOffset(ParticleSystem.POSITION_OFFSET_CONTAINER);
- final float x = this.POSITION_OFFSET[Constants.VERTEX_INDEX_X];
- final float y = this.POSITION_OFFSET[Constants.VERTEX_INDEX_Y];
+ final float x = ParticleSystem.POSITION_OFFSET_CONTAINER[Constants.VERTEX_INDEX_X];
+ final float y = ParticleSystem.POSITION_OFFSET_CONTAINER[Constants.VERTEX_INDEX_Y];
- if(particle == null) {
+ if (particle == null) {
particle = new Particle();
- particles[particlesAlive] = particle;
+ this.mParticles[this.mParticlesAlive] = particle;
particle.setEntity(this.mEntityFactory.create(x, y));
} else {
particle.reset();
@@ -209,14 +206,12 @@ private void spawnParticle() {
/* Apply particle initializers. */
{
- final ArrayList> particleInitializers = this.mParticleInitializers;
- for(int i = this.mParticleInitializerCount - 1; i >= 0; i--) {
- particleInitializers.get(i).onInitializeParticle(particle);
+ for (int i = this.mParticleInitializers.size() - 1; i >= 0; i--) {
+ this.mParticleInitializers.get(i).onInitializeParticle(particle);
}
- final ArrayList> particleModifiers = this.mParticleModifiers;
- for(int i = this.mParticleModifierCount - 1; i >= 0; i--) {
- particleModifiers.get(i).onInitializeParticle(particle);
+ for (int i = this.mParticleModifiers.size() - 1; i >= 0; i--) {
+ this.mParticleModifiers.get(i).onInitializeParticle(particle);
}
}
@@ -225,7 +220,7 @@ private void spawnParticle() {
}
protected float determineCurrentRate() {
- if(this.mRateMinimum == this.mRateMaximum){
+ if (this.mRateMinimum == this.mRateMaximum) {
return this.mRateMinimum;
} else {
return MathUtils.random(this.mRateMinimum, this.mRateMaximum);
diff --git a/src/org/andengine/entity/particle/SpriteParticleSystem.java b/src/org/andengine/entity/particle/SpriteParticleSystem.java
index b7bd64453..aef2b20e2 100644
--- a/src/org/andengine/entity/particle/SpriteParticleSystem.java
+++ b/src/org/andengine/entity/particle/SpriteParticleSystem.java
@@ -7,7 +7,7 @@
import org.andengine.opengl.vbo.VertexBufferObjectManager;
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 21:00:23 - 04.12.2011
@@ -38,6 +38,10 @@ public Sprite create(final float pX, final float pY) {
}, pParticleEmitter, pRateMinimum, pRateMaximum, pParticlesMaximum);
}
+ protected SpriteParticleSystem(final float pX, final float pY, final IEntityFactory pEntityFactory, final IParticleEmitter pParticleEmitter, final float pRateMinimum, final float pRateMaximum, final int pParticlesMaximum) {
+ super(pX, pY, pEntityFactory, pParticleEmitter, pRateMinimum, pRateMaximum, pParticlesMaximum);
+ }
+
// ===========================================================
// Getter & Setter
// ===========================================================
diff --git a/src/org/andengine/entity/particle/emitter/BaseCircleParticleEmitter.java b/src/org/andengine/entity/particle/emitter/BaseCircleParticleEmitter.java
index 6cf5bd3cf..618990acb 100644
--- a/src/org/andengine/entity/particle/emitter/BaseCircleParticleEmitter.java
+++ b/src/org/andengine/entity/particle/emitter/BaseCircleParticleEmitter.java
@@ -2,9 +2,9 @@
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 20:14:43 - 01.10.2010
*/
diff --git a/src/org/andengine/entity/particle/emitter/BaseParticleEmitter.java b/src/org/andengine/entity/particle/emitter/BaseParticleEmitter.java
index 8c29f6ebf..1ec272956 100644
--- a/src/org/andengine/entity/particle/emitter/BaseParticleEmitter.java
+++ b/src/org/andengine/entity/particle/emitter/BaseParticleEmitter.java
@@ -1,9 +1,9 @@
package org.andengine.entity.particle.emitter;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:58:12 - 01.10.2010
*/
diff --git a/src/org/andengine/entity/particle/emitter/BaseRectangleParticleEmitter.java b/src/org/andengine/entity/particle/emitter/BaseRectangleParticleEmitter.java
index 0dfccd07c..334020209 100644
--- a/src/org/andengine/entity/particle/emitter/BaseRectangleParticleEmitter.java
+++ b/src/org/andengine/entity/particle/emitter/BaseRectangleParticleEmitter.java
@@ -2,9 +2,9 @@
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 18:53:18 - 01.10.2010
*/
diff --git a/src/org/andengine/entity/particle/emitter/CircleOutlineParticleEmitter.java b/src/org/andengine/entity/particle/emitter/CircleOutlineParticleEmitter.java
index 95ad9e4e8..9807c8247 100644
--- a/src/org/andengine/entity/particle/emitter/CircleOutlineParticleEmitter.java
+++ b/src/org/andengine/entity/particle/emitter/CircleOutlineParticleEmitter.java
@@ -6,12 +6,10 @@
import org.andengine.util.math.MathConstants;
import org.andengine.util.math.MathUtils;
-import android.util.FloatMath;
-
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 20:18:41 - 01.10.2010
*/
@@ -47,8 +45,8 @@ public CircleOutlineParticleEmitter(final float pCenterX, final float pCenterY,
@Override
public void getPositionOffset(final float[] pOffset) {
final float random = MathUtils.RANDOM.nextFloat() * MathConstants.PI * 2;
- pOffset[VERTEX_INDEX_X] = this.mCenterX + FloatMath.cos(random) * this.mRadiusX;
- pOffset[VERTEX_INDEX_Y] = this.mCenterY + FloatMath.sin(random) * this.mRadiusY;
+ pOffset[VERTEX_INDEX_X] = this.mCenterX + (float) Math.cos(random) * this.mRadiusX;
+ pOffset[VERTEX_INDEX_Y] = this.mCenterY + (float) Math.sin(random) * this.mRadiusY;
}
// ===========================================================
diff --git a/src/org/andengine/entity/particle/emitter/CircleParticleEmitter.java b/src/org/andengine/entity/particle/emitter/CircleParticleEmitter.java
index ba8c69a7b..f492a7609 100644
--- a/src/org/andengine/entity/particle/emitter/CircleParticleEmitter.java
+++ b/src/org/andengine/entity/particle/emitter/CircleParticleEmitter.java
@@ -6,12 +6,10 @@
import org.andengine.util.math.MathConstants;
import org.andengine.util.math.MathUtils;
-import android.util.FloatMath;
-
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 20:18:41 - 01.10.2010
*/
@@ -47,8 +45,8 @@ public CircleParticleEmitter(final float pCenterX, final float pCenterY, final f
@Override
public void getPositionOffset(final float[] pOffset) {
final float random = MathUtils.RANDOM.nextFloat() * MathConstants.PI * 2;
- pOffset[VERTEX_INDEX_X] = this.mCenterX + FloatMath.cos(random) * this.mRadiusX * MathUtils.RANDOM.nextFloat();
- pOffset[VERTEX_INDEX_Y] = this.mCenterY + FloatMath.sin(random) * this.mRadiusY * MathUtils.RANDOM.nextFloat();
+ pOffset[VERTEX_INDEX_X] = this.mCenterX + (float) Math.cos(random) * this.mRadiusX * MathUtils.RANDOM.nextFloat();
+ pOffset[VERTEX_INDEX_Y] = this.mCenterY + (float) Math.sin(random) * this.mRadiusY * MathUtils.RANDOM.nextFloat();
}
// ===========================================================
diff --git a/src/org/andengine/entity/particle/emitter/IParticleEmitter.java b/src/org/andengine/entity/particle/emitter/IParticleEmitter.java
index 80c6d1a19..881fac369 100644
--- a/src/org/andengine/entity/particle/emitter/IParticleEmitter.java
+++ b/src/org/andengine/entity/particle/emitter/IParticleEmitter.java
@@ -3,9 +3,9 @@
import org.andengine.engine.handler.IUpdateHandler;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:48:09 - 01.10.2010
*/
diff --git a/src/org/andengine/entity/particle/emitter/PointParticleEmitter.java b/src/org/andengine/entity/particle/emitter/PointParticleEmitter.java
index 763371845..ca052fa6b 100644
--- a/src/org/andengine/entity/particle/emitter/PointParticleEmitter.java
+++ b/src/org/andengine/entity/particle/emitter/PointParticleEmitter.java
@@ -4,9 +4,9 @@
import static org.andengine.util.Constants.VERTEX_INDEX_Y;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 23:14:42 - 01.10.2010
*/
diff --git a/src/org/andengine/entity/particle/emitter/RectangleOutlineParticleEmitter.java b/src/org/andengine/entity/particle/emitter/RectangleOutlineParticleEmitter.java
index d81def32e..f8967b102 100644
--- a/src/org/andengine/entity/particle/emitter/RectangleOutlineParticleEmitter.java
+++ b/src/org/andengine/entity/particle/emitter/RectangleOutlineParticleEmitter.java
@@ -6,9 +6,9 @@
import org.andengine.util.math.MathUtils;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:48:00 - 01.10.2010
*/
diff --git a/src/org/andengine/entity/particle/emitter/RectangleParticleEmitter.java b/src/org/andengine/entity/particle/emitter/RectangleParticleEmitter.java
index b4e1da14c..f693564c3 100644
--- a/src/org/andengine/entity/particle/emitter/RectangleParticleEmitter.java
+++ b/src/org/andengine/entity/particle/emitter/RectangleParticleEmitter.java
@@ -6,9 +6,9 @@
import org.andengine.util.math.MathUtils;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:48:00 - 01.10.2010
*/
diff --git a/src/org/andengine/entity/particle/initializer/AccelerationParticleInitializer.java b/src/org/andengine/entity/particle/initializer/AccelerationParticleInitializer.java
index 47de27615..2fa371037 100644
--- a/src/org/andengine/entity/particle/initializer/AccelerationParticleInitializer.java
+++ b/src/org/andengine/entity/particle/initializer/AccelerationParticleInitializer.java
@@ -4,9 +4,9 @@
import org.andengine.entity.particle.Particle;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 21:21:10 - 14.03.2010
*/
diff --git a/src/org/andengine/entity/particle/initializer/AlphaParticleInitializer.java b/src/org/andengine/entity/particle/initializer/AlphaParticleInitializer.java
index a51e8c649..a7ccfdc56 100644
--- a/src/org/andengine/entity/particle/initializer/AlphaParticleInitializer.java
+++ b/src/org/andengine/entity/particle/initializer/AlphaParticleInitializer.java
@@ -5,9 +5,9 @@
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 18:53:41 - 02.10.2010
*/
diff --git a/src/org/andengine/entity/particle/initializer/BaseDoubleValueParticleInitializer.java b/src/org/andengine/entity/particle/initializer/BaseDoubleValueParticleInitializer.java
index 1ceb167ff..15c9586f1 100644
--- a/src/org/andengine/entity/particle/initializer/BaseDoubleValueParticleInitializer.java
+++ b/src/org/andengine/entity/particle/initializer/BaseDoubleValueParticleInitializer.java
@@ -5,9 +5,9 @@
import org.andengine.util.math.MathUtils;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:58:29 - 04.05.2010
*/
@@ -53,7 +53,7 @@ protected final void onInitializeParticle(final Particle pParticle, final flo
// ===========================================================
protected float getRandomValueB() {
- if(this.mMinValueB == this.mMaxValueB) {
+ if (this.mMinValueB == this.mMaxValueB) {
return this.mMaxValueB;
} else {
return MathUtils.random(this.mMinValueB, this.mMaxValueB);
diff --git a/src/org/andengine/entity/particle/initializer/BaseSingleValueParticleInitializer.java b/src/org/andengine/entity/particle/initializer/BaseSingleValueParticleInitializer.java
index 580d1a9fb..1b62c9cb2 100644
--- a/src/org/andengine/entity/particle/initializer/BaseSingleValueParticleInitializer.java
+++ b/src/org/andengine/entity/particle/initializer/BaseSingleValueParticleInitializer.java
@@ -5,9 +5,9 @@
import org.andengine.util.math.MathUtils;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 10:18:06 - 29.06.2010
*/
@@ -52,7 +52,7 @@ public final void onInitializeParticle(final Particle pParticle) {
// ===========================================================
protected float getRandomValue() {
- if(this.mMinValue == this.mMaxValue) {
+ if (this.mMinValue == this.mMaxValue) {
return this.mMaxValue;
} else {
return MathUtils.random(this.mMinValue, this.mMaxValue);
diff --git a/src/org/andengine/entity/particle/initializer/BaseTripleValueParticleInitializer.java b/src/org/andengine/entity/particle/initializer/BaseTripleValueParticleInitializer.java
index 37bce1e1a..101f448e4 100644
--- a/src/org/andengine/entity/particle/initializer/BaseTripleValueParticleInitializer.java
+++ b/src/org/andengine/entity/particle/initializer/BaseTripleValueParticleInitializer.java
@@ -5,9 +5,9 @@
import org.andengine.util.math.MathUtils;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:58:29 - 04.05.2010
*/
@@ -53,7 +53,7 @@ protected final void onInitializeParticle(final Particle pParticle, final flo
// ===========================================================
protected float getRandomValueC() {
- if(this.mMinValueC == this.mMaxValueC) {
+ if (this.mMinValueC == this.mMaxValueC) {
return this.mMaxValueC;
} else {
return MathUtils.random(this.mMinValueC, this.mMaxValueC);
diff --git a/src/org/andengine/entity/particle/initializer/BlendFunctionParticleInitializer.java b/src/org/andengine/entity/particle/initializer/BlendFunctionParticleInitializer.java
index cec51c15f..9c1909f9b 100644
--- a/src/org/andengine/entity/particle/initializer/BlendFunctionParticleInitializer.java
+++ b/src/org/andengine/entity/particle/initializer/BlendFunctionParticleInitializer.java
@@ -8,9 +8,9 @@
/**
* Sets the blend function used to draw the {@link Particle} during its lifespan. Only applicable to {@link Shape}s.
- *
- * @author janne.sinivirta
- *
+ *
+ * @author Janne Sinivirta
+ *
* @since 17:24:32 - 28.12.2011
*/
public class BlendFunctionParticleInitializer implements IParticleInitializer {
diff --git a/src/org/andengine/entity/particle/initializer/ColorParticleInitializer.java b/src/org/andengine/entity/particle/initializer/ColorParticleInitializer.java
index c9d7cae67..f2502cb24 100644
--- a/src/org/andengine/entity/particle/initializer/ColorParticleInitializer.java
+++ b/src/org/andengine/entity/particle/initializer/ColorParticleInitializer.java
@@ -2,13 +2,13 @@
import org.andengine.entity.IEntity;
import org.andengine.entity.particle.Particle;
-import org.andengine.util.color.Color;
+import org.andengine.util.adt.color.Color;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 10:17:42 - 29.06.2010
*/
@@ -28,7 +28,7 @@ public class ColorParticleInitializer extends BaseTripleValue
public ColorParticleInitializer(final Color pColor) {
super(pColor.getRed(), pColor.getRed(), pColor.getGreen(), pColor.getGreen(), pColor.getBlue(), pColor.getBlue());
}
-
+
public ColorParticleInitializer(final float pRed, final float pGreen, final float pBlue) {
super(pRed, pRed, pGreen, pGreen, pBlue, pBlue);
}
@@ -36,7 +36,7 @@ public ColorParticleInitializer(final float pRed, final float pGreen, final floa
public ColorParticleInitializer(final Color pMinColor, final Color pMaxColor) {
super(pMinColor.getRed(), pMaxColor.getRed(), pMinColor.getGreen(), pMaxColor.getGreen(), pMinColor.getBlue(), pMaxColor.getBlue());
}
-
+
public ColorParticleInitializer(final float pMinRed, final float pMaxRed, final float pMinGreen, final float pMaxGreen, final float pMinBlue, final float pMaxBlue) {
super(pMinRed, pMaxRed, pMinGreen, pMaxGreen, pMinBlue, pMaxBlue);
}
diff --git a/src/org/andengine/entity/particle/modifier/ExpireParticleInitializer.java b/src/org/andengine/entity/particle/initializer/ExpireParticleInitializer.java
similarity index 93%
rename from src/org/andengine/entity/particle/modifier/ExpireParticleInitializer.java
rename to src/org/andengine/entity/particle/initializer/ExpireParticleInitializer.java
index 9bbdf4ac7..c6a482bfb 100644
--- a/src/org/andengine/entity/particle/modifier/ExpireParticleInitializer.java
+++ b/src/org/andengine/entity/particle/initializer/ExpireParticleInitializer.java
@@ -1,14 +1,13 @@
-package org.andengine.entity.particle.modifier;
+package org.andengine.entity.particle.initializer;
import org.andengine.entity.IEntity;
import org.andengine.entity.particle.Particle;
-import org.andengine.entity.particle.initializer.IParticleInitializer;
import org.andengine.util.math.MathUtils;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 21:21:10 - 14.03.2010
*/
diff --git a/src/org/andengine/entity/particle/initializer/GravityParticleInitializer.java b/src/org/andengine/entity/particle/initializer/GravityParticleInitializer.java
index 3dde7d5d7..bf08927e3 100644
--- a/src/org/andengine/entity/particle/initializer/GravityParticleInitializer.java
+++ b/src/org/andengine/entity/particle/initializer/GravityParticleInitializer.java
@@ -5,9 +5,9 @@
import android.hardware.SensorManager;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 12:04:00 - 15.03.2010
*/
diff --git a/src/org/andengine/entity/particle/initializer/IParticleInitializer.java b/src/org/andengine/entity/particle/initializer/IParticleInitializer.java
index fd2e4f361..64a01968d 100644
--- a/src/org/andengine/entity/particle/initializer/IParticleInitializer.java
+++ b/src/org/andengine/entity/particle/initializer/IParticleInitializer.java
@@ -4,9 +4,9 @@
import org.andengine.entity.particle.Particle;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 10:12:09 - 29.06.2010
*/
diff --git a/src/org/andengine/entity/particle/initializer/RotationParticleInitializer.java b/src/org/andengine/entity/particle/initializer/RotationParticleInitializer.java
index 785eb8388..2a3bd9c2e 100644
--- a/src/org/andengine/entity/particle/initializer/RotationParticleInitializer.java
+++ b/src/org/andengine/entity/particle/initializer/RotationParticleInitializer.java
@@ -4,9 +4,9 @@
import org.andengine.entity.particle.Particle;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 10:17:42 - 29.06.2010
*/
diff --git a/src/org/andengine/entity/particle/initializer/ScaleParticleInitializer.java b/src/org/andengine/entity/particle/initializer/ScaleParticleInitializer.java
index 6a94826c7..626318877 100644
--- a/src/org/andengine/entity/particle/initializer/ScaleParticleInitializer.java
+++ b/src/org/andengine/entity/particle/initializer/ScaleParticleInitializer.java
@@ -5,7 +5,7 @@
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 10:03:29 - 19.11.2011
diff --git a/src/org/andengine/entity/particle/initializer/VelocityParticleInitializer.java b/src/org/andengine/entity/particle/initializer/VelocityParticleInitializer.java
index dd4c46458..f0c69b20f 100644
--- a/src/org/andengine/entity/particle/initializer/VelocityParticleInitializer.java
+++ b/src/org/andengine/entity/particle/initializer/VelocityParticleInitializer.java
@@ -4,9 +4,9 @@
import org.andengine.entity.particle.Particle;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 21:21:10 - 14.03.2010
*/
diff --git a/src/org/andengine/entity/particle/modifier/AlphaParticleModifier.java b/src/org/andengine/entity/particle/modifier/AlphaParticleModifier.java
index 93faec292..e57a9237d 100644
--- a/src/org/andengine/entity/particle/modifier/AlphaParticleModifier.java
+++ b/src/org/andengine/entity/particle/modifier/AlphaParticleModifier.java
@@ -6,9 +6,9 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 21:21:10 - 14.03.2010
*/
diff --git a/src/org/andengine/entity/particle/modifier/BaseDoubleValueSpanParticleModifier.java b/src/org/andengine/entity/particle/modifier/BaseDoubleValueSpanParticleModifier.java
index 177fd125d..f78ef2b3f 100644
--- a/src/org/andengine/entity/particle/modifier/BaseDoubleValueSpanParticleModifier.java
+++ b/src/org/andengine/entity/particle/modifier/BaseDoubleValueSpanParticleModifier.java
@@ -6,9 +6,9 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:19:46 - 29.06.2010
*/
diff --git a/src/org/andengine/entity/particle/modifier/BaseSingleValueSpanParticleModifier.java b/src/org/andengine/entity/particle/modifier/BaseSingleValueSpanParticleModifier.java
index caf014d51..d1342a156 100644
--- a/src/org/andengine/entity/particle/modifier/BaseSingleValueSpanParticleModifier.java
+++ b/src/org/andengine/entity/particle/modifier/BaseSingleValueSpanParticleModifier.java
@@ -6,9 +6,9 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 16:10:16 - 04.05.2010
*/
@@ -68,7 +68,7 @@ public void onInitializeParticle(final Particle pParticle) {
@Override
public void onUpdateParticle(final Particle pParticle) {
final float lifeTime = pParticle.getLifeTime();
- if(lifeTime > this.mFromTime && lifeTime < this.mToTime) {
+ if (lifeTime > this.mFromTime && lifeTime < this.mToTime) {
final float percentageDone = this.mEaseFunction.getPercentage((lifeTime - this.mFromTime), this.mDuration);
this.onSetValue(pParticle, percentageDone, this.mFromValue + percentageDone * this.mValueSpan);
}
diff --git a/src/org/andengine/entity/particle/modifier/BaseTripleValueSpanParticleModifier.java b/src/org/andengine/entity/particle/modifier/BaseTripleValueSpanParticleModifier.java
index b46418390..fb6fb90e9 100644
--- a/src/org/andengine/entity/particle/modifier/BaseTripleValueSpanParticleModifier.java
+++ b/src/org/andengine/entity/particle/modifier/BaseTripleValueSpanParticleModifier.java
@@ -6,9 +6,9 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:19:46 - 29.06.2010
*/
diff --git a/src/org/andengine/entity/particle/modifier/ColorParticleModifier.java b/src/org/andengine/entity/particle/modifier/ColorParticleModifier.java
index 4a6c81852..365809cc5 100644
--- a/src/org/andengine/entity/particle/modifier/ColorParticleModifier.java
+++ b/src/org/andengine/entity/particle/modifier/ColorParticleModifier.java
@@ -2,13 +2,14 @@
import org.andengine.entity.IEntity;
import org.andengine.entity.particle.Particle;
+import org.andengine.util.adt.color.Color;
import org.andengine.util.modifier.ease.EaseLinear;
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:22:26 - 29.06.2010
*/
@@ -25,6 +26,14 @@ public class ColorParticleModifier extends BaseTripleValueSpa
// Constructors
// ===========================================================
+ public ColorParticleModifier(final float pFromTime, final float pToTime, final Color pFromColor, final Color pToColor) {
+ this(pFromTime, pToTime, pFromColor.getRed(), pToColor.getRed(), pFromColor.getGreen(), pToColor.getGreen(), pFromColor.getBlue(), pToColor.getBlue());
+ }
+
+ public ColorParticleModifier(final float pFromTime, final float pToTime, final Color pFromColor, final Color pToColor, final IEaseFunction pEaseFunction) {
+ super(pFromTime, pToTime, pFromColor.getRed(), pToColor.getRed(), pFromColor.getGreen(), pToColor.getGreen(), pFromColor.getBlue(), pToColor.getBlue(), pEaseFunction);
+ }
+
public ColorParticleModifier(final float pFromTime, final float pToTime, final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue) {
this(pFromTime, pToTime, pFromRed, pToRed, pFromGreen, pToGreen, pFromBlue, pToBlue, EaseLinear.getInstance());
}
diff --git a/src/org/andengine/entity/particle/modifier/IParticleModifier.java b/src/org/andengine/entity/particle/modifier/IParticleModifier.java
index 1e9a1360d..e078b583c 100644
--- a/src/org/andengine/entity/particle/modifier/IParticleModifier.java
+++ b/src/org/andengine/entity/particle/modifier/IParticleModifier.java
@@ -5,9 +5,9 @@
import org.andengine.entity.particle.initializer.IParticleInitializer;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 20:06:05 - 14.03.2010
*/
diff --git a/src/org/andengine/entity/particle/modifier/OffCameraExpireParticleModifier.java b/src/org/andengine/entity/particle/modifier/OffCameraExpireParticleModifier.java
index 711ec363e..c2d54e29b 100644
--- a/src/org/andengine/entity/particle/modifier/OffCameraExpireParticleModifier.java
+++ b/src/org/andengine/entity/particle/modifier/OffCameraExpireParticleModifier.java
@@ -2,17 +2,17 @@
import org.andengine.engine.camera.Camera;
+import org.andengine.entity.IEntity;
import org.andengine.entity.particle.Particle;
-import org.andengine.entity.shape.RectangularShape;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 21:21:10 - 14.03.2010
*/
-public class OffCameraExpireParticleModifier implements IParticleModifier {
+public class OffCameraExpireParticleModifier implements IParticleModifier {
// ===========================================================
// Constants
// ===========================================================
@@ -50,7 +50,7 @@ public void onInitializeParticle(final Particle pParticle) {
@Override
public void onUpdateParticle(final Particle pParticle) {
- if(!this.mCamera.isRectangularShapeVisible(pParticle.getEntity())) {
+ if (!this.mCamera.isEntityVisible(pParticle.getEntity())) {
pParticle.setExpired(true);
}
}
diff --git a/src/org/andengine/entity/particle/modifier/RotationParticleModifier.java b/src/org/andengine/entity/particle/modifier/RotationParticleModifier.java
index cd9a3de64..de8ec793b 100644
--- a/src/org/andengine/entity/particle/modifier/RotationParticleModifier.java
+++ b/src/org/andengine/entity/particle/modifier/RotationParticleModifier.java
@@ -6,9 +6,9 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 10:36:18 - 29.06.2010
*/
diff --git a/src/org/andengine/entity/particle/modifier/ScaleParticleModifier.java b/src/org/andengine/entity/particle/modifier/ScaleParticleModifier.java
index 1243eee51..d94cf2786 100644
--- a/src/org/andengine/entity/particle/modifier/ScaleParticleModifier.java
+++ b/src/org/andengine/entity/particle/modifier/ScaleParticleModifier.java
@@ -6,9 +6,9 @@
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 20:37:27 - 04.05.2010
*/
diff --git a/src/org/andengine/entity/primitive/DrawMode.java b/src/org/andengine/entity/primitive/DrawMode.java
index b2ec80c2f..3471c591f 100644
--- a/src/org/andengine/entity/primitive/DrawMode.java
+++ b/src/org/andengine/entity/primitive/DrawMode.java
@@ -3,7 +3,7 @@
import android.opengl.GLES20;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:46:51 - 28.03.2012
diff --git a/src/org/andengine/entity/primitive/Gradient.java b/src/org/andengine/entity/primitive/Gradient.java
new file mode 100644
index 000000000..88b996a58
--- /dev/null
+++ b/src/org/andengine/entity/primitive/Gradient.java
@@ -0,0 +1,484 @@
+package org.andengine.entity.primitive;
+
+import org.andengine.engine.camera.Camera;
+import org.andengine.entity.primitive.vbo.HighPerformanceGradientVertexBufferObject;
+import org.andengine.entity.primitive.vbo.IGradientVertexBufferObject;
+import org.andengine.entity.shape.Shape;
+import org.andengine.opengl.shader.PositionColorShaderProgram;
+import org.andengine.opengl.shader.constants.ShaderProgramConstants;
+import org.andengine.opengl.util.GLState;
+import org.andengine.opengl.vbo.DrawType;
+import org.andengine.opengl.vbo.VertexBufferObjectManager;
+import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttribute;
+import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
+import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributesBuilder;
+import org.andengine.util.adt.color.Color;
+import org.andengine.util.math.MathUtils;
+
+import android.opengl.GLES20;
+
+/**
+ * (c) 2012 Zynga Inc.
+ *
+ * @author Nicolas Gramlich
+ * @since 14:23:56 - 23.04.2012
+ */
+public class Gradient extends Shape {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ public static final int VERTEX_INDEX_X = 0;
+ public static final int VERTEX_INDEX_Y = Gradient.VERTEX_INDEX_X + 1;
+ public static final int COLOR_INDEX = Gradient.VERTEX_INDEX_Y + 1;
+
+ public static final int VERTEX_SIZE = 2 + 1;
+ public static final int VERTICES_PER_RECTANGLE = 4;
+ public static final int RECTANGLE_SIZE = Gradient.VERTEX_SIZE * Gradient.VERTICES_PER_RECTANGLE;
+
+ public static final VertexBufferObjectAttributes VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT = new VertexBufferObjectAttributesBuilder(2)
+ .add(ShaderProgramConstants.ATTRIBUTE_POSITION_LOCATION, ShaderProgramConstants.ATTRIBUTE_POSITION, 2, GLES20.GL_FLOAT, false)
+ .add(ShaderProgramConstants.ATTRIBUTE_COLOR_LOCATION, ShaderProgramConstants.ATTRIBUTE_COLOR, 4, GLES20.GL_UNSIGNED_BYTE, true)
+ .build();
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ protected final IGradientVertexBufferObject mGradientVertexBufferObject;
+
+ private final Color mToColor = new Color(Color.WHITE);
+ private float mGradientVectorX = 0;
+ private float mGradientVectorY = -1;
+ private boolean mGradientFitToBounds;
+ private boolean mGradientDitherEnabled;
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ /**
+ * Uses a default {@link HighPerformanceGradientVertexBufferObject} in {@link DrawType#STATIC} with the {@link VertexBufferObjectAttribute}s: {@link Gradient#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
+ */
+ public Gradient(final float pX, final float pY, final float pWidth, final float pHeight, final VertexBufferObjectManager pVertexBufferObjectManager) {
+ this(pX, pY, pWidth, pHeight, pVertexBufferObjectManager, DrawType.STATIC);
+ }
+
+ /**
+ * Uses a default {@link HighPerformanceGradientVertexBufferObject} with the {@link VertexBufferObjectAttribute}s: {@link Gradient#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
+ */
+ public Gradient(final float pX, final float pY, final float pWidth, final float pHeight, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
+ this(pX, pY, pWidth, pHeight, new HighPerformanceGradientVertexBufferObject(pVertexBufferObjectManager, Gradient.RECTANGLE_SIZE, pDrawType, true, Gradient.VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT));
+ }
+
+ public Gradient(final float pX, final float pY, final float pWidth, final float pHeight, final IGradientVertexBufferObject pGradientVertexBufferObject) {
+ super(pX, pY, pWidth, pHeight, PositionColorShaderProgram.getInstance());
+
+ this.mGradientVertexBufferObject = pGradientVertexBufferObject;
+
+ this.onUpdateVertices();
+ this.onUpdateColor();
+
+ this.setBlendingEnabled(true);
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ public boolean isGradientFitToBounds() {
+ return this.mGradientFitToBounds;
+ }
+
+ /**
+ * @param pGradientFitToBounds If true ensures the from and to color are always on the bounds of the {@link Gradient} entity.
+ * If false the from and to color might exceed the bounds of the {@link Gradient} entity, depending on the angle/vector supplied.
+ */
+ public void setGradientFitToBounds(final boolean pGradientFitToBounds) {
+ if (this.mGradientFitToBounds != pGradientFitToBounds) {
+ this.mGradientFitToBounds = pGradientFitToBounds;
+
+ this.onUpdateColor();
+ }
+ }
+
+ public boolean isGradientDitherEnabled() {
+ return this.mGradientDitherEnabled;
+ }
+
+ /**
+ * @param pGradientDitherEnabled true to enable dither, false to use the currently active dither setting in {@link GLState}.
+ */
+ public void setGradientDitherEnabled(final boolean pGradientDitherEnabled) {
+ this.mGradientDitherEnabled = pGradientDitherEnabled;
+ }
+
+ @Deprecated
+ @Override
+ public float getRed() {
+ return super.getRed();
+ }
+
+ @Deprecated
+ @Override
+ public float getGreen() {
+ return super.getGreen();
+ }
+
+ @Deprecated
+ @Override
+ public float getBlue() {
+ return super.getBlue();
+ }
+
+ @Deprecated
+ @Override
+ public float getAlpha() {
+ return super.getAlpha();
+ }
+
+ @Deprecated
+ @Override
+ public Color getColor() {
+ return super.getColor();
+ }
+
+ @Deprecated
+ @Override
+ public void setRed(final float pRed) {
+ super.setRed(pRed);
+ }
+
+ @Deprecated
+ @Override
+ public void setGreen(final float pGreen) {
+ super.setGreen(pGreen);
+ }
+
+ @Deprecated
+ @Override
+ public void setBlue(final float pBlue) {
+ super.setBlue(pBlue);
+ }
+
+ @Deprecated
+ @Override
+ public void setAlpha(final float pAlpha) {
+ super.setAlpha(pAlpha);
+ }
+
+ @Deprecated
+ @Override
+ public void setColor(final Color pColor) {
+ super.setColor(pColor);
+ }
+
+ @Deprecated
+ @Override
+ public void setColor(final float pRed, final float pGreen, final float pBlue) {
+ super.setColor(pRed, pGreen, pBlue);
+ }
+
+ @Deprecated
+ @Override
+ public void setColor(final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
+ super.setColor(pRed, pGreen, pBlue, pAlpha);
+ }
+
+ public float getFromRed() {
+ return super.getRed();
+ }
+
+ public float getFromGreen() {
+ return super.getGreen();
+ }
+
+ public float getFromBlue() {
+ return super.getBlue();
+ }
+
+ public float getFromAlpha() {
+ return super.getAlpha();
+ }
+
+ public Color getFromColor() {
+ return super.getColor();
+ }
+
+ /**
+ * @param pRed from 0.0f to 1.0f
+ */
+ public void setFromRed(final float pRed) {
+ super.setRed(pRed);
+ }
+
+ /**
+ * @param pGreen from 0.0f to 1.0f
+ */
+ public void setFromGreen(final float pGreen) {
+ super.setGreen(pGreen);
+ }
+
+ /**
+ * @param pBlue from 0.0f to 1.0f
+ */
+ public void setFromBlue(final float pBlue) {
+ super.setBlue(pBlue);
+ }
+
+ /**
+ * @param pAlpha from 0.0f (transparent) to 1.0f (opaque)
+ */
+ public void setFromAlpha(final float pAlpha) {
+ super.setAlpha(pAlpha);
+ }
+
+ /**
+ * @param pRed from 0.0f to 1.0f
+ * @param pGreen from 0.0f to 1.0f
+ * @param pBlue from 0.0f to 1.0f
+ */
+ public void setFromColor(final float pRed, final float pGreen, final float pBlue) {
+ super.setColor(pRed, pGreen, pBlue);
+ }
+
+ /**
+ * @param pRed from 0.0f to 1.0f
+ * @param pGreen from 0.0f to 1.0f
+ * @param pBlue from 0.0f to 1.0f
+ * @param pAlpha from 0.0f (transparent) to 1.0f (opaque)
+ */
+ public void setFromColor(final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
+ super.setColor(pRed, pGreen, pBlue, pAlpha);
+ }
+
+ public void setFromColor(final Color pColor) {
+ super.setColor(pColor);
+ }
+
+ public float getToRed() {
+ return this.mToColor.getRed();
+ }
+
+ public float getToGreen() {
+ return this.mToColor.getGreen();
+ }
+
+ public float getToBlue() {
+ return this.mToColor.getBlue();
+ }
+
+ public float getToAlpha() {
+ return this.mToColor.getAlpha();
+ }
+
+ public Color getToColor() {
+ return this.mToColor;
+ }
+
+ /**
+ * @param pRed from 0.0f to 1.0f
+ */
+ public void setToRed(final float pRed) {
+ if (this.mToColor.setRedChecking(pRed)) { // TODO Is this check worth it?
+ this.onUpdateColor();
+ }
+ }
+
+ /**
+ * @param pGreen from 0.0f to 1.0f
+ */
+ public void setToGreen(final float pGreen) {
+ if (this.mToColor.setGreenChecking(pGreen)) { // TODO Is this check worth it?
+ this.onUpdateColor();
+ }
+ }
+
+ /**
+ * @param pBlue from 0.0f to 1.0f
+ */
+ public void setToBlue(final float pBlue) {
+ if (this.mToColor.setBlueChecking(pBlue)) { // TODO Is this check worth it?
+ this.onUpdateColor();
+ }
+ }
+
+ /**
+ * @param pAlpha from 0.0f (transparent) to 1.0f (opaque)
+ */
+ public void setToAlpha(final float pAlpha) {
+ if (this.mToColor.setAlphaChecking(pAlpha)) { // TODO Is this check worth it?
+ this.onUpdateColor();
+ }
+ }
+
+ /**
+ * @param pRed from 0.0f to 1.0f
+ * @param pGreen from 0.0f to 1.0f
+ * @param pBlue from 0.0f to 1.0f
+ */
+ public void setToColor(final float pRed, final float pGreen, final float pBlue) {
+ if (this.mToColor.setChecking(pRed, pGreen, pBlue)) { // TODO Is this check worth it?
+ this.onUpdateColor();
+ }
+ }
+
+ /**
+ * @param pRed from 0.0f to 1.0f
+ * @param pGreen from 0.0f to 1.0f
+ * @param pBlue from 0.0f to 1.0f
+ * @param pAlpha from 0.0f (transparent) to 1.0f (opaque)
+ */
+ public void setToColor(final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
+ if (this.mToColor.setChecking(pRed, pGreen, pBlue, pAlpha)) { // TODO Is this check worth it?
+ this.onUpdateColor();
+ }
+ }
+
+ public void setToColor(final Color pColor) {
+ if (this.mToColor.setChecking(pColor)) { // TODO Is this check worth it?
+ this.onUpdateColor();
+ }
+ }
+
+ public float getGradientVectorX() {
+ return this.mGradientVectorX;
+ }
+
+ public float getGradientVectorY() {
+ return this.mGradientVectorY;
+ }
+
+ public void setGradientVectorX(final float pGradientVectorX) {
+ this.mGradientVectorX = pGradientVectorX;
+
+ this.onUpdateColor();
+ }
+
+ public void setGradientVectorY(final float pGradientVectorY) {
+ this.mGradientVectorY = pGradientVectorY;
+
+ this.onUpdateColor();
+ }
+
+ public void setGradientVector(final float pGradientVectorX, final float pGradientVectorY) {
+ this.mGradientVectorX = pGradientVectorX;
+ this.mGradientVectorY = pGradientVectorY;
+
+ this.onUpdateColor();
+ }
+
+ /**
+ * @param pGradientAngle in degrees. 0 is a 'left-to-right', 90 is 'top-to-bottom', ...
+ */
+ public void setGradientAngle(final float pGradientAngle) {
+ final float angleInRad = MathUtils.degToRad(pGradientAngle);
+
+ this.setGradientVector((float) Math.cos(angleInRad), (float) Math.sin(angleInRad));
+ }
+
+ public void setGradientColor(final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue) {
+ this.mColor.set(pFromRed, pFromGreen, pFromBlue);
+ this.mToColor.set(pToRed, pToGreen, pToBlue);
+
+ this.onUpdateColor();
+ }
+
+ public void setGradientColor(final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue, final float pFromAlpha, final float pToAlpha) {
+ this.mColor.set(pFromRed, pFromGreen, pFromBlue, pFromAlpha);
+ this.mToColor.set(pToRed, pToGreen, pToBlue, pToAlpha);
+
+ this.onUpdateColor();
+ }
+
+ public void setGradientColor(final Color pFromColor, final Color pToColor) {
+ this.mColor.set(pFromColor);
+ this.mToColor.set(pToColor);
+
+ this.onUpdateColor();
+ }
+
+ public void setGradient(final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue, final float pGradientVectorX, final float pGradientVectorY) {
+ this.mGradientVectorX = pGradientVectorX;
+ this.mGradientVectorY = pGradientVectorY;
+
+ this.mColor.set(pFromRed, pFromGreen, pFromBlue);
+ this.mToColor.set(pToRed, pToGreen, pToBlue);
+
+ this.onUpdateColor();
+ }
+
+ public void setGradient(final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue, final float pFromAlpha, final float pToAlpha, final float pGradientVectorX, final float pGradientVectorY) {
+ this.mGradientVectorX = pGradientVectorX;
+ this.mGradientVectorY = pGradientVectorY;
+
+ this.mColor.set(pFromRed, pFromGreen, pFromBlue, pFromAlpha);
+ this.mToColor.set(pToRed, pToGreen, pToBlue, pToAlpha);
+
+ this.onUpdateColor();
+ }
+
+ public void setGradient(final Color pFromColor, final Color pToColor, final float pGradientVectorX, final float pGradientVectorY) {
+ this.mGradientVectorX = pGradientVectorX;
+ this.mGradientVectorY = pGradientVectorY;
+
+ this.mColor.set(pFromColor);
+ this.mToColor.set(pToColor);
+
+ this.onUpdateColor();
+ }
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ @Override
+ public IGradientVertexBufferObject getVertexBufferObject() {
+ return this.mGradientVertexBufferObject;
+ }
+
+ @Override
+ protected void preDraw(final GLState pGLState, final Camera pCamera) {
+ super.preDraw(pGLState, pCamera);
+
+ this.mGradientVertexBufferObject.bind(pGLState, this.mShaderProgram);
+ }
+
+ @Override
+ protected void draw(final GLState pGLState, final Camera pCamera) {
+ if (this.mGradientDitherEnabled) {
+ final boolean wasDitherEnabled = pGLState.enableDither();
+
+ this.mGradientVertexBufferObject.draw(GLES20.GL_TRIANGLE_STRIP, Gradient.VERTICES_PER_RECTANGLE);
+
+ pGLState.setDitherEnabled(wasDitherEnabled);
+ } else {
+ this.mGradientVertexBufferObject.draw(GLES20.GL_TRIANGLE_STRIP, Gradient.VERTICES_PER_RECTANGLE);
+ }
+ }
+
+ @Override
+ protected void postDraw(final GLState pGLState, final Camera pCamera) {
+ this.mGradientVertexBufferObject.unbind(pGLState, this.mShaderProgram);
+
+ super.postDraw(pGLState, pCamera);
+ }
+
+ @Override
+ protected void onUpdateColor() {
+ this.mGradientVertexBufferObject.onUpdateColor(this);
+ }
+
+ @Override
+ protected void onUpdateVertices() {
+ this.mGradientVertexBufferObject.onUpdateVertices(this);
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
\ No newline at end of file
diff --git a/src/org/andengine/entity/primitive/Line.java b/src/org/andengine/entity/primitive/Line.java
index 1bc892c53..57e3b47eb 100644
--- a/src/org/andengine/entity/primitive/Line.java
+++ b/src/org/andengine/entity/primitive/Line.java
@@ -1,10 +1,9 @@
package org.andengine.entity.primitive;
import org.andengine.engine.camera.Camera;
+import org.andengine.entity.IEntity;
import org.andengine.entity.primitive.vbo.HighPerformanceLineVertexBufferObject;
import org.andengine.entity.primitive.vbo.ILineVertexBufferObject;
-import org.andengine.entity.shape.IShape;
-import org.andengine.entity.shape.RectangularShape;
import org.andengine.entity.shape.Shape;
import org.andengine.opengl.shader.PositionColorShaderProgram;
import org.andengine.opengl.shader.constants.ShaderProgramConstants;
@@ -15,7 +14,6 @@
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributesBuilder;
import org.andengine.util.algorithm.collision.LineCollisionChecker;
-import org.andengine.util.algorithm.collision.RectangularShapeCollisionChecker;
import org.andengine.util.exception.MethodNotSupportedException;
import android.opengl.GLES20;
@@ -23,7 +21,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 09:50:36 - 04.04.2010
*/
@@ -32,7 +30,7 @@ public class Line extends Shape {
// Constants
// ===========================================================
- public static final float LINE_WIDTH_DEFAULT = 1.0f;
+ public static final float LINE_WIDTH_DEFAULT = GLState.LINE_WIDTH_DEFAULT;
public static final int VERTEX_INDEX_X = 0;
public static final int VERTEX_INDEX_Y = Line.VERTEX_INDEX_X + 1;
@@ -63,21 +61,21 @@ public class Line extends Shape {
// ===========================================================
/**
- * Uses a default {@link HighPerformanceLineVertexBufferObject} in {@link DrawType#STATIC} with the {@link VertexBufferObjectAttribute}s: {@link Line#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
+ * Uses a default {@link HighPerformanceLineVertexBufferObject} in {@link DrawType#STATIC} with the {@link VertexBufferObjectAttribute}s: {@link #VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
*/
public Line(final float pX1, final float pY1, final float pX2, final float pY2, final VertexBufferObjectManager pVertexBufferObjectManager) {
this(pX1, pY1, pX2, pY2, Line.LINE_WIDTH_DEFAULT, pVertexBufferObjectManager, DrawType.STATIC);
}
/**
- * Uses a default {@link HighPerformanceLineVertexBufferObject} with the {@link VertexBufferObjectAttribute}s: {@link Line#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
+ * Uses a default {@link HighPerformanceLineVertexBufferObject} with the {@link VertexBufferObjectAttribute}s: {@link #VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
*/
public Line(final float pX1, final float pY1, final float pX2, final float pY2, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
this(pX1, pY1, pX2, pY2, Line.LINE_WIDTH_DEFAULT, pVertexBufferObjectManager, pDrawType);
}
/**
- * Uses a default {@link HighPerformanceLineVertexBufferObject} in {@link DrawType#STATIC} with the {@link VertexBufferObjectAttribute}s: {@link Line#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
+ * Uses a default {@link HighPerformanceLineVertexBufferObject} in {@link DrawType#STATIC} with the {@link VertexBufferObjectAttribute}s: {@link #VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
*/
public Line(final float pX1, final float pY1, final float pX2, final float pY2, final float pLineWidth, final VertexBufferObjectManager pVertexBufferObjectManager) {
this(pX1, pY1, pX2, pY2, pLineWidth, pVertexBufferObjectManager, DrawType.STATIC);
@@ -88,11 +86,13 @@ public Line(final float pX1, final float pY1, final float pX2, final float pY2,
}
public Line(final float pX1, final float pY1, final float pX2, final float pY2, final float pLineWidth, final ILineVertexBufferObject pLineVertexBufferObject) {
- super(pX1, pY1, PositionColorShaderProgram.getInstance());
+ super(pX1, pY1, pX2 - pX1, pY2 - pY1, PositionColorShaderProgram.getInstance());
this.mX2 = pX2;
this.mY2 = pY2;
+ this.setOffsetCenter(0, 0);
+
this.mLineWidth = pLineWidth;
this.mLineVertexBufferObject = pLineVertexBufferObject;
@@ -100,15 +100,6 @@ public Line(final float pX1, final float pY1, final float pX2, final float pY2,
this.onUpdateVertices();
this.onUpdateColor();
- final float centerX = (this.mX2 - this.mX) * 0.5f;
- final float centerY = (this.mY2 - this.mY) * 0.5f;
-
- this.mRotationCenterX = centerX;
- this.mRotationCenterY = centerY;
-
- this.mScaleCenterX = this.mRotationCenterX;
- this.mScaleCenterY = this.mRotationCenterY;
-
this.setBlendingEnabled(true);
}
@@ -117,7 +108,7 @@ public Line(final float pX1, final float pY1, final float pX2, final float pY2,
// ===========================================================
/**
- * @deprecated Instead use {@link Line#getX1()} or {@link Line#getX2()}.
+ * @deprecated Instead use {@link #getX1()} or {@link #getX2()}.
*/
@Deprecated
@Override
@@ -126,7 +117,7 @@ public float getX() {
}
/**
- * @deprecatedInstead use {@link Line#getY1()} or {@link Line#getY2()}.
+ * @deprecated Instead use {@link #getY1()} or {@link #getY2()}.
*/
@Deprecated
@Override
@@ -159,33 +150,37 @@ public void setLineWidth(final float pLineWidth) {
}
/**
- * Instead use {@link Line#setPosition(float, float, float, float)}.
+ * Instead use {@link #setPosition(float, float, float, float)}.
*/
@Deprecated
@Override
public void setX(final float pX) {
final float dX = this.mX - pX;
+ this.mX2 += dX;
+
super.setX(pX);
- this.mX2 += dX;
+ this.onUpdateVertices();
}
/**
- * Instead use {@link Line#setPosition(float, float, float, float)}.
+ * Instead use {@link #setPosition(float, float, float, float)}.
*/
@Deprecated
@Override
public void setY(final float pY) {
final float dY = this.mY - pY;
-
- super.setY(pY);
-
+
this.mY2 += dY;
+
+ super.setY(pY);
+
+ this.onUpdateVertices();
}
/**
- * Instead use {@link Line#setPosition(float, float, float, float)}.
+ * Instead use {@link #setPosition(float, float, float, float)}.
*/
@Deprecated
@Override
@@ -193,10 +188,12 @@ public void setPosition(final float pX, final float pY) {
final float dX = this.mX - pX;
final float dY = this.mY - pY;
- super.setPosition(pX, pY);
-
this.mX2 += dX;
this.mY2 += dY;
+
+ super.setPosition(pX, pY);
+
+ this.onUpdateVertices();
}
public void setPosition(final float pX1, final float pY1, final float pX2, final float pY2) {
@@ -208,6 +205,24 @@ public void setPosition(final float pX1, final float pY1, final float pX2, final
this.onUpdateVertices();
}
+ @Deprecated
+ @Override
+ public void setWidth(final float pWidth) {
+ super.setWidth(pWidth);
+ }
+
+ @Deprecated
+ @Override
+ public void setHeight(final float pHeight) {
+ super.setHeight(pHeight);
+ }
+
+ @Deprecated
+ @Override
+ public void setSize(final float pWidth, final float pHeight) {
+ super.setSize(pWidth, pHeight);
+ }
+
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@@ -270,14 +285,12 @@ public boolean contains(final float pX, final float pY) {
}
@Override
- public boolean collidesWith(final IShape pOtherShape) {
- if(pOtherShape instanceof Line) {
- final Line otherLine = (Line) pOtherShape;
+ public boolean collidesWith(final IEntity pOtherEntity) {
+ if (pOtherEntity instanceof Line) {
+ final Line otherLine = (Line) pOtherEntity;
return LineCollisionChecker.checkLineCollision(this.mX, this.mY, this.mX2, this.mY2, otherLine.mX, otherLine.mY, otherLine.mX2, otherLine.mY2);
- } else if(pOtherShape instanceof RectangularShape) {
- return RectangularShapeCollisionChecker.checkCollision((RectangularShape) pOtherShape, this);
} else {
- return false;
+ return super.collidesWith(pOtherEntity);
}
}
diff --git a/src/org/andengine/entity/primitive/LineChain.java b/src/org/andengine/entity/primitive/LineChain.java
new file mode 100644
index 000000000..27db8f6c5
--- /dev/null
+++ b/src/org/andengine/entity/primitive/LineChain.java
@@ -0,0 +1,311 @@
+package org.andengine.entity.primitive;
+
+import org.andengine.engine.camera.Camera;
+import org.andengine.entity.primitive.vbo.HighPerformanceLineChainVertexBufferObject;
+import org.andengine.entity.primitive.vbo.ILineChainVertexBufferObject;
+import org.andengine.entity.shape.Shape;
+import org.andengine.opengl.shader.PositionColorShaderProgram;
+import org.andengine.opengl.shader.constants.ShaderProgramConstants;
+import org.andengine.opengl.util.GLState;
+import org.andengine.opengl.vbo.DrawType;
+import org.andengine.opengl.vbo.VertexBufferObjectManager;
+import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttribute;
+import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
+import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributesBuilder;
+import org.andengine.util.exception.MethodNotSupportedException;
+
+import android.opengl.GLES20;
+
+/**
+ * (c) 2013 Nicolas Gramlich
+ *
+ * @author Nicolas Gramlich
+ * @since 20:26:36 - 30.05.2013
+ */
+public abstract class LineChain extends Shape {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ public static final float LINE_WIDTH_DEFAULT = GLState.LINE_WIDTH_DEFAULT;
+
+ public static final int VERTEX_INDEX_X = 0;
+ public static final int VERTEX_INDEX_Y = LineChain.VERTEX_INDEX_X + 1;
+ public static final int COLOR_INDEX = LineChain.VERTEX_INDEX_Y + 1;
+
+ public static final int VERTEX_SIZE = 2 + 1;
+
+ public static final VertexBufferObjectAttributes VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT = new VertexBufferObjectAttributesBuilder(2)
+ .add(ShaderProgramConstants.ATTRIBUTE_POSITION_LOCATION, ShaderProgramConstants.ATTRIBUTE_POSITION, 2, GLES20.GL_FLOAT, false)
+ .add(ShaderProgramConstants.ATTRIBUTE_COLOR_LOCATION, ShaderProgramConstants.ATTRIBUTE_COLOR, 4, GLES20.GL_UNSIGNED_BYTE, true)
+ .build();
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ protected int mCapacity;
+ protected final ILineChainVertexBufferObject mLineChainVertexBufferObject;
+
+ protected final float[] mXs;
+ protected final float[] mYs;
+
+ protected float mLineWidth;
+
+ protected int mIndex;
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ /**
+ * Uses a default {@link HighPerformanceLineChainVertexBufferObject} in {@link DrawType#STATIC} with the {@link VertexBufferObjectAttribute}s: {@link #VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
+ */
+ public LineChain(final float pX, final float pY, final int pCapacity, final VertexBufferObjectManager pVertexBufferObjectManager) {
+ this(pX, pY, LineChain.LINE_WIDTH_DEFAULT, pCapacity, pVertexBufferObjectManager, DrawType.STATIC);
+ }
+
+ /**
+ * Uses a default {@link HighPerformanceLineChainVertexBufferObject} with the {@link VertexBufferObjectAttribute}s: {@link #VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
+ */
+ public LineChain(final float pX, final float pY, final int pCapacity, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
+ this(pX, pY, LineChain.LINE_WIDTH_DEFAULT, pCapacity, pVertexBufferObjectManager, pDrawType);
+ }
+
+ /**
+ * Uses a default {@link HighPerformanceLineChainVertexBufferObject} in {@link DrawType#STATIC} with the {@link VertexBufferObjectAttribute}s: {@link #VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
+ */
+ public LineChain(final float pX, final float pY, final float pLineWidth, final int pCapacity, final VertexBufferObjectManager pVertexBufferObjectManager) {
+ this(pX, pY, pLineWidth, pCapacity, pVertexBufferObjectManager, DrawType.STATIC);
+ }
+
+ public LineChain(final float pX, final float pY, final float pLineWidth, final int pCapacity, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
+ this(pX, pY, pLineWidth, pCapacity, new HighPerformanceLineChainVertexBufferObject(pVertexBufferObjectManager, pCapacity * LineChain.VERTEX_SIZE, pDrawType, true, LineChain.VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT));
+ }
+
+ public LineChain(final float pX, final float pY, final float pLineWidth, final int pCapacity, final ILineChainVertexBufferObject pLineChainVertexBufferObject) {
+ super(pX, pY, 0, 0, PositionColorShaderProgram.getInstance());
+
+ this.mXs = new float[pCapacity];
+ this.mYs = new float[pCapacity];
+ this.mCapacity = pCapacity;
+
+ this.mLineWidth = pLineWidth;
+
+ this.mLineChainVertexBufferObject = pLineChainVertexBufferObject;
+
+ this.onUpdateVertices();
+ this.onUpdateColor();
+
+ this.setBlendingEnabled(true);
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ public int getCapacity() {
+ return this.mCapacity;
+ }
+
+ public int getIndex() {
+ return this.mIndex;
+ }
+
+ public void setIndex(final int pIndex) {
+ this.assertCapacity(pIndex);
+
+ this.mIndex = pIndex;
+ }
+
+ public float getLineWidth() {
+ return this.mLineWidth;
+ }
+
+ public void setLineWidth(final float pLineWidth) {
+ this.mLineWidth = pLineWidth;
+ }
+
+ @Override
+ public void setX(final float pX) {
+ final float dX = this.mX - pX;
+
+ for (int i = this.mIndex - 1; i >= 0; i++) {
+ this.mXs[i] += dX;
+ }
+
+ super.setX(pX);
+
+ this.onUpdateVertices();
+ }
+
+ @Override
+ public void setY(final float pY) {
+ final float dY = this.mY - pY;
+
+ for (int i = this.mIndex - 1; i >= 0; i++) {
+ this.mYs[i] += dY;
+ }
+
+ super.setY(pY);
+
+ this.onUpdateVertices();
+ }
+
+ @Override
+ public void setPosition(final float pX, final float pY) {
+ final float dX = this.mX - pX;
+ final float dY = this.mY - pY;
+
+ for (int i = this.mIndex - 1; i >= 0; i++) {
+ this.mXs[i] += dX;
+ this.mYs[i] += dY;
+ }
+
+ super.setPosition(pX, pY);
+
+ this.onUpdateVertices();
+ }
+
+ public float getX(final int pIndex) {
+ this.assertCapacity(pIndex);
+
+ return this.mX + this.mXs[pIndex];
+ }
+
+ public float getY(final int pIndex) {
+ this.assertCapacity(pIndex);
+
+ return this.mY + this.mYs[pIndex];
+ }
+
+ public void setX(final int pIndex, final float pX) {
+ this.assertCapacity(pIndex);
+ this.assertIndex(pIndex);
+
+ this.mXs[pIndex] = pX;
+
+ this.onUpdateVertices();
+ }
+
+ public void setY(final int pIndex, final float pY) {
+ this.assertCapacity(pIndex);
+ this.assertIndex(pIndex);
+
+ this.mYs[pIndex] = pY;
+
+ this.onUpdateVertices();
+ }
+
+ public void add(final float pX, final float pY) {
+ this.assertCapacity();
+
+ this.mXs[this.mIndex] = pX;
+ this.mYs[this.mIndex] = pY;
+
+ this.mIndex++;
+
+ this.onUpdateVertices();
+ }
+
+ public void shift() {
+ final int length = this.mCapacity - 1;
+ System.arraycopy(this.mXs, 0, this.mXs, 1, length);
+ System.arraycopy(this.mYs, 0, this.mYs, 1, length);
+ }
+
+ @Deprecated
+ @Override
+ public void setWidth(final float pWidth) {
+ super.setWidth(pWidth);
+ }
+
+ @Deprecated
+ @Override
+ public void setHeight(final float pHeight) {
+ super.setHeight(pHeight);
+ }
+
+ @Deprecated
+ @Override
+ public void setSize(final float pWidth, final float pHeight) {
+ super.setSize(pWidth, pHeight);
+ }
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ @Override
+ public ILineChainVertexBufferObject getVertexBufferObject() {
+ return this.mLineChainVertexBufferObject;
+ }
+
+ @Override
+ protected void preDraw(final GLState pGLState, final Camera pCamera) {
+ super.preDraw(pGLState, pCamera);
+
+ pGLState.lineWidth(this.mLineWidth);
+
+ this.mLineChainVertexBufferObject.bind(pGLState, this.mShaderProgram);
+ }
+
+ @Override
+ protected void postDraw(final GLState pGLState, final Camera pCamera) {
+ this.mLineChainVertexBufferObject.unbind(pGLState, this.mShaderProgram);
+
+ super.postDraw(pGLState, pCamera);
+ }
+
+ @Override
+ protected void onUpdateColor() {
+ this.mLineChainVertexBufferObject.onUpdateColor(this);
+ }
+
+ @Override
+ protected void onUpdateVertices() {
+ this.mLineChainVertexBufferObject.onUpdateVertices(this);
+ }
+
+ @Override
+ public float[] getSceneCenterCoordinates() {
+ throw new MethodNotSupportedException();
+ }
+
+ @Override
+ public float[] getSceneCenterCoordinates(final float[] pReuse) {
+ throw new MethodNotSupportedException();
+ }
+
+ @Override
+ @Deprecated
+ public boolean contains(final float pX, final float pY) {
+ throw new MethodNotSupportedException();
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ private void assertIndex(final int pIndex) {
+ if (pIndex >= this.mIndex - 1) {
+ throw new IllegalStateException("This supplied pIndex: '" + pIndex + "' is exceeding the current index: '" + this.mIndex + "' of this " + this.getClass().getSimpleName() + "!");
+ }
+ }
+
+ private void assertCapacity(final int pIndex) {
+ if (pIndex >= this.mCapacity) {
+ throw new IllegalStateException("This supplied pIndex: '" + pIndex + "' is exceeding the capacity: '" + this.mCapacity + "' of this " + this.getClass().getSimpleName() + "!");
+ }
+ }
+
+ private void assertCapacity() {
+ if (this.mIndex == this.mCapacity) {
+ throw new IllegalStateException("This " + this.getClass().getSimpleName() + " has already reached its capacity (" + this.mCapacity + ") !");
+ }
+ }
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
\ No newline at end of file
diff --git a/src/org/andengine/entity/primitive/LineLoop.java b/src/org/andengine/entity/primitive/LineLoop.java
new file mode 100644
index 000000000..b1a8ea454
--- /dev/null
+++ b/src/org/andengine/entity/primitive/LineLoop.java
@@ -0,0 +1,70 @@
+package org.andengine.entity.primitive;
+
+import org.andengine.engine.camera.Camera;
+import org.andengine.entity.primitive.vbo.ILineChainVertexBufferObject;
+import org.andengine.opengl.util.GLState;
+import org.andengine.opengl.vbo.DrawType;
+import org.andengine.opengl.vbo.VertexBufferObjectManager;
+
+import android.opengl.GLES20;
+
+/**
+ * (c) 2013 Nicolas Gramlich
+ *
+ * @author Nicolas Gramlich
+ * @since 13:51:36 - 01.06.2013
+ */
+public class LineLoop extends LineChain {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ public LineLoop(final float pX, final float pY, final int pCapacity, final VertexBufferObjectManager pVertexBufferObjectManager) {
+ super(pX, pY, pCapacity, pVertexBufferObjectManager);
+ }
+
+ public LineLoop(final float pX, final float pY, final int pCapacity, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
+ super(pX, pY, pCapacity, pVertexBufferObjectManager, pDrawType);
+ }
+
+ public LineLoop(final float pX, final float pY, final float pLineWidth, final int pCapacity, final VertexBufferObjectManager pVertexBufferObjectManager) {
+ super(pX, pY, pLineWidth, pCapacity, pVertexBufferObjectManager);
+ }
+
+ public LineLoop(final float pX, final float pY, final float pLineWidth, final int pCapacity, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
+ super(pX, pY, pLineWidth, pCapacity, pVertexBufferObjectManager, pDrawType);
+ }
+
+ public LineLoop(final float pX, final float pY, final float pLineWidth, final int pCapacity, final ILineChainVertexBufferObject pLineChainVertexBufferObject) {
+ super(pX, pY, pLineWidth, pCapacity, pLineChainVertexBufferObject);
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ @Override
+ protected void draw(final GLState pGLState, final Camera pCamera) {
+ this.mLineChainVertexBufferObject.draw(GLES20.GL_LINE_LOOP, this.mIndex);
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
diff --git a/src/org/andengine/entity/primitive/LineStrip.java b/src/org/andengine/entity/primitive/LineStrip.java
new file mode 100644
index 000000000..c9b5959b1
--- /dev/null
+++ b/src/org/andengine/entity/primitive/LineStrip.java
@@ -0,0 +1,70 @@
+package org.andengine.entity.primitive;
+
+import org.andengine.engine.camera.Camera;
+import org.andengine.entity.primitive.vbo.ILineChainVertexBufferObject;
+import org.andengine.opengl.util.GLState;
+import org.andengine.opengl.vbo.DrawType;
+import org.andengine.opengl.vbo.VertexBufferObjectManager;
+
+import android.opengl.GLES20;
+
+/**
+ * (c) 2013 Nicolas Gramlich
+ *
+ * @author Nicolas Gramlich
+ * @since 13:51:36 - 01.06.2013
+ */
+public class LineStrip extends LineChain {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ public LineStrip(final float pX, final float pY, final int pCapacity, final VertexBufferObjectManager pVertexBufferObjectManager) {
+ super(pX, pY, pCapacity, pVertexBufferObjectManager);
+ }
+
+ public LineStrip(final float pX, final float pY, final int pCapacity, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
+ super(pX, pY, pCapacity, pVertexBufferObjectManager, pDrawType);
+ }
+
+ public LineStrip(final float pX, final float pY, final float pLineWidth, final int pCapacity, final VertexBufferObjectManager pVertexBufferObjectManager) {
+ super(pX, pY, pLineWidth, pCapacity, pVertexBufferObjectManager);
+ }
+
+ public LineStrip(final float pX, final float pY, final float pLineWidth, final int pCapacity, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
+ super(pX, pY, pLineWidth, pCapacity, pVertexBufferObjectManager, pDrawType);
+ }
+
+ public LineStrip(final float pX, final float pY, final float pLineWidth, final int pCapacity, final ILineChainVertexBufferObject pLineChainVertexBufferObject) {
+ super(pX, pY, pLineWidth, pCapacity, pLineChainVertexBufferObject);
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ @Override
+ protected void draw(final GLState pGLState, final Camera pCamera) {
+ this.mLineChainVertexBufferObject.draw(GLES20.GL_LINE_STRIP, this.mIndex);
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
diff --git a/src/org/andengine/entity/primitive/Mesh.java b/src/org/andengine/entity/primitive/Mesh.java
index 0f083e4e1..840968e91 100644
--- a/src/org/andengine/entity/primitive/Mesh.java
+++ b/src/org/andengine/entity/primitive/Mesh.java
@@ -1,10 +1,9 @@
package org.andengine.entity.primitive;
import org.andengine.engine.camera.Camera;
+import org.andengine.entity.IEntity;
import org.andengine.entity.primitive.vbo.HighPerformanceMeshVertexBufferObject;
import org.andengine.entity.primitive.vbo.IMeshVertexBufferObject;
-import org.andengine.entity.shape.IShape;
-import org.andengine.entity.shape.RectangularShape;
import org.andengine.entity.shape.Shape;
import org.andengine.opengl.shader.PositionColorShaderProgram;
import org.andengine.opengl.shader.constants.ShaderProgramConstants;
@@ -19,7 +18,7 @@
import android.opengl.GLES20;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 16:44:50 - 09.02.2012
@@ -56,18 +55,36 @@ public class Mesh extends Shape {
* Uses a default {@link HighPerformanceMeshVertexBufferObject} in {@link DrawType#STATIC} with the {@link VertexBufferObjectAttribute}s: {@link Mesh#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
*/
public Mesh(final float pX, final float pY, final float[] pBufferData, final int pVertexCount, final DrawMode pDrawMode, final VertexBufferObjectManager pVertexBufferObjectManager) {
- this(pX, pY, pBufferData, pVertexCount, pDrawMode, pVertexBufferObjectManager, DrawType.STATIC);
+ this(pX, pY, 0, 0, pBufferData, pVertexCount, pDrawMode, pVertexBufferObjectManager);
+ }
+
+ /**
+ * Uses a default {@link HighPerformanceMeshVertexBufferObject} in {@link DrawType#STATIC} with the {@link VertexBufferObjectAttribute}s: {@link Mesh#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
+ */
+ public Mesh(final float pX, final float pY, final float pWidth, final float pHeight, final float[] pBufferData, final int pVertexCount, final DrawMode pDrawMode, final VertexBufferObjectManager pVertexBufferObjectManager) {
+ this(pX, pY, pWidth, pHeight, pBufferData, pVertexCount, pDrawMode, pVertexBufferObjectManager, DrawType.STATIC);
}
/**
* Uses a default {@link HighPerformanceMeshVertexBufferObject} with the {@link VertexBufferObjectAttribute}s: {@link Mesh#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
*/
public Mesh(final float pX, final float pY, final float[] pBufferData, final int pVertexCount, final DrawMode pDrawMode, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
- this(pX, pY, pVertexCount, pDrawMode, new HighPerformanceMeshVertexBufferObject(pVertexBufferObjectManager, pBufferData, pVertexCount, pDrawType, true, Mesh.VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT));
+ this(pX, pY, 0, 0, pBufferData, pVertexCount, pDrawMode, pVertexBufferObjectManager, pDrawType);
+ }
+
+ /**
+ * Uses a default {@link HighPerformanceMeshVertexBufferObject} with the {@link VertexBufferObjectAttribute}s: {@link Mesh#VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT}.
+ */
+ public Mesh(final float pX, final float pY, final float pWidth, final float pHeight, final float[] pBufferData, final int pVertexCount, final DrawMode pDrawMode, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
+ this(pX, pY, pWidth, pHeight, pVertexCount, pDrawMode, new HighPerformanceMeshVertexBufferObject(pVertexBufferObjectManager, pBufferData, pVertexCount, pDrawType, true, Mesh.VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT));
}
public Mesh(final float pX, final float pY, final int pVertexCount, final DrawMode pDrawMode, final IMeshVertexBufferObject pMeshVertexBufferObject) {
- super(pX, pY, PositionColorShaderProgram.getInstance());
+ this(pX, pY, 0, 0, pVertexCount, pDrawMode, pMeshVertexBufferObject);
+ }
+
+ public Mesh(final float pX, final float pY, final float pWidth, final float pHeight, final int pVertexCount, final DrawMode pDrawMode, final IMeshVertexBufferObject pMeshVertexBufferObject) {
+ super(pX, pY, pWidth, pHeight, PositionColorShaderProgram.getInstance());
this.mDrawMode = pDrawMode.getDrawMode();
this.mMeshVertexBufferObject = pMeshVertexBufferObject;
@@ -139,15 +156,15 @@ public boolean contains(final float pX, final float pY) {
}
@Override
- public boolean collidesWith(final IShape pOtherShape) {
- if(pOtherShape instanceof Line) {
+ public boolean collidesWith(final IEntity pOtherEntity) {
+ if (pOtherEntity instanceof Mesh) {
// TODO
- return false;
- } else if(pOtherShape instanceof RectangularShape) {
+ return super.collidesWith(pOtherEntity);
+ } else if (pOtherEntity instanceof Line) {
// TODO
- return false;
+ return super.collidesWith(pOtherEntity);
} else {
- return false;
+ return super.collidesWith(pOtherEntity);
}
}
diff --git a/src/org/andengine/entity/primitive/Rectangle.java b/src/org/andengine/entity/primitive/Rectangle.java
index 1eeab4434..c56ec30b6 100644
--- a/src/org/andengine/entity/primitive/Rectangle.java
+++ b/src/org/andengine/entity/primitive/Rectangle.java
@@ -3,7 +3,7 @@
import org.andengine.engine.camera.Camera;
import org.andengine.entity.primitive.vbo.HighPerformanceRectangleVertexBufferObject;
import org.andengine.entity.primitive.vbo.IRectangleVertexBufferObject;
-import org.andengine.entity.shape.RectangularShape;
+import org.andengine.entity.shape.Shape;
import org.andengine.opengl.shader.PositionColorShaderProgram;
import org.andengine.opengl.shader.constants.ShaderProgramConstants;
import org.andengine.opengl.util.GLState;
@@ -18,11 +18,11 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 12:18:49 - 13.03.2010
*/
-public class Rectangle extends RectangularShape {
+public class Rectangle extends Shape {
// ===========================================================
// Constants
// ===========================================================
diff --git a/src/org/andengine/entity/primitive/vbo/HighPerformanceGradientVertexBufferObject.java b/src/org/andengine/entity/primitive/vbo/HighPerformanceGradientVertexBufferObject.java
new file mode 100644
index 000000000..0ead93196
--- /dev/null
+++ b/src/org/andengine/entity/primitive/vbo/HighPerformanceGradientVertexBufferObject.java
@@ -0,0 +1,129 @@
+package org.andengine.entity.primitive.vbo;
+
+import org.andengine.entity.primitive.Gradient;
+import org.andengine.opengl.vbo.DrawType;
+import org.andengine.opengl.vbo.HighPerformanceVertexBufferObject;
+import org.andengine.opengl.vbo.VertexBufferObjectManager;
+import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
+import org.andengine.util.adt.color.ColorUtils;
+import org.andengine.util.math.MathConstants;
+import org.andengine.util.math.MathUtils;
+
+/**
+ * (c) 2012 Zynga Inc.
+ *
+ * @author Nicolas Gramlich
+ * @since 14:27:09 - 23.04.2012
+ */
+public class HighPerformanceGradientVertexBufferObject extends HighPerformanceVertexBufferObject implements IGradientVertexBufferObject {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ public HighPerformanceGradientVertexBufferObject(final VertexBufferObjectManager pVertexBufferObjectManager, final int pCapacity, final DrawType pDrawType, final boolean pAutoDispose, final VertexBufferObjectAttributes pVertexBufferObjectAttributes) {
+ super(pVertexBufferObjectManager, pCapacity, pDrawType, pAutoDispose, pVertexBufferObjectAttributes);
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ @Override
+ public void onUpdateColor(final Gradient pGradient) {
+ final float[] bufferData = this.mBufferData;
+
+ final float gradientVectorX = pGradient.getGradientVectorX();
+ final float gradientVectorY = pGradient.getGradientVectorY();
+
+ final float length = MathUtils.length(gradientVectorX, gradientVectorY);
+ if (length == 0) {
+ return;
+ }
+
+ float dX = gradientVectorX / length;
+ float dY = gradientVectorY / length;
+
+ final float c = MathConstants.SQRT_2;
+ final float c2 = 2 * c;
+
+ if (pGradient.isGradientFitToBounds()) {
+ final float tmp = 1 / (Math.abs(dX) + Math.abs(dY));
+ dX *= tmp * c;
+ dY *= tmp * c;
+ }
+
+ final float fromRed = pGradient.getFromRed();
+ final float fromGreen = pGradient.getFromGreen();
+ final float fromBlue = pGradient.getFromBlue();
+ final float fromAlpha = pGradient.getFromAlpha(); // TODO * 'this.mOverallOpactity'
+
+ final float toRed = pGradient.getToRed();
+ final float toGreen = pGradient.getToGreen();
+ final float toBlue = pGradient.getToBlue();
+ final float toAlpha = pGradient.getToAlpha(); // TODO * 'this.mOverallOpactity'
+
+ /* Pre-fetch some calculations. */
+ final float dRed = fromRed - toRed;
+ final float dGreen = fromGreen - toGreen;
+ final float dBlue = fromBlue - toBlue;
+ final float dAlpha = fromAlpha - toAlpha;
+
+
+ final float v0 = (c + dX + dY) / c2;
+ bufferData[(0 * Gradient.VERTEX_SIZE) + Gradient.COLOR_INDEX] = ColorUtils.convertRGBAToABGRPackedFloat(toRed + (dRed * v0), toGreen + (dGreen * v0), toBlue + (dBlue * v0), toAlpha + (dAlpha * v0));
+
+ final float v1 = (c + dX - dY) / c2;
+ bufferData[(1 * Gradient.VERTEX_SIZE) + Gradient.COLOR_INDEX] = ColorUtils.convertRGBAToABGRPackedFloat(toRed + (dRed * v1), toGreen + (dGreen * v1), toBlue + (dBlue * v1), toAlpha + (dAlpha * v1));
+
+ final float v2 = (c - dX + dY) / c2;
+ bufferData[(2 * Gradient.VERTEX_SIZE) + Gradient.COLOR_INDEX] = ColorUtils.convertRGBAToABGRPackedFloat(toRed + (dRed * v2), toGreen + (dGreen * v2), toBlue + (dBlue * v2), toAlpha + (dAlpha * v2));
+
+ final float v3 = (c - dX - dY) / c2;
+ bufferData[(3 * Gradient.VERTEX_SIZE) + Gradient.COLOR_INDEX] = ColorUtils.convertRGBAToABGRPackedFloat(toRed + (dRed * v3), toGreen + (dGreen * v3), toBlue + (dBlue * v3), toAlpha + (dAlpha * v3));
+
+
+ this.setDirtyOnHardware();
+ }
+
+ @Override
+ public void onUpdateVertices(final Gradient pGradient) {
+ final float[] bufferData = this.mBufferData;
+
+ final float width = pGradient.getWidth(); // TODO Optimize with field access?
+ final float height = pGradient.getHeight(); // TODO Optimize with field access?
+
+ bufferData[(0 * Gradient.VERTEX_SIZE) + Gradient.VERTEX_INDEX_X] = 0;
+ bufferData[(0 * Gradient.VERTEX_SIZE) + Gradient.VERTEX_INDEX_Y] = 0;
+
+ bufferData[(1 * Gradient.VERTEX_SIZE) + Gradient.VERTEX_INDEX_X] = 0;
+ bufferData[(1 * Gradient.VERTEX_SIZE) + Gradient.VERTEX_INDEX_Y] = height;
+
+ bufferData[(2 * Gradient.VERTEX_SIZE) + Gradient.VERTEX_INDEX_X] = width;
+ bufferData[(2 * Gradient.VERTEX_SIZE) + Gradient.VERTEX_INDEX_Y] = 0;
+
+ bufferData[(3 * Gradient.VERTEX_SIZE) + Gradient.VERTEX_INDEX_X] = width;
+ bufferData[(3 * Gradient.VERTEX_SIZE) + Gradient.VERTEX_INDEX_Y] = height;
+
+ this.setDirtyOnHardware();
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
\ No newline at end of file
diff --git a/src/org/andengine/entity/primitive/vbo/HighPerformanceLineChainVertexBufferObject.java b/src/org/andengine/entity/primitive/vbo/HighPerformanceLineChainVertexBufferObject.java
new file mode 100644
index 000000000..c95700ff8
--- /dev/null
+++ b/src/org/andengine/entity/primitive/vbo/HighPerformanceLineChainVertexBufferObject.java
@@ -0,0 +1,78 @@
+package org.andengine.entity.primitive.vbo;
+
+import org.andengine.entity.primitive.LineChain;
+import org.andengine.opengl.vbo.DrawType;
+import org.andengine.opengl.vbo.HighPerformanceVertexBufferObject;
+import org.andengine.opengl.vbo.VertexBufferObjectManager;
+import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
+
+/**
+ * (c) 2013 Nicolas Gramlich
+ *
+ * @author Nicolas Gramlich
+ * @since 21:50:00 - 30.05.2013
+ */
+public class HighPerformanceLineChainVertexBufferObject extends HighPerformanceVertexBufferObject implements ILineChainVertexBufferObject {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ public HighPerformanceLineChainVertexBufferObject(final VertexBufferObjectManager pVertexBufferObjectManager, final int pCapacity, final DrawType pDrawType, final boolean pAutoDispose, final VertexBufferObjectAttributes pVertexBufferObjectAttributes) {
+ super(pVertexBufferObjectManager, pCapacity, pDrawType, pAutoDispose, pVertexBufferObjectAttributes);
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ @Override
+ public void onUpdateColor(final LineChain pLineChain) {
+ final float[] bufferData = this.mBufferData;
+
+ final float packedColor = pLineChain.getColor().getABGRPackedFloat();
+
+ for (int i = pLineChain.getCapacity() - 1; i >= 0; i--) {
+ bufferData[(i * LineChain.VERTEX_SIZE) + LineChain.COLOR_INDEX] = packedColor;
+ }
+
+ this.setDirtyOnHardware();
+ }
+
+ @Override
+ public void onUpdateVertices(final LineChain pLineChain) {
+ final float[] bufferData = this.mBufferData;
+
+ bufferData[(0 * LineChain.VERTEX_SIZE) + LineChain.VERTEX_INDEX_X] = 0;
+ bufferData[(0 * LineChain.VERTEX_SIZE) + LineChain.VERTEX_INDEX_Y] = 0;
+
+ final float x = pLineChain.getX();
+ final float y = pLineChain.getY();
+
+ for (int i = pLineChain.getCapacity() - 1; i >= 0; i--) {
+ bufferData[(i * LineChain.VERTEX_SIZE) + LineChain.VERTEX_INDEX_X] = pLineChain.getX(i) - x;
+ bufferData[(i * LineChain.VERTEX_SIZE) + LineChain.VERTEX_INDEX_Y] = pLineChain.getY(i) - y;
+ }
+
+ this.setDirtyOnHardware();
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
\ No newline at end of file
diff --git a/src/org/andengine/entity/primitive/vbo/HighPerformanceLineVertexBufferObject.java b/src/org/andengine/entity/primitive/vbo/HighPerformanceLineVertexBufferObject.java
index 31665570a..7c5282499 100644
--- a/src/org/andengine/entity/primitive/vbo/HighPerformanceLineVertexBufferObject.java
+++ b/src/org/andengine/entity/primitive/vbo/HighPerformanceLineVertexBufferObject.java
@@ -7,7 +7,7 @@
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:45:00 - 28.03.2012
@@ -43,8 +43,8 @@ public void onUpdateColor(final Line pLine) {
final float packedColor = pLine.getColor().getABGRPackedFloat();
- bufferData[0 * Line.VERTEX_SIZE + Line.COLOR_INDEX] = packedColor;
- bufferData[1 * Line.VERTEX_SIZE + Line.COLOR_INDEX] = packedColor;
+ bufferData[(0 * Line.VERTEX_SIZE) + Line.COLOR_INDEX] = packedColor;
+ bufferData[(1 * Line.VERTEX_SIZE) + Line.COLOR_INDEX] = packedColor;
this.setDirtyOnHardware();
}
@@ -53,11 +53,11 @@ public void onUpdateColor(final Line pLine) {
public void onUpdateVertices(final Line pLine) {
final float[] bufferData = this.mBufferData;
- bufferData[0 * Line.VERTEX_SIZE + Line.VERTEX_INDEX_X] = 0;
- bufferData[0 * Line.VERTEX_SIZE + Line.VERTEX_INDEX_Y] = 0;
+ bufferData[(0 * Line.VERTEX_SIZE) + Line.VERTEX_INDEX_X] = 0;
+ bufferData[(0 * Line.VERTEX_SIZE) + Line.VERTEX_INDEX_Y] = 0;
- bufferData[1 * Line.VERTEX_SIZE + Line.VERTEX_INDEX_X] = pLine.getX2() - pLine.getX1();
- bufferData[1 * Line.VERTEX_SIZE + Line.VERTEX_INDEX_Y] = pLine.getY2() - pLine.getY1();
+ bufferData[(1 * Line.VERTEX_SIZE) + Line.VERTEX_INDEX_X] = pLine.getX2() - pLine.getX1();
+ bufferData[(1 * Line.VERTEX_SIZE) + Line.VERTEX_INDEX_Y] = pLine.getY2() - pLine.getY1();
this.setDirtyOnHardware();
}
diff --git a/src/org/andengine/entity/primitive/vbo/HighPerformanceMeshVertexBufferObject.java b/src/org/andengine/entity/primitive/vbo/HighPerformanceMeshVertexBufferObject.java
index ae75f2761..183f88842 100644
--- a/src/org/andengine/entity/primitive/vbo/HighPerformanceMeshVertexBufferObject.java
+++ b/src/org/andengine/entity/primitive/vbo/HighPerformanceMeshVertexBufferObject.java
@@ -7,7 +7,7 @@
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:46:51 - 28.03.2012
@@ -47,7 +47,7 @@ public void onUpdateColor(final Mesh pMesh) {
final float packedColor = pMesh.getColor().getABGRPackedFloat();
- for(int i = 0; i < this.mVertexCount; i++) {
+ for (int i = 0; i < this.mVertexCount; i++) {
bufferData[(i * Mesh.VERTEX_SIZE) + Mesh.COLOR_INDEX] = packedColor;
}
diff --git a/src/org/andengine/entity/primitive/vbo/HighPerformanceRectangleVertexBufferObject.java b/src/org/andengine/entity/primitive/vbo/HighPerformanceRectangleVertexBufferObject.java
index e1b79c40a..a8836f492 100644
--- a/src/org/andengine/entity/primitive/vbo/HighPerformanceRectangleVertexBufferObject.java
+++ b/src/org/andengine/entity/primitive/vbo/HighPerformanceRectangleVertexBufferObject.java
@@ -7,7 +7,7 @@
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:48:14 - 28.03.2012
@@ -43,10 +43,10 @@ public void onUpdateColor(final Rectangle pRectangle) {
final float packedColor = pRectangle.getColor().getABGRPackedFloat();
- bufferData[0 * Rectangle.VERTEX_SIZE + Rectangle.COLOR_INDEX] = packedColor;
- bufferData[1 * Rectangle.VERTEX_SIZE + Rectangle.COLOR_INDEX] = packedColor;
- bufferData[2 * Rectangle.VERTEX_SIZE + Rectangle.COLOR_INDEX] = packedColor;
- bufferData[3 * Rectangle.VERTEX_SIZE + Rectangle.COLOR_INDEX] = packedColor;
+ bufferData[(0 * Rectangle.VERTEX_SIZE) + Rectangle.COLOR_INDEX] = packedColor;
+ bufferData[(1 * Rectangle.VERTEX_SIZE) + Rectangle.COLOR_INDEX] = packedColor;
+ bufferData[(2 * Rectangle.VERTEX_SIZE) + Rectangle.COLOR_INDEX] = packedColor;
+ bufferData[(3 * Rectangle.VERTEX_SIZE) + Rectangle.COLOR_INDEX] = packedColor;
this.setDirtyOnHardware();
}
@@ -55,22 +55,20 @@ public void onUpdateColor(final Rectangle pRectangle) {
public void onUpdateVertices(final Rectangle pRectangle) {
final float[] bufferData = this.mBufferData;
- final float x = 0;
- final float y = 0;
- final float x2 = pRectangle.getWidth(); // TODO Optimize with field access?
- final float y2 = pRectangle.getHeight(); // TODO Optimize with field access?
+ final float width = pRectangle.getWidth(); // TODO Optimize with field access?
+ final float height = pRectangle.getHeight(); // TODO Optimize with field access?
- bufferData[0 * Rectangle.VERTEX_SIZE + Rectangle.VERTEX_INDEX_X] = x;
- bufferData[0 * Rectangle.VERTEX_SIZE + Rectangle.VERTEX_INDEX_Y] = y;
+ bufferData[(0 * Rectangle.VERTEX_SIZE) + Rectangle.VERTEX_INDEX_X] = 0;
+ bufferData[(0 * Rectangle.VERTEX_SIZE) + Rectangle.VERTEX_INDEX_Y] = 0;
- bufferData[1 * Rectangle.VERTEX_SIZE + Rectangle.VERTEX_INDEX_X] = x;
- bufferData[1 * Rectangle.VERTEX_SIZE + Rectangle.VERTEX_INDEX_Y] = y2;
+ bufferData[(1 * Rectangle.VERTEX_SIZE) + Rectangle.VERTEX_INDEX_X] = 0;
+ bufferData[(1 * Rectangle.VERTEX_SIZE) + Rectangle.VERTEX_INDEX_Y] = height;
- bufferData[2 * Rectangle.VERTEX_SIZE + Rectangle.VERTEX_INDEX_X] = x2;
- bufferData[2 * Rectangle.VERTEX_SIZE + Rectangle.VERTEX_INDEX_Y] = y;
+ bufferData[(2 * Rectangle.VERTEX_SIZE) + Rectangle.VERTEX_INDEX_X] = width;
+ bufferData[(2 * Rectangle.VERTEX_SIZE) + Rectangle.VERTEX_INDEX_Y] = 0;
- bufferData[3 * Rectangle.VERTEX_SIZE + Rectangle.VERTEX_INDEX_X] = x2;
- bufferData[3 * Rectangle.VERTEX_SIZE + Rectangle.VERTEX_INDEX_Y] = y2;
+ bufferData[(3 * Rectangle.VERTEX_SIZE) + Rectangle.VERTEX_INDEX_X] = width;
+ bufferData[(3 * Rectangle.VERTEX_SIZE) + Rectangle.VERTEX_INDEX_Y] = height;
this.setDirtyOnHardware();
}
diff --git a/src/org/andengine/entity/primitive/vbo/IGradientVertexBufferObject.java b/src/org/andengine/entity/primitive/vbo/IGradientVertexBufferObject.java
new file mode 100644
index 000000000..9af59158d
--- /dev/null
+++ b/src/org/andengine/entity/primitive/vbo/IGradientVertexBufferObject.java
@@ -0,0 +1,23 @@
+package org.andengine.entity.primitive.vbo;
+
+import org.andengine.entity.primitive.Gradient;
+import org.andengine.opengl.vbo.IVertexBufferObject;
+
+/**
+ * (c) 2012 Zynga Inc.
+ *
+ * @author Nicolas Gramlich
+ * @since 14:27:22 - 23.04.2012
+ */
+public interface IGradientVertexBufferObject extends IVertexBufferObject {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ public void onUpdateColor(final Gradient pGradient);
+ public void onUpdateVertices(final Gradient pGradient);
+}
\ No newline at end of file
diff --git a/src/org/andengine/entity/primitive/vbo/ILineChainVertexBufferObject.java b/src/org/andengine/entity/primitive/vbo/ILineChainVertexBufferObject.java
new file mode 100644
index 000000000..e517b20e5
--- /dev/null
+++ b/src/org/andengine/entity/primitive/vbo/ILineChainVertexBufferObject.java
@@ -0,0 +1,23 @@
+package org.andengine.entity.primitive.vbo;
+
+import org.andengine.entity.primitive.LineChain;
+import org.andengine.opengl.vbo.IVertexBufferObject;
+
+/**
+ * (c) 2013 Nicolas Gramlich
+ *
+ * @author Nicolas Gramlich
+ * @since 21:49:01 - 30.05.2013
+ */
+public interface ILineChainVertexBufferObject extends IVertexBufferObject {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ public void onUpdateColor(final LineChain pLineChain);
+ public void onUpdateVertices(final LineChain pLineChain);
+}
\ No newline at end of file
diff --git a/src/org/andengine/entity/primitive/vbo/ILineVertexBufferObject.java b/src/org/andengine/entity/primitive/vbo/ILineVertexBufferObject.java
index 07c572285..e179c8ecf 100644
--- a/src/org/andengine/entity/primitive/vbo/ILineVertexBufferObject.java
+++ b/src/org/andengine/entity/primitive/vbo/ILineVertexBufferObject.java
@@ -4,7 +4,7 @@
import org.andengine.opengl.vbo.IVertexBufferObject;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:45:00 - 28.03.2012
diff --git a/src/org/andengine/entity/primitive/vbo/IMeshVertexBufferObject.java b/src/org/andengine/entity/primitive/vbo/IMeshVertexBufferObject.java
index 0e0ec2fe9..fa6223316 100644
--- a/src/org/andengine/entity/primitive/vbo/IMeshVertexBufferObject.java
+++ b/src/org/andengine/entity/primitive/vbo/IMeshVertexBufferObject.java
@@ -4,7 +4,7 @@
import org.andengine.opengl.vbo.IVertexBufferObject;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:46:51 - 28.03.2012
diff --git a/src/org/andengine/entity/primitive/vbo/IRectangleVertexBufferObject.java b/src/org/andengine/entity/primitive/vbo/IRectangleVertexBufferObject.java
index 017a845ef..dde390ec1 100644
--- a/src/org/andengine/entity/primitive/vbo/IRectangleVertexBufferObject.java
+++ b/src/org/andengine/entity/primitive/vbo/IRectangleVertexBufferObject.java
@@ -4,7 +4,7 @@
import org.andengine.opengl.vbo.IVertexBufferObject;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:48:14 - 28.03.2012
diff --git a/src/org/andengine/entity/primitive/vbo/LowMemoryGradientVertexBufferObject.java b/src/org/andengine/entity/primitive/vbo/LowMemoryGradientVertexBufferObject.java
new file mode 100644
index 000000000..4fcd6cc5c
--- /dev/null
+++ b/src/org/andengine/entity/primitive/vbo/LowMemoryGradientVertexBufferObject.java
@@ -0,0 +1,131 @@
+package org.andengine.entity.primitive.vbo;
+
+import java.nio.FloatBuffer;
+
+import org.andengine.entity.primitive.Gradient;
+import org.andengine.opengl.vbo.DrawType;
+import org.andengine.opengl.vbo.LowMemoryVertexBufferObject;
+import org.andengine.opengl.vbo.VertexBufferObjectManager;
+import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
+import org.andengine.util.adt.color.ColorUtils;
+import org.andengine.util.math.MathConstants;
+import org.andengine.util.math.MathUtils;
+
+/**
+ * (c) 2012 Zynga Inc.
+ *
+ * @author Nicolas Gramlich
+ * @since 14:27:33 - 23.04.2012
+ */
+public class LowMemoryGradientVertexBufferObject extends LowMemoryVertexBufferObject implements IGradientVertexBufferObject {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ public LowMemoryGradientVertexBufferObject(final VertexBufferObjectManager pVertexBufferObjectManager, final int pCapacity, final DrawType pDrawType, final boolean pAutoDispose, final VertexBufferObjectAttributes pVertexBufferObjectAttributes) {
+ super(pVertexBufferObjectManager, pCapacity, pDrawType, pAutoDispose, pVertexBufferObjectAttributes);
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ @Override
+ public void onUpdateColor(final Gradient pGradient) {
+ final FloatBuffer bufferData = this.mFloatBuffer;
+
+ final float gradientVectorX = pGradient.getGradientVectorX();
+ final float gradientVectorY = pGradient.getGradientVectorY();
+
+ final float length = MathUtils.length(gradientVectorX, gradientVectorY);
+ if (length == 0) {
+ return;
+ }
+
+ float dX = gradientVectorX / length;
+ float dY = gradientVectorY / length;
+
+ final float c = MathConstants.SQRT_2;
+ final float c2 = 2 * c;
+
+ if (pGradient.isGradientFitToBounds()) {
+ final float tmp = 1 / (Math.abs(dX) + Math.abs(dY));
+ dX *= tmp * c;
+ dY *= tmp * c;
+ }
+
+ final float fromRed = pGradient.getFromRed();
+ final float fromGreen = pGradient.getFromGreen();
+ final float fromBlue = pGradient.getFromBlue();
+ final float fromAlpha = pGradient.getFromAlpha(); // TODO * 'this.mOverallOpactity'
+
+ final float toRed = pGradient.getToRed();
+ final float toGreen = pGradient.getToGreen();
+ final float toBlue = pGradient.getToBlue();
+ final float toAlpha = pGradient.getToAlpha(); // TODO * 'this.mOverallOpactity'
+
+ /* Pre-fetch some calculations. */
+ final float dRed = fromRed - toRed;
+ final float dGreen = fromGreen - toGreen;
+ final float dBlue = fromBlue - toBlue;
+ final float dAlpha = fromAlpha - toAlpha;
+
+
+ final float v0 = (c + dX + dY) / c2;
+ bufferData.put((0 * Gradient.VERTEX_SIZE) + Gradient.COLOR_INDEX, ColorUtils.convertRGBAToABGRPackedFloat(toRed + (dRed * v0), toGreen + (dGreen * v0), toBlue + (dBlue * v0), toAlpha + (dAlpha * v0)));
+
+ final float v1 = (c + dX - dY) / c2;
+ bufferData.put((1 * Gradient.VERTEX_SIZE) + Gradient.COLOR_INDEX, ColorUtils.convertRGBAToABGRPackedFloat(toRed + (dRed * v1), toGreen + (dGreen * v1), toBlue + (dBlue * v1), toAlpha + (dAlpha * v1)));
+
+ final float v2 = (c - dX + dY) / c2;
+ bufferData.put((2 * Gradient.VERTEX_SIZE) + Gradient.COLOR_INDEX, ColorUtils.convertRGBAToABGRPackedFloat(toRed + (dRed * v2), toGreen + (dGreen * v2), toBlue + (dBlue * v2), toAlpha + (dAlpha * v2)));
+
+ final float v3 = (c - dX - dY) / c2;
+ bufferData.put((3 * Gradient.VERTEX_SIZE) + Gradient.COLOR_INDEX, ColorUtils.convertRGBAToABGRPackedFloat(toRed + (dRed * v3), toGreen + (dGreen * v3), toBlue + (dBlue * v3), toAlpha + (dAlpha * v3)));
+
+
+ this.setDirtyOnHardware();
+ }
+
+ @Override
+ public void onUpdateVertices(final Gradient pGradient) {
+ final FloatBuffer bufferData = this.mFloatBuffer;
+
+ final float width = pGradient.getWidth(); // TODO Optimize with field access?
+ final float height = pGradient.getHeight(); // TODO Optimize with field access?
+
+ bufferData.put((0 * Gradient.VERTEX_SIZE) + Gradient.VERTEX_INDEX_X, 0);
+ bufferData.put((0 * Gradient.VERTEX_SIZE) + Gradient.VERTEX_INDEX_Y, 0);
+
+ bufferData.put((1 * Gradient.VERTEX_SIZE) + Gradient.VERTEX_INDEX_X, 0);
+ bufferData.put((1 * Gradient.VERTEX_SIZE) + Gradient.VERTEX_INDEX_Y, height);
+
+ bufferData.put((2 * Gradient.VERTEX_SIZE) + Gradient.VERTEX_INDEX_X, width);
+ bufferData.put((2 * Gradient.VERTEX_SIZE) + Gradient.VERTEX_INDEX_Y, 0);
+
+ bufferData.put((3 * Gradient.VERTEX_SIZE) + Gradient.VERTEX_INDEX_X, width);
+ bufferData.put((3 * Gradient.VERTEX_SIZE) + Gradient.VERTEX_INDEX_Y, height);
+
+ this.setDirtyOnHardware();
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
\ No newline at end of file
diff --git a/src/org/andengine/entity/primitive/vbo/LowMemoryLineChainVertexBufferObject.java b/src/org/andengine/entity/primitive/vbo/LowMemoryLineChainVertexBufferObject.java
new file mode 100644
index 000000000..0c93882a3
--- /dev/null
+++ b/src/org/andengine/entity/primitive/vbo/LowMemoryLineChainVertexBufferObject.java
@@ -0,0 +1,80 @@
+package org.andengine.entity.primitive.vbo;
+
+import java.nio.FloatBuffer;
+
+import org.andengine.entity.primitive.LineChain;
+import org.andengine.opengl.vbo.DrawType;
+import org.andengine.opengl.vbo.LowMemoryVertexBufferObject;
+import org.andengine.opengl.vbo.VertexBufferObjectManager;
+import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
+
+/**
+ * (c) 2013 Nicolas Gramlich
+ *
+ * @author Nicolas Gramlich
+ * @since 21:50:00 - 30.05.2013
+ */
+public class LowMemoryLineChainVertexBufferObject extends LowMemoryVertexBufferObject implements ILineChainVertexBufferObject {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ public LowMemoryLineChainVertexBufferObject(final VertexBufferObjectManager pVertexBufferObjectManager, final int pCapacity, final DrawType pDrawType, final boolean pAutoDispose, final VertexBufferObjectAttributes pVertexBufferObjectAttributes) {
+ super(pVertexBufferObjectManager, pCapacity, pDrawType, pAutoDispose, pVertexBufferObjectAttributes);
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ @Override
+ public void onUpdateColor(final LineChain pLineChain) {
+ final FloatBuffer bufferData = this.mFloatBuffer;
+
+ final float packedColor = pLineChain.getColor().getABGRPackedFloat();
+
+ for (int i = pLineChain.getCapacity() - 1; i >= 0; i--) {
+ bufferData.put((i * LineChain.VERTEX_SIZE) + LineChain.COLOR_INDEX, packedColor);
+ }
+
+ this.setDirtyOnHardware();
+ }
+
+ @Override
+ public void onUpdateVertices(final LineChain pLineChain) {
+ final FloatBuffer bufferData = this.mFloatBuffer;
+
+ bufferData.put((0 * LineChain.VERTEX_SIZE) + LineChain.VERTEX_INDEX_X, 0);
+ bufferData.put((0 * LineChain.VERTEX_SIZE) + LineChain.VERTEX_INDEX_Y, 0);
+
+ final float x = pLineChain.getX();
+ final float y = pLineChain.getY();
+
+ for (int i = pLineChain.getCapacity() - 1; i >= 0; i--) {
+ bufferData.put((i * LineChain.VERTEX_SIZE) + LineChain.VERTEX_INDEX_X, pLineChain.getX(i) - x);
+ bufferData.put((i * LineChain.VERTEX_SIZE) + LineChain.VERTEX_INDEX_Y, pLineChain.getY(i) - y);
+ }
+
+ this.setDirtyOnHardware();
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
\ No newline at end of file
diff --git a/src/org/andengine/entity/primitive/vbo/LowMemoryLineVertexBufferObject.java b/src/org/andengine/entity/primitive/vbo/LowMemoryLineVertexBufferObject.java
index 42da35b4c..8b7c4db36 100644
--- a/src/org/andengine/entity/primitive/vbo/LowMemoryLineVertexBufferObject.java
+++ b/src/org/andengine/entity/primitive/vbo/LowMemoryLineVertexBufferObject.java
@@ -9,7 +9,7 @@
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:45:00 - 28.03.2012
@@ -45,8 +45,8 @@ public void onUpdateColor(final Line pLine) {
final float packedColor = pLine.getColor().getABGRPackedFloat();
- bufferData.put(0 * Line.VERTEX_SIZE + Line.COLOR_INDEX, packedColor);
- bufferData.put(1 * Line.VERTEX_SIZE + Line.COLOR_INDEX, packedColor);
+ bufferData.put((0 * Line.VERTEX_SIZE) + Line.COLOR_INDEX, packedColor);
+ bufferData.put((1 * Line.VERTEX_SIZE) + Line.COLOR_INDEX, packedColor);
this.setDirtyOnHardware();
}
@@ -55,11 +55,11 @@ public void onUpdateColor(final Line pLine) {
public void onUpdateVertices(final Line pLine) {
final FloatBuffer bufferData = this.mFloatBuffer;
- bufferData.put(0 * Line.VERTEX_SIZE + Line.VERTEX_INDEX_X, 0);
- bufferData.put(0 * Line.VERTEX_SIZE + Line.VERTEX_INDEX_Y, 0);
+ bufferData.put((0 * Line.VERTEX_SIZE) + Line.VERTEX_INDEX_X, 0);
+ bufferData.put((0 * Line.VERTEX_SIZE) + Line.VERTEX_INDEX_Y, 0);
- bufferData.put(1 * Line.VERTEX_SIZE + Line.VERTEX_INDEX_X, pLine.getX2() - pLine.getX1()); // TODO Optimize with field access?
- bufferData.put(1 * Line.VERTEX_SIZE + Line.VERTEX_INDEX_Y, pLine.getY2() - pLine.getY1()); // TODO Optimize with field access?
+ bufferData.put((1 * Line.VERTEX_SIZE) + Line.VERTEX_INDEX_X, pLine.getX2() - pLine.getX1()); // TODO Optimize with field access?
+ bufferData.put((1 * Line.VERTEX_SIZE) + Line.VERTEX_INDEX_Y, pLine.getY2() - pLine.getY1()); // TODO Optimize with field access?
this.setDirtyOnHardware();
}
diff --git a/src/org/andengine/entity/primitive/vbo/LowMemoryRectangleVertexBufferObject.java b/src/org/andengine/entity/primitive/vbo/LowMemoryRectangleVertexBufferObject.java
index 798d1a774..0226c8a2a 100644
--- a/src/org/andengine/entity/primitive/vbo/LowMemoryRectangleVertexBufferObject.java
+++ b/src/org/andengine/entity/primitive/vbo/LowMemoryRectangleVertexBufferObject.java
@@ -9,7 +9,7 @@
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:48:14 - 28.03.2012
@@ -45,10 +45,10 @@ public void onUpdateColor(final Rectangle pRectangle) {
final float packedColor = pRectangle.getColor().getABGRPackedFloat();
- bufferData.put(0 * Rectangle.VERTEX_SIZE + Rectangle.COLOR_INDEX, packedColor);
- bufferData.put(1 * Rectangle.VERTEX_SIZE + Rectangle.COLOR_INDEX, packedColor);
- bufferData.put(2 * Rectangle.VERTEX_SIZE + Rectangle.COLOR_INDEX, packedColor);
- bufferData.put(3 * Rectangle.VERTEX_SIZE + Rectangle.COLOR_INDEX, packedColor);
+ bufferData.put((0 * Rectangle.VERTEX_SIZE) + Rectangle.COLOR_INDEX, packedColor);
+ bufferData.put((1 * Rectangle.VERTEX_SIZE) + Rectangle.COLOR_INDEX, packedColor);
+ bufferData.put((2 * Rectangle.VERTEX_SIZE) + Rectangle.COLOR_INDEX, packedColor);
+ bufferData.put((3 * Rectangle.VERTEX_SIZE) + Rectangle.COLOR_INDEX, packedColor);
this.setDirtyOnHardware();
}
@@ -57,22 +57,20 @@ public void onUpdateColor(final Rectangle pRectangle) {
public void onUpdateVertices(final Rectangle pRectangle) {
final FloatBuffer bufferData = this.mFloatBuffer;
- final float x = 0;
- final float y = 0;
- final float x2 = pRectangle.getWidth();
- final float y2 = pRectangle.getHeight();
+ final float width = pRectangle.getWidth(); // TODO Optimize with field access?
+ final float height = pRectangle.getHeight(); // TODO Optimize with field access?
- bufferData.put(0 * Rectangle.VERTEX_SIZE + Rectangle.VERTEX_INDEX_X, x);
- bufferData.put(0 * Rectangle.VERTEX_SIZE + Rectangle.VERTEX_INDEX_Y, y);
+ bufferData.put((0 * Rectangle.VERTEX_SIZE) + Rectangle.VERTEX_INDEX_X, 0);
+ bufferData.put((0 * Rectangle.VERTEX_SIZE) + Rectangle.VERTEX_INDEX_Y, 0);
- bufferData.put(1 * Rectangle.VERTEX_SIZE + Rectangle.VERTEX_INDEX_X, x);
- bufferData.put(1 * Rectangle.VERTEX_SIZE + Rectangle.VERTEX_INDEX_Y, y2);
+ bufferData.put((1 * Rectangle.VERTEX_SIZE) + Rectangle.VERTEX_INDEX_X, 0);
+ bufferData.put((1 * Rectangle.VERTEX_SIZE) + Rectangle.VERTEX_INDEX_Y, height);
- bufferData.put(2 * Rectangle.VERTEX_SIZE + Rectangle.VERTEX_INDEX_X, x2);
- bufferData.put(2 * Rectangle.VERTEX_SIZE + Rectangle.VERTEX_INDEX_Y, y);
+ bufferData.put((2 * Rectangle.VERTEX_SIZE) + Rectangle.VERTEX_INDEX_X, width);
+ bufferData.put((2 * Rectangle.VERTEX_SIZE) + Rectangle.VERTEX_INDEX_Y, 0);
- bufferData.put(3 * Rectangle.VERTEX_SIZE + Rectangle.VERTEX_INDEX_X, x2);
- bufferData.put(3 * Rectangle.VERTEX_SIZE + Rectangle.VERTEX_INDEX_Y, y2);
+ bufferData.put((3 * Rectangle.VERTEX_SIZE) + Rectangle.VERTEX_INDEX_X, width);
+ bufferData.put((3 * Rectangle.VERTEX_SIZE) + Rectangle.VERTEX_INDEX_Y, height);
this.setDirtyOnHardware();
}
diff --git a/src/org/andengine/entity/scene/CameraScene.java b/src/org/andengine/entity/scene/CameraScene.java
index eef5adc5a..64ff3b38c 100644
--- a/src/org/andengine/entity/scene/CameraScene.java
+++ b/src/org/andengine/entity/scene/CameraScene.java
@@ -1,14 +1,15 @@
package org.andengine.entity.scene;
import org.andengine.engine.camera.Camera;
-import org.andengine.entity.shape.IAreaShape;
+import org.andengine.entity.IEntity;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.util.GLState;
+import org.andengine.util.exception.MethodNotSupportedException;
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:35:53 - 29.03.2010
*/
@@ -28,7 +29,7 @@ public class CameraScene extends Scene {
// ===========================================================
/**
- * {@link CameraScene#setCamera(Camera)} needs to be called manually. Otherwise nothing will be drawn.
+ * {@link #setCamera(Camera)} needs to be called manually. Otherwise nothing will be drawn.
*/
public CameraScene() {
this(null);
@@ -50,23 +51,48 @@ public void setCamera(final Camera pCamera) {
this.mCamera = pCamera;
}
+ @Override
+ public float getWidth() {
+ return this.mCamera.getCameraSceneWidth();
+ }
+
+ @Override
+ public float getHeight() {
+ return this.mCamera.getCameraSceneHeight();
+ }
+
+ @Override
+ public void setWidth(final float pWidth) {
+ throw new MethodNotSupportedException();
+ }
+
+ @Override
+ public void setHeight(final float pHeight) {
+ throw new MethodNotSupportedException();
+ }
+
+ @Override
+ public void setSize(final float pWidth, final float pHeight) {
+ throw new MethodNotSupportedException();
+ }
+
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public boolean onSceneTouchEvent(final TouchEvent pSceneTouchEvent) {
- if(this.mCamera == null) {
+ if (this.mCamera == null) {
return false;
} else {
- this.mCamera.convertSceneToCameraSceneTouchEvent(pSceneTouchEvent);
+ this.mCamera.convertSceneTouchEventToCameraSceneTouchEvent(pSceneTouchEvent);
final boolean handled = super.onSceneTouchEvent(pSceneTouchEvent);
- if(handled) {
+ if (handled) {
return true;
} else {
- this.mCamera.convertCameraSceneToSceneTouchEvent(pSceneTouchEvent);
+ this.mCamera.convertCameraSceneTouchEventToSceneTouchEvent(pSceneTouchEvent);
return false;
}
}
@@ -75,10 +101,10 @@ public boolean onSceneTouchEvent(final TouchEvent pSceneTouchEvent) {
@Override
protected boolean onChildSceneTouchEvent(final TouchEvent pSceneTouchEvent) {
final boolean childIsCameraScene = this.mChildScene instanceof CameraScene;
- if(childIsCameraScene) {
- this.mCamera.convertCameraSceneToSceneTouchEvent(pSceneTouchEvent);
+ if (childIsCameraScene) {
+ this.mCamera.convertCameraSceneTouchEventToSceneTouchEvent(pSceneTouchEvent);
final boolean result = super.onChildSceneTouchEvent(pSceneTouchEvent);
- this.mCamera.convertSceneToCameraSceneTouchEvent(pSceneTouchEvent);
+ this.mCamera.convertSceneTouchEventToCameraSceneTouchEvent(pSceneTouchEvent);
return result;
} else {
return super.onChildSceneTouchEvent(pSceneTouchEvent);
@@ -94,17 +120,16 @@ protected void onApplyMatrix(final GLState pGLState, final Camera pCamera) {
// Methods
// ===========================================================
- public void centerShapeInCamera(final IAreaShape pAreaShape) {
- final Camera camera = this.mCamera;
- pAreaShape.setPosition((camera.getWidth() - pAreaShape.getWidth()) * 0.5f, (camera.getHeight() - pAreaShape.getHeight()) * 0.5f);
+ public void centerEntityInCamera(final IEntity pEntity) {
+ pEntity.setPosition(this.mCamera.getCenterX(), this.mCamera.getCenterY());
}
- public void centerShapeInCameraHorizontally(final IAreaShape pAreaShape) {
- pAreaShape.setPosition((this.mCamera.getWidth() - pAreaShape.getWidth()) * 0.5f, pAreaShape.getY());
+ public void centerEntityInCameraHorizontally(final IEntity pEntity) {
+ pEntity.setX(this.mCamera.getCenterX());
}
- public void centerShapeInCameraVertically(final IAreaShape pAreaShape) {
- pAreaShape.setPosition(pAreaShape.getX(), (this.mCamera.getHeight() - pAreaShape.getHeight()) * 0.5f);
+ public void centerEntityInCameraVertically(final IEntity pEntity) {
+ pEntity.setY(this.mCamera.getCenterY());
}
// ===========================================================
diff --git a/src/org/andengine/entity/scene/IOnAreaTouchListener.java b/src/org/andengine/entity/scene/IOnAreaTouchListener.java
index 58da60934..c9c6e99b8 100644
--- a/src/org/andengine/entity/scene/IOnAreaTouchListener.java
+++ b/src/org/andengine/entity/scene/IOnAreaTouchListener.java
@@ -7,7 +7,7 @@
* dispatched to an {@link ITouchArea} area. The callback will be invoked
* before the {@link TouchEvent} is passed to the {@link ITouchArea}.
*
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 15:01:48 PM - 27.03.2012
@@ -24,12 +24,12 @@ public interface IOnAreaTouchListener {
/**
* Called when a {@link TouchEvent} is dispatched to an {@link ITouchArea}. This allows
* listeners to get a chance to respond before the target {@link ITouchArea#onAreaTouched(TouchEvent, float, float)} is called.
- *
+ *
* @param pTouchArea The {@link ITouchArea} that the {@link TouchEvent} has been dispatched to.
* @param pSceneTouchEvent The {@link TouchEvent} object containing full information about the event.
* @param pTouchAreaLocalX the x coordinate within the area touched.
* @param pTouchAreaLocalY the y coordinate within the area touched.
- *
+ *
* @return true if this {@link IOnAreaTouchListener} has consumed the {@link TouchEvent}, false otherwise.
*/
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final ITouchArea pTouchArea, final float pTouchAreaLocalX, final float pTouchAreaLocalY);
diff --git a/src/org/andengine/entity/scene/IOnSceneTouchListener.java b/src/org/andengine/entity/scene/IOnSceneTouchListener.java
index ed99f5718..8e1a10702 100644
--- a/src/org/andengine/entity/scene/IOnSceneTouchListener.java
+++ b/src/org/andengine/entity/scene/IOnSceneTouchListener.java
@@ -7,7 +7,7 @@
* dispatched to a {@link Scene}. The callback will be invoked
* after all {@link ITouchArea}s have been checked and none consumed the {@link TouchEvent}.
*
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 15:02:20 - 27.03.2012
@@ -23,10 +23,10 @@ public interface IOnSceneTouchListener {
/**
* Called when a {@link TouchEvent} is dispatched to a {@link Scene}.
- *
+ *
* @param pScene The {@link Scene} that the {@link TouchEvent} has been dispatched to.
* @param pSceneTouchEvent The {@link TouchEvent} object containing full information about the event.
- *
+ *
* @return true if this {@link IOnSceneTouchListener} has consumed the {@link TouchEvent}, false otherwise.
*/
public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent);
diff --git a/src/org/andengine/entity/scene/ITouchArea.java b/src/org/andengine/entity/scene/ITouchArea.java
index cc577f63b..474b7cb8a 100644
--- a/src/org/andengine/entity/scene/ITouchArea.java
+++ b/src/org/andengine/entity/scene/ITouchArea.java
@@ -4,7 +4,7 @@
import org.andengine.util.IMatcher;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 15:01:18 - 27.03.2012
@@ -20,8 +20,8 @@ public interface ITouchArea {
public boolean contains(final float pX, final float pY);
- public float[] convertSceneToLocalCoordinates(final float pX, final float pY);
- public float[] convertLocalToSceneCoordinates(final float pX, final float pY);
+ public float[] convertSceneCoordinatesToLocalCoordinates(final float pX, final float pY);
+ public float[] convertLocalCoordinatesToSceneCoordinates(final float pX, final float pY);
/**
* This method only fires if this {@link ITouchArea} is registered to the {@link Scene} via {@link Scene#registerTouchArea(ITouchArea)}.
diff --git a/src/org/andengine/entity/scene/Scene.java b/src/org/andengine/entity/scene/Scene.java
index f05966ea2..df8594c69 100644
--- a/src/org/andengine/entity/scene/Scene.java
+++ b/src/org/andengine/entity/scene/Scene.java
@@ -4,7 +4,6 @@
import org.andengine.engine.handler.runnable.RunnableHandler;
import org.andengine.entity.Entity;
import org.andengine.entity.IEntity;
-import org.andengine.entity.scene.ITouchArea.ITouchAreaMatcher;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.scene.background.IBackground;
import org.andengine.entity.shape.IShape;
@@ -12,15 +11,15 @@
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.util.GLState;
import org.andengine.util.Constants;
+import org.andengine.util.adt.color.Color;
import org.andengine.util.adt.list.SmartList;
-import org.andengine.util.color.Color;
import android.util.SparseArray;
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 12:47:39 - 08.03.2010
*/
@@ -72,7 +71,7 @@ public Scene() {
@Deprecated
public Scene(final int pChildCount) {
- for(int i = 0; i < pChildCount; i++) {
+ for (int i = 0; i < pChildCount; i++) {
this.attachChild(new Entity());
}
}
@@ -98,7 +97,7 @@ public boolean isBackgroundEnabled() {
}
public void setBackgroundEnabled(final boolean pEnabled) {
- this.mBackgroundEnabled = pEnabled;
+ this.mBackgroundEnabled = pEnabled;
}
public void setOnSceneTouchListener(final IOnSceneTouchListener pOnSceneTouchListener) {
@@ -181,11 +180,11 @@ public boolean isTouchAreaBindingOnActionMoveEnabled() {
* with {@link TouchEvent#ACTION_DOWN}, they will receive all subsequent {@link TouchEvent}s
* that are made with the same PointerID (finger)
* even if the {@link TouchEvent} is outside of the actual {@link ITouchArea}!
- *
+ *
* @param pTouchAreaBindingOnActionDownEnabled
*/
public void setTouchAreaBindingOnActionDownEnabled(final boolean pTouchAreaBindingOnActionDownEnabled) {
- if(this.mTouchAreaBindingOnActionDownEnabled && !pTouchAreaBindingOnActionDownEnabled) {
+ if (this.mTouchAreaBindingOnActionDownEnabled && !pTouchAreaBindingOnActionDownEnabled) {
this.mTouchAreaBindings.clear();
}
this.mTouchAreaBindingOnActionDownEnabled = pTouchAreaBindingOnActionDownEnabled;
@@ -199,11 +198,11 @@ public void setTouchAreaBindingOnActionDownEnabled(final boolean pTouchAreaBindi
* with {@link TouchEvent#ACTION_MOVE}, they will receive all subsequent {@link TouchEvent}s
* that are made with the same PointerID (finger)
* even if the {@link TouchEvent} is outside of the actual {@link ITouchArea}!
- *
+ *
* @param pTouchAreaBindingOnActionMoveEnabled
*/
public void setTouchAreaBindingOnActionMoveEnabled(final boolean pTouchAreaBindingOnActionMoveEnabled) {
- if(this.mTouchAreaBindingOnActionMoveEnabled && !pTouchAreaBindingOnActionMoveEnabled) {
+ if (this.mTouchAreaBindingOnActionMoveEnabled && !pTouchAreaBindingOnActionMoveEnabled) {
this.mTouchAreaBindings.clear();
}
this.mTouchAreaBindingOnActionMoveEnabled = pTouchAreaBindingOnActionMoveEnabled;
@@ -221,11 +220,11 @@ public boolean isOnSceneTouchListenerBindingOnActionDownEnabled() {
* with {@link TouchEvent#ACTION_DOWN}, it will receive all subsequent {@link TouchEvent}s
* that are made with the same PointerID (finger)
* even if the {@link TouchEvent} is would belong to an overlaying {@link ITouchArea}!
- *
+ *
* @param pOnSceneTouchListenerBindingOnActionDownEnabled
*/
public void setOnSceneTouchListenerBindingOnActionDownEnabled(final boolean pOnSceneTouchListenerBindingOnActionDownEnabled) {
- if(this.mOnSceneTouchListenerBindingOnActionDownEnabled && !pOnSceneTouchListenerBindingOnActionDownEnabled) {
+ if (this.mOnSceneTouchListenerBindingOnActionDownEnabled && !pOnSceneTouchListenerBindingOnActionDownEnabled) {
this.mOnSceneTouchListenerBindings.clear();
}
this.mOnSceneTouchListenerBindingOnActionDownEnabled = pOnSceneTouchListenerBindingOnActionDownEnabled;
@@ -239,8 +238,8 @@ public void setOnSceneTouchListenerBindingOnActionDownEnabled(final boolean pOnS
protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
final Scene childScene = this.mChildScene;
- if(childScene == null || !this.mChildSceneModalDraw) {
- if(this.mBackgroundEnabled) {
+ if (childScene == null || !this.mChildSceneModalDraw) {
+ if (this.mBackgroundEnabled) {
pGLState.pushProjectionGLMatrix();
pCamera.onApplySceneBackgroundMatrix(pGLState);
@@ -263,7 +262,7 @@ protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
}
}
- if(childScene != null) {
+ if (childScene != null) {
childScene.onDraw(pGLState, pCamera);
}
}
@@ -279,12 +278,12 @@ protected void onManagedUpdate(final float pSecondsElapsed) {
this.mRunnableHandler.onUpdate(pSecondsElapsed);
final Scene childScene = this.mChildScene;
- if(childScene == null || !this.mChildSceneModalUpdate) {
+ if (childScene == null || !this.mChildSceneModalUpdate) {
this.mBackground.onUpdate(pSecondsElapsed);
super.onManagedUpdate(pSecondsElapsed);
}
- if(childScene != null) {
+ if (childScene != null) {
childScene.onUpdate(pSecondsElapsed);
}
}
@@ -294,39 +293,39 @@ public boolean onSceneTouchEvent(final TouchEvent pSceneTouchEvent) {
final boolean isActionDown = pSceneTouchEvent.isActionDown();
final boolean isActionMove = pSceneTouchEvent.isActionMove();
- if(!isActionDown) {
- if(this.mOnSceneTouchListenerBindingOnActionDownEnabled) {
+ if (!isActionDown) {
+ if (this.mOnSceneTouchListenerBindingOnActionDownEnabled) {
final IOnSceneTouchListener boundOnSceneTouchListener = this.mOnSceneTouchListenerBindings.get(pSceneTouchEvent.getPointerID());
if (boundOnSceneTouchListener != null) {
/* Check if boundTouchArea needs to be removed. */
- switch(action) {
+ switch (action) {
case TouchEvent.ACTION_UP:
case TouchEvent.ACTION_CANCEL:
this.mOnSceneTouchListenerBindings.remove(pSceneTouchEvent.getPointerID());
}
final Boolean handled = this.mOnSceneTouchListener.onSceneTouchEvent(this, pSceneTouchEvent);
- if(handled != null && handled) {
+ if (handled != null && handled) {
return true;
}
}
}
- if(this.mTouchAreaBindingOnActionDownEnabled) {
+ if (this.mTouchAreaBindingOnActionDownEnabled) {
final SparseArray touchAreaBindings = this.mTouchAreaBindings;
final ITouchArea boundTouchArea = touchAreaBindings.get(pSceneTouchEvent.getPointerID());
/* In the case a ITouchArea has been bound to this PointerID,
* we'll pass this this TouchEvent to the same ITouchArea. */
- if(boundTouchArea != null) {
+ if (boundTouchArea != null) {
final float sceneTouchEventX = pSceneTouchEvent.getX();
final float sceneTouchEventY = pSceneTouchEvent.getY();
/* Check if boundTouchArea needs to be removed. */
- switch(action) {
+ switch (action) {
case TouchEvent.ACTION_UP:
case TouchEvent.ACTION_CANCEL:
touchAreaBindings.remove(pSceneTouchEvent.getPointerID());
}
final Boolean handled = this.onAreaTouchEvent(pSceneTouchEvent, sceneTouchEventX, sceneTouchEventY, boundTouchArea);
- if(handled != null && handled) {
+ if (handled != null && handled) {
return true;
}
}
@@ -334,11 +333,11 @@ public boolean onSceneTouchEvent(final TouchEvent pSceneTouchEvent) {
}
final Scene childScene = this.mChildScene;
- if(childScene != null) {
+ if (childScene != null) {
final boolean handledByChild = this.onChildSceneTouchEvent(pSceneTouchEvent);
- if(handledByChild) {
+ if (handledByChild) {
return true;
- } else if(this.mChildSceneModalTouch) {
+ } else if (this.mChildSceneModalTouch) {
return false;
}
}
@@ -347,18 +346,18 @@ public boolean onSceneTouchEvent(final TouchEvent pSceneTouchEvent) {
final float sceneTouchEventY = pSceneTouchEvent.getY();
final SmartList touchAreas = this.mTouchAreas;
- if(touchAreas != null) {
+ if (touchAreas != null) {
final int touchAreaCount = touchAreas.size();
- if(touchAreaCount > 0) {
- if(this.mOnAreaTouchTraversalBackToFront) { /* Back to Front. */
- for(int i = 0; i < touchAreaCount; i++) {
+ if (touchAreaCount > 0) {
+ if (this.mOnAreaTouchTraversalBackToFront) { /* Back to Front. */
+ for (int i = 0; i < touchAreaCount; i++) {
final ITouchArea touchArea = touchAreas.get(i);
- if(touchArea.contains(sceneTouchEventX, sceneTouchEventY)) {
+ if (touchArea.contains(sceneTouchEventX, sceneTouchEventY)) {
final Boolean handled = this.onAreaTouchEvent(pSceneTouchEvent, sceneTouchEventX, sceneTouchEventY, touchArea);
- if(handled != null && handled) {
+ if (handled != null && handled) {
/* If binding of ITouchAreas is enabled and this is an ACTION_DOWN event,
- * bind this ITouchArea to the PointerID. */
- if((this.mTouchAreaBindingOnActionDownEnabled && isActionDown) || (this.mTouchAreaBindingOnActionMoveEnabled && isActionMove)) {
+ * bind this ITouchArea to the PointerID. */
+ if ((this.mTouchAreaBindingOnActionDownEnabled && isActionDown) || (this.mTouchAreaBindingOnActionMoveEnabled && isActionMove)) {
this.mTouchAreaBindings.put(pSceneTouchEvent.getPointerID(), touchArea);
}
return true;
@@ -366,14 +365,14 @@ public boolean onSceneTouchEvent(final TouchEvent pSceneTouchEvent) {
}
}
} else { /* Front to back. */
- for(int i = touchAreaCount - 1; i >= 0; i--) {
+ for (int i = touchAreaCount - 1; i >= 0; i--) {
final ITouchArea touchArea = touchAreas.get(i);
- if(touchArea.contains(sceneTouchEventX, sceneTouchEventY)) {
+ if (touchArea.contains(sceneTouchEventX, sceneTouchEventY)) {
final Boolean handled = this.onAreaTouchEvent(pSceneTouchEvent, sceneTouchEventX, sceneTouchEventY, touchArea);
- if(handled != null && handled) {
+ if (handled != null && handled) {
/* If binding of ITouchAreas is enabled and this is an ACTION_DOWN event,
- * bind this ITouchArea to the PointerID. */
- if((this.mTouchAreaBindingOnActionDownEnabled && isActionDown) || (this.mTouchAreaBindingOnActionMoveEnabled && isActionMove)) {
+ * bind this ITouchArea to the PointerID. */
+ if ((this.mTouchAreaBindingOnActionDownEnabled && isActionDown) || (this.mTouchAreaBindingOnActionMoveEnabled && isActionMove)) {
this.mTouchAreaBindings.put(pSceneTouchEvent.getPointerID(), touchArea);
}
return true;
@@ -384,12 +383,12 @@ public boolean onSceneTouchEvent(final TouchEvent pSceneTouchEvent) {
}
}
/* If no area was touched, the Scene itself was touched as a fallback. */
- if(this.mOnSceneTouchListener != null){
+ if (this.mOnSceneTouchListener != null) {
final Boolean handled = this.mOnSceneTouchListener.onSceneTouchEvent(this, pSceneTouchEvent);
- if(handled != null && handled) {
+ if (handled != null && handled) {
/* If binding of ITouchAreas is enabled and this is an ACTION_DOWN event,
- * bind the active OnSceneTouchListener to the PointerID. */
- if(this.mOnSceneTouchListenerBindingOnActionDownEnabled && isActionDown) {
+ * bind the active OnSceneTouchListener to the PointerID. */
+ if (this.mOnSceneTouchListenerBindingOnActionDownEnabled && isActionDown) {
this.mOnSceneTouchListenerBindings.put(pSceneTouchEvent.getPointerID(), this.mOnSceneTouchListener);
}
return true;
@@ -402,14 +401,14 @@ public boolean onSceneTouchEvent(final TouchEvent pSceneTouchEvent) {
}
private Boolean onAreaTouchEvent(final TouchEvent pSceneTouchEvent, final float sceneTouchEventX, final float sceneTouchEventY, final ITouchArea touchArea) {
- final float[] touchAreaLocalCoordinates = touchArea.convertSceneToLocalCoordinates(sceneTouchEventX, sceneTouchEventY);
+ final float[] touchAreaLocalCoordinates = touchArea.convertSceneCoordinatesToLocalCoordinates(sceneTouchEventX, sceneTouchEventY);
final float touchAreaLocalX = touchAreaLocalCoordinates[Constants.VERTEX_INDEX_X];
final float touchAreaLocalY = touchAreaLocalCoordinates[Constants.VERTEX_INDEX_Y];
final boolean handledSelf = touchArea.onAreaTouched(pSceneTouchEvent, touchAreaLocalX, touchAreaLocalY);
- if(handledSelf) {
+ if (handledSelf) {
return Boolean.TRUE;
- } else if(this.mOnAreaTouchListener != null) {
+ } else if (this.mOnAreaTouchListener != null) {
return this.mOnAreaTouchListener.onAreaTouched(pSceneTouchEvent, touchArea, touchAreaLocalX, touchAreaLocalY);
} else {
return null;
@@ -463,7 +462,7 @@ public SmartList getTouchAreas() {
public void back() {
this.clearChildScene();
- if(this.mParentScene != null) {
+ if (this.mParentScene != null) {
this.mParentScene.clearChildScene();
this.mParentScene = null;
}
diff --git a/src/org/andengine/entity/scene/background/AutoParallaxBackground.java b/src/org/andengine/entity/scene/background/AutoParallaxBackground.java
index b1a997864..745c49068 100644
--- a/src/org/andengine/entity/scene/background/AutoParallaxBackground.java
+++ b/src/org/andengine/entity/scene/background/AutoParallaxBackground.java
@@ -3,9 +3,9 @@
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 19:44:31 - 19.07.2010
*/
@@ -26,6 +26,7 @@ public class AutoParallaxBackground extends ParallaxBackground {
public AutoParallaxBackground(final float pRed, final float pGreen, final float pBlue, final float pParallaxChangePerSecond) {
super(pRed, pGreen, pBlue);
+
this.mParallaxChangePerSecond = pParallaxChangePerSecond;
}
diff --git a/src/org/andengine/entity/scene/background/Background.java b/src/org/andengine/entity/scene/background/Background.java
index b023ab919..7dfe93155 100644
--- a/src/org/andengine/entity/scene/background/Background.java
+++ b/src/org/andengine/entity/scene/background/Background.java
@@ -2,7 +2,7 @@
import org.andengine.engine.camera.Camera;
import org.andengine.opengl.util.GLState;
-import org.andengine.util.color.Color;
+import org.andengine.util.adt.color.Color;
import org.andengine.util.modifier.IModifier;
import org.andengine.util.modifier.ModifierList;
@@ -12,7 +12,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 14:08:17 - 19.07.2010
*/
@@ -27,7 +27,7 @@ public class Background implements IBackground {
// Fields
// ===========================================================
- private ModifierList mBackgroundModifiers = null;
+ private ModifierList mBackgroundModifiers;
private final Color mColor = new Color(0, 0, 0, 1);
private boolean mColorEnabled = true;
@@ -100,7 +100,7 @@ public void setColorEnabled(final boolean pColorEnabled) {
@Override
public void registerBackgroundModifier(final IModifier pBackgroundModifier) {
- if(this.mBackgroundModifiers == null) {
+ if (this.mBackgroundModifiers == null) {
this.allocateBackgroundModifiers();
}
this.mBackgroundModifiers.add(pBackgroundModifier);
@@ -108,7 +108,7 @@ public void registerBackgroundModifier(final IModifier pBackgroundM
@Override
public boolean unregisterBackgroundModifier(final IModifier pBackgroundModifier) {
- if(this.mBackgroundModifiers != null) {
+ if (this.mBackgroundModifiers != null) {
return this.mBackgroundModifiers.remove(pBackgroundModifier);
} else {
return false;
@@ -117,21 +117,21 @@ public boolean unregisterBackgroundModifier(final IModifier pBackgr
@Override
public void clearBackgroundModifiers() {
- if(this.mBackgroundModifiers != null) {
+ if (this.mBackgroundModifiers != null) {
this.mBackgroundModifiers.clear();
}
}
@Override
public void onUpdate(final float pSecondsElapsed) {
- if(this.mBackgroundModifiers != null) {
+ if (this.mBackgroundModifiers != null) {
this.mBackgroundModifiers.onUpdate(pSecondsElapsed);
}
}
@Override
public void onDraw(final GLState pGLState, final Camera pCamera) {
- if(this.mColorEnabled) {
+ if (this.mColorEnabled) {
GLES20.glClearColor(this.mColor.getRed(), this.mColor.getGreen(), this.mColor.getBlue(), this.mColor.getAlpha());
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); // TODO Does this cause problems when multisampling?
}
diff --git a/src/org/andengine/entity/scene/background/EntityBackground.java b/src/org/andengine/entity/scene/background/EntityBackground.java
index 9cba6efa3..dd7c942bb 100644
--- a/src/org/andengine/entity/scene/background/EntityBackground.java
+++ b/src/org/andengine/entity/scene/background/EntityBackground.java
@@ -5,9 +5,9 @@
import org.andengine.opengl.util.GLState;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 18:25:10 - 21.07.2010
*/
diff --git a/src/org/andengine/entity/scene/background/IBackground.java b/src/org/andengine/entity/scene/background/IBackground.java
index bce15fd9b..9f7a83137 100644
--- a/src/org/andengine/entity/scene/background/IBackground.java
+++ b/src/org/andengine/entity/scene/background/IBackground.java
@@ -2,13 +2,13 @@
import org.andengine.engine.handler.IDrawHandler;
import org.andengine.engine.handler.IUpdateHandler;
-import org.andengine.util.color.Color;
+import org.andengine.util.adt.color.Color;
import org.andengine.util.modifier.IModifier;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 13:47:41 - 19.07.2010
*/
diff --git a/src/org/andengine/entity/scene/background/ParallaxBackground.java b/src/org/andengine/entity/scene/background/ParallaxBackground.java
index 22bb53979..c3f0dc14c 100644
--- a/src/org/andengine/entity/scene/background/ParallaxBackground.java
+++ b/src/org/andengine/entity/scene/background/ParallaxBackground.java
@@ -3,13 +3,14 @@
import java.util.ArrayList;
import org.andengine.engine.camera.Camera;
-import org.andengine.entity.shape.IAreaShape;
+import org.andengine.entity.IEntity;
import org.andengine.opengl.util.GLState;
+import org.andengine.util.debug.Debug;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:36:26 - 19.07.2010
*/
@@ -54,7 +55,7 @@ public void onDraw(final GLState pGLState, final Camera pCamera) {
final float parallaxValue = this.mParallaxValue;
final ArrayList parallaxEntities = this.mParallaxEntities;
- for(int i = 0; i < this.mParallaxEntityCount; i++) {
+ for (int i = 0; i < this.mParallaxEntityCount; i++) {
parallaxEntities.get(i).onDraw(pGLState, pCamera, parallaxValue);
}
}
@@ -71,7 +72,7 @@ public void attachParallaxEntity(final ParallaxEntity pParallaxEntity) {
public boolean detachParallaxEntity(final ParallaxEntity pParallaxEntity) {
this.mParallaxEntityCount--;
final boolean success = this.mParallaxEntities.remove(pParallaxEntity);
- if(!success) {
+ if (!success) {
this.mParallaxEntityCount++;
}
return success;
@@ -91,15 +92,24 @@ public static class ParallaxEntity {
// ===========================================================
final float mParallaxFactor;
- final IAreaShape mAreaShape;
+ final IEntity mEntity;
// ===========================================================
// Constructors
// ===========================================================
- public ParallaxEntity(final float pParallaxFactor, final IAreaShape pAreaShape) {
+ public ParallaxEntity(final float pParallaxFactor, final IEntity pEntity) {
this.mParallaxFactor = pParallaxFactor;
- this.mAreaShape = pAreaShape;
+ this.mEntity = pEntity;
+
+ // TODO Adjust onDraw calculations, so that these assumptions aren't necessary.
+ if (this.mEntity.getX() != 0) {
+ Debug.w("The X position of a " + this.getClass().getSimpleName() + " is expected to be 0.");
+ }
+
+ if (this.mEntity.getOffsetCenterX() != 0) {
+ Debug.w("The OffsetCenterXposition of a " + this.getClass().getSimpleName() + " is expected to be 0.");
+ }
}
// ===========================================================
@@ -118,21 +128,21 @@ public void onDraw(final GLState pGLState, final Camera pCamera, final float pPa
pGLState.pushModelViewGLMatrix();
{
final float cameraWidth = pCamera.getWidth();
- final float shapeWidthScaled = this.mAreaShape.getWidthScaled();
- float baseOffset = (pParallaxValue * this.mParallaxFactor) % shapeWidthScaled;
+ final float entityWidthScaled = this.mEntity.getWidth() * this.mEntity.getScaleX();
+ float baseOffset = (pParallaxValue * this.mParallaxFactor) % entityWidthScaled;
- while(baseOffset > 0) {
- baseOffset -= shapeWidthScaled;
+ while (baseOffset > 0) {
+ baseOffset -= entityWidthScaled;
}
pGLState.translateModelViewGLMatrixf(baseOffset, 0, 0);
float currentMaxX = baseOffset;
-
+
do {
- this.mAreaShape.onDraw(pGLState, pCamera);
- pGLState.translateModelViewGLMatrixf(shapeWidthScaled, 0, 0);
- currentMaxX += shapeWidthScaled;
- } while(currentMaxX < cameraWidth);
+ this.mEntity.onDraw(pGLState, pCamera);
+ pGLState.translateModelViewGLMatrixf(entityWidthScaled, 0, 0);
+ currentMaxX += entityWidthScaled;
+ } while (currentMaxX < cameraWidth);
}
pGLState.popModelViewGLMatrix();
}
diff --git a/src/org/andengine/entity/scene/background/RepeatingSpriteBackground.java b/src/org/andengine/entity/scene/background/RepeatingSpriteBackground.java
index 7aef2106f..319abc4c0 100644
--- a/src/org/andengine/entity/scene/background/RepeatingSpriteBackground.java
+++ b/src/org/andengine/entity/scene/background/RepeatingSpriteBackground.java
@@ -1,19 +1,13 @@
package org.andengine.entity.scene.background;
import org.andengine.entity.sprite.Sprite;
-import org.andengine.opengl.texture.TextureManager;
-import org.andengine.opengl.texture.TextureOptions;
-import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
-import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
-import org.andengine.opengl.texture.atlas.bitmap.source.IBitmapTextureAtlasSource;
-import org.andengine.opengl.texture.bitmap.BitmapTextureFormat;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:11:10 - 19.07.2010
*/
@@ -22,42 +16,28 @@ public class RepeatingSpriteBackground extends SpriteBackground {
// Constants
// ===========================================================
+ private static final float SCALE_DEFAULT = 1;
+
// ===========================================================
// Fields
// ===========================================================
- private BitmapTextureAtlas mBitmapTextureAtlas;
- private final float mScale;
-
// ===========================================================
// Constructors
// ===========================================================
- /**
- * @param pCameraWidth
- * @param pCameraHeight
- * @param pTextureManager
- * @param pBitmapTextureAtlasSource needs to be a power of two as otherwise the repeating feature doesn't work.
- */
- public RepeatingSpriteBackground(final float pCameraWidth, final float pCameraHeight, final TextureManager pTextureManager, final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final VertexBufferObjectManager pVertexBufferObjectManager) throws IllegalArgumentException {
- this(pCameraWidth, pCameraHeight, pTextureManager, pBitmapTextureAtlasSource, 1, pVertexBufferObjectManager);
+ public RepeatingSpriteBackground(final float pCameraWidth, final float pCameraHeight, final ITextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager) throws IllegalArgumentException {
+ this(pCameraWidth, pCameraHeight, pTextureRegion, SCALE_DEFAULT, pVertexBufferObjectManager);
}
- public RepeatingSpriteBackground(final float pCameraWidth, final float pCameraHeight, final TextureManager pTextureManager, final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final float pScale, final VertexBufferObjectManager pVertexBufferObjectManager) throws IllegalArgumentException {
- super(null);
-
- this.mScale = pScale;
- this.mEntity = this.loadSprite(pCameraWidth, pCameraHeight, pTextureManager, pBitmapTextureAtlasSource, pVertexBufferObjectManager);
+ public RepeatingSpriteBackground(final float pCameraWidth, final float pCameraHeight, final ITextureRegion pTextureRegion, final float pScale, final VertexBufferObjectManager pVertexBufferObjectManager) throws IllegalArgumentException {
+ super(RepeatingSpriteBackground.createSprite(pCameraWidth, pCameraHeight, pTextureRegion, pScale, pVertexBufferObjectManager));
}
// ===========================================================
// Getter & Setter
// ===========================================================
- public BitmapTextureAtlas getBitmapTextureAtlas() {
- return this.mBitmapTextureAtlas;
- }
-
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@@ -66,22 +46,13 @@ public BitmapTextureAtlas getBitmapTextureAtlas() {
// Methods
// ===========================================================
- private Sprite loadSprite(final float pCameraWidth, final float pCameraHeight, final TextureManager pTextureManager, final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final VertexBufferObjectManager pVertexBufferObjectManager) throws IllegalArgumentException {
- this.mBitmapTextureAtlas = new BitmapTextureAtlas(pTextureManager, pBitmapTextureAtlasSource.getTextureWidth(), pBitmapTextureAtlasSource.getTextureHeight(), BitmapTextureFormat.RGBA_8888, TextureOptions.REPEATING_NEAREST);
- final ITextureRegion textureRegion = BitmapTextureAtlasTextureRegionFactory.createFromSource(this.mBitmapTextureAtlas, pBitmapTextureAtlasSource, 0, 0);
-
- final int width = Math.round(pCameraWidth / this.mScale);
- final int height = Math.round(pCameraHeight / this.mScale);
-
- textureRegion.setTextureWidth(width);
- textureRegion.setTextureHeight(height);
+ private static Sprite createSprite(final float pCameraWidth, final float pCameraHeight, final ITextureRegion pTextureRegion, final float pScale, final VertexBufferObjectManager pVertexBufferObjectManager) throws IllegalArgumentException {
+ final int width = Math.round(pCameraWidth / pScale);
+ final int height = Math.round(pCameraHeight / pScale);
- this.mBitmapTextureAtlas.load();
+ pTextureRegion.setTextureSize(width, height);
- final Sprite sprite = new Sprite(0, 0, width, height, textureRegion, pVertexBufferObjectManager);
- sprite.setScaleCenter(0, 0);
- sprite.setScale(this.mScale);
- return sprite;
+ return new Sprite(pCameraWidth * 0.5f, pCameraHeight * 0.5f, width * pScale, height * pScale, pTextureRegion, pVertexBufferObjectManager);
}
// ===========================================================
diff --git a/src/org/andengine/entity/scene/background/SpriteBackground.java b/src/org/andengine/entity/scene/background/SpriteBackground.java
index 0661aaa39..9a752e67b 100644
--- a/src/org/andengine/entity/scene/background/SpriteBackground.java
+++ b/src/org/andengine/entity/scene/background/SpriteBackground.java
@@ -3,9 +3,9 @@
import org.andengine.entity.sprite.Sprite;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 14:01:43 - 19.07.2010
*/
@@ -33,11 +33,11 @@ public SpriteBackground(final float pRed, final float pGreen, final float pBlue,
// ===========================================================
// Getter & Setter
// ===========================================================
-
+
public Sprite getSprite() {
- return (Sprite)this.mEntity;
+ return (Sprite) this.mEntity;
}
-
+
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
diff --git a/src/org/andengine/entity/scene/background/modifier/ColorBackgroundModifier.java b/src/org/andengine/entity/scene/background/modifier/ColorBackgroundModifier.java
index d59c046ef..5f8106994 100644
--- a/src/org/andengine/entity/scene/background/modifier/ColorBackgroundModifier.java
+++ b/src/org/andengine/entity/scene/background/modifier/ColorBackgroundModifier.java
@@ -1,7 +1,7 @@
package org.andengine.entity.scene.background.modifier;
import org.andengine.entity.scene.background.IBackground;
-import org.andengine.util.color.Color;
+import org.andengine.util.adt.color.Color;
import org.andengine.util.modifier.BaseTripleValueSpanModifier;
import org.andengine.util.modifier.ease.EaseLinear;
import org.andengine.util.modifier.ease.IEaseFunction;
@@ -9,7 +9,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 14:51:03 - 03.09.2010
*/
@@ -63,7 +63,7 @@ protected ColorBackgroundModifier(final ColorBackgroundModifier pColorBackground
}
@Override
- public ColorBackgroundModifier deepCopy(){
+ public ColorBackgroundModifier deepCopy() {
return new ColorBackgroundModifier(this);
}
diff --git a/src/org/andengine/entity/scene/background/modifier/IBackgroundModifier.java b/src/org/andengine/entity/scene/background/modifier/IBackgroundModifier.java
index 35accdb31..eecd46d6a 100644
--- a/src/org/andengine/entity/scene/background/modifier/IBackgroundModifier.java
+++ b/src/org/andengine/entity/scene/background/modifier/IBackgroundModifier.java
@@ -4,9 +4,9 @@
import org.andengine.util.modifier.IModifier;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 14:55:54 - 03.09.2010
*/
@@ -26,7 +26,7 @@ public interface IBackgroundModifier extends IModifier {
// Inner and Anonymous Classes
// ===========================================================
- public static interface IBackgroundModifierListener extends IModifierListener{
+ public static interface IBackgroundModifierListener extends IModifierListener {
// ===========================================================
// Constants
// ===========================================================
diff --git a/src/org/andengine/entity/scene/background/modifier/LoopBackgroundModifier.java b/src/org/andengine/entity/scene/background/modifier/LoopBackgroundModifier.java
index ab080d2b8..0932a868d 100644
--- a/src/org/andengine/entity/scene/background/modifier/LoopBackgroundModifier.java
+++ b/src/org/andengine/entity/scene/background/modifier/LoopBackgroundModifier.java
@@ -4,9 +4,9 @@
import org.andengine.util.modifier.LoopModifier;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:03:53 - 03.09.2010
*/
@@ -32,7 +32,7 @@ public LoopBackgroundModifier(final IBackgroundModifier pBackgroundModifier, fin
}
public LoopBackgroundModifier(final IBackgroundModifier pBackgroundModifier, final int pLoopCount, final ILoopBackgroundModifierListener pLoopModifierListener) {
- super(pBackgroundModifier, pLoopCount, pLoopModifierListener, (IBackgroundModifierListener)null);
+ super(pBackgroundModifier, pLoopCount, pLoopModifierListener, (IBackgroundModifierListener) null);
}
public LoopBackgroundModifier(final IBackgroundModifier pBackgroundModifier, final int pLoopCount, final IBackgroundModifierListener pBackgroundModifierListener) {
diff --git a/src/org/andengine/entity/scene/background/modifier/ParallelBackgroundModifier.java b/src/org/andengine/entity/scene/background/modifier/ParallelBackgroundModifier.java
index f5179dc73..c0713c44d 100644
--- a/src/org/andengine/entity/scene/background/modifier/ParallelBackgroundModifier.java
+++ b/src/org/andengine/entity/scene/background/modifier/ParallelBackgroundModifier.java
@@ -4,9 +4,9 @@
import org.andengine.util.modifier.ParallelModifier;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:03:57 - 03.09.2010
*/
diff --git a/src/org/andengine/entity/scene/background/modifier/SequenceBackgroundModifier.java b/src/org/andengine/entity/scene/background/modifier/SequenceBackgroundModifier.java
index 16b6107ac..f9a6006b4 100644
--- a/src/org/andengine/entity/scene/background/modifier/SequenceBackgroundModifier.java
+++ b/src/org/andengine/entity/scene/background/modifier/SequenceBackgroundModifier.java
@@ -4,9 +4,9 @@
import org.andengine.util.modifier.SequenceModifier;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:04:02 - 03.09.2010
*/
@@ -26,7 +26,7 @@ public class SequenceBackgroundModifier extends SequenceModifier im
public SequenceBackgroundModifier(final IBackgroundModifier... pBackgroundModifiers) throws IllegalArgumentException {
super(pBackgroundModifiers);
}
-
+
public SequenceBackgroundModifier(final ISubSequenceBackgroundModifierListener pSubSequenceBackgroundModifierListener, final IBackgroundModifier... pBackgroundModifiers) throws IllegalArgumentException {
super(pSubSequenceBackgroundModifierListener, pBackgroundModifiers);
}
diff --git a/src/org/andengine/entity/scene/menu/MenuScene.java b/src/org/andengine/entity/scene/menu/MenuScene.java
index 7de51199a..e13102658 100644
--- a/src/org/andengine/entity/scene/menu/MenuScene.java
+++ b/src/org/andengine/entity/scene/menu/MenuScene.java
@@ -8,16 +8,17 @@
import org.andengine.entity.scene.IOnSceneTouchListener;
import org.andengine.entity.scene.ITouchArea;
import org.andengine.entity.scene.Scene;
-import org.andengine.entity.scene.menu.animator.IMenuAnimator;
+import org.andengine.entity.scene.menu.animator.IMenuSceneAnimator;
+import org.andengine.entity.scene.menu.animator.InstantMenuSceneAnimator;
import org.andengine.entity.scene.menu.item.IMenuItem;
import org.andengine.input.touch.TouchEvent;
import android.view.MotionEvent;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 20:06:51 - 01.04.2010
*/
@@ -30,11 +31,11 @@ public class MenuScene extends CameraScene implements IOnAreaTouchListener, IOnS
// Fields
// ===========================================================
- private final ArrayList mMenuItems = new ArrayList();
+ protected final ArrayList mMenuItems = new ArrayList();
private IOnMenuItemClickListener mOnMenuItemClickListener;
- private IMenuAnimator mMenuAnimator = IMenuAnimator.DEFAULT;
+ private IMenuSceneAnimator mMenuSceneAnimator;
private IMenuItem mSelectedMenuItem;
@@ -42,20 +43,22 @@ public class MenuScene extends CameraScene implements IOnAreaTouchListener, IOnS
// Constructors
// ===========================================================
- public MenuScene() {
- this(null, null);
+ public MenuScene(final Camera pCamera) {
+ this(pCamera, new InstantMenuSceneAnimator());
}
- public MenuScene(final IOnMenuItemClickListener pOnMenuItemClickListener) {
- this(null, pOnMenuItemClickListener);
+ public MenuScene(final Camera pCamera, final IMenuSceneAnimator pMenuSceneAnimator) {
+ this(pCamera, pMenuSceneAnimator, null);
}
- public MenuScene(final Camera pCamera) {
- this(pCamera, null);
+ public MenuScene(final Camera pCamera, final IOnMenuItemClickListener pOnMenuItemClickListener) {
+ this(pCamera, new InstantMenuSceneAnimator(), pOnMenuItemClickListener);
}
- public MenuScene(final Camera pCamera, final IOnMenuItemClickListener pOnMenuItemClickListener) {
+ public MenuScene(final Camera pCamera, final IMenuSceneAnimator pMenuSceneAnimator, final IOnMenuItemClickListener pOnMenuItemClickListener) {
super(pCamera);
+
+ this.mMenuSceneAnimator = pMenuSceneAnimator;
this.mOnMenuItemClickListener = pOnMenuItemClickListener;
this.setOnSceneTouchListener(this);
this.setOnAreaTouchListener(this);
@@ -73,6 +76,14 @@ public void setOnMenuItemClickListener(final IOnMenuItemClickListener pOnMenuIte
this.mOnMenuItemClickListener = pOnMenuItemClickListener;
}
+ public ArrayList getMenuItems() {
+ return this.mMenuItems;
+ }
+
+ public IMenuItem getMenuItem(final int pIndex) {
+ return this.mMenuItems.get(pIndex);
+ }
+
public int getMenuItemCount() {
return this.mMenuItems.size();
}
@@ -83,6 +94,14 @@ public void addMenuItem(final IMenuItem pMenuItem) {
this.registerTouchArea(pMenuItem);
}
+ public void clearMenuItems() {
+ for (int i = this.mMenuItems.size() - 1; i >= 0; i--) {
+ final IMenuItem menuItem = this.mMenuItems.remove(i);
+ this.detachChild(menuItem);
+ this.unregisterTouchArea(menuItem);
+ }
+ }
+
@Override
public MenuScene getChildScene() {
return (MenuScene)super.getChildScene();
@@ -90,23 +109,27 @@ public MenuScene getChildScene() {
@Override
public void setChildScene(final Scene pChildScene, final boolean pModalDraw, final boolean pModalUpdate, final boolean pModalTouch) throws IllegalArgumentException {
- if(pChildScene instanceof MenuScene) {
+ if (pChildScene instanceof MenuScene) {
super.setChildScene(pChildScene, pModalDraw, pModalUpdate, pModalTouch);
} else {
- throw new IllegalArgumentException("MenuScene accepts only MenuScenes as a ChildScene.");
+ throw new IllegalArgumentException("A " + MenuScene.class.getSimpleName() + " accepts only " + MenuScene.class.getSimpleName() + " as a ChildScene.");
}
}
@Override
public void clearChildScene() {
- if(this.getChildScene() != null) {
+ if (this.getChildScene() != null) {
this.getChildScene().reset();
super.clearChildScene();
}
}
- public void setMenuAnimator(final IMenuAnimator pMenuAnimator) {
- this.mMenuAnimator = pMenuAnimator;
+ public IMenuSceneAnimator getMenuSceneAnimator() {
+ return this.mMenuSceneAnimator;
+ }
+
+ public void setMenuSceneAnimator(final IMenuSceneAnimator pMenuSceneAnimator) {
+ this.mMenuSceneAnimator = pMenuSceneAnimator;
}
// ===========================================================
@@ -117,17 +140,17 @@ public void setMenuAnimator(final IMenuAnimator pMenuAnimator) {
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final ITouchArea pTouchArea, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
final IMenuItem menuItem = ((IMenuItem)pTouchArea);
- switch(pSceneTouchEvent.getAction()) {
+ switch (pSceneTouchEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
- if(this.mSelectedMenuItem != null && this.mSelectedMenuItem != menuItem) {
+ if ((this.mSelectedMenuItem != null) && (this.mSelectedMenuItem != menuItem)) {
this.mSelectedMenuItem.onUnselected();
}
this.mSelectedMenuItem = menuItem;
this.mSelectedMenuItem.onSelected();
break;
case MotionEvent.ACTION_UP:
- if(this.mOnMenuItemClickListener != null) {
+ if (this.mOnMenuItemClickListener != null) {
final boolean handled = this.mOnMenuItemClickListener.onMenuItemClicked(this, menuItem, pTouchAreaLocalX, pTouchAreaLocalY);
menuItem.onUnselected();
this.mSelectedMenuItem = null;
@@ -144,7 +167,7 @@ public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final ITouchArea
@Override
public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {
- if(this.mSelectedMenuItem != null) {
+ if (this.mSelectedMenuItem != null) {
this.mSelectedMenuItem.onUnselected();
this.mSelectedMenuItem = null;
}
@@ -153,21 +176,25 @@ public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouc
@Override
public void back() {
- super.back();
+ this.back(true, true);
+ }
- this.reset();
+ public void back(final boolean pResetAnimations) {
+ this.back(pResetAnimations, true);
}
- @Override
- public void reset() {
- super.reset();
+ public void back(final boolean pResetAnimations, final boolean pResetParentMenuSceneAnimations) {
+ super.back();
- final ArrayList menuItems = this.mMenuItems;
- for(int i = menuItems.size() - 1; i >= 0; i--) {
- menuItems.get(i).reset();
+ if (pResetAnimations) {
+ this.resetAnimations();
}
- this.prepareAnimations();
+ if (pResetParentMenuSceneAnimations) {
+ if ((this.mParentScene != null) && (this.mParentScene instanceof MenuScene)) {
+ ((MenuScene)this.mParentScene).resetAnimations();
+ }
+ }
}
// ===========================================================
@@ -179,17 +206,11 @@ public void closeMenuScene() {
}
public void buildAnimations() {
- this.prepareAnimations();
-
- final float cameraWidthRaw = this.mCamera.getWidthRaw();
- final float cameraHeightRaw = this.mCamera.getHeightRaw();
- this.mMenuAnimator.buildAnimations(this.mMenuItems, cameraWidthRaw, cameraHeightRaw);
+ this.mMenuSceneAnimator.buildMenuSceneAnimations(this);
}
- public void prepareAnimations() {
- final float cameraWidthRaw = this.mCamera.getWidthRaw();
- final float cameraHeightRaw = this.mCamera.getHeightRaw();
- this.mMenuAnimator.prepareAnimations(this.mMenuItems, cameraWidthRaw, cameraHeightRaw);
+ public void resetAnimations() {
+ this.mMenuSceneAnimator.resetMenuSceneAnimations(this);
}
// ===========================================================
diff --git a/src/org/andengine/entity/scene/menu/animator/AlphaMenuAnimator.java b/src/org/andengine/entity/scene/menu/animator/AlphaMenuAnimator.java
deleted file mode 100644
index 01d1bcc63..000000000
--- a/src/org/andengine/entity/scene/menu/animator/AlphaMenuAnimator.java
+++ /dev/null
@@ -1,127 +0,0 @@
-package org.andengine.entity.scene.menu.animator;
-
-import java.util.ArrayList;
-
-import org.andengine.entity.modifier.AlphaModifier;
-import org.andengine.entity.scene.menu.item.IMenuItem;
-import org.andengine.util.HorizontalAlign;
-import org.andengine.util.modifier.ease.IEaseFunction;
-
-/**
- * (c) 2010 Nicolas Gramlich
- * (c) 2011 Zynga Inc.
- *
- * @author Nicolas Gramlich
- * @since 11:04:35 - 02.04.2010
- */
-public class AlphaMenuAnimator extends BaseMenuAnimator {
- // ===========================================================
- // Constants
- // ===========================================================
-
- private static final float ALPHA_FROM = 0.0f;
- private static final float ALPHA_TO = 1.0f;
-
- // ===========================================================
- // Fields
- // ===========================================================
-
- // ===========================================================
- // Constructors
- // ===========================================================
-
- public AlphaMenuAnimator(){
- super();
- }
-
- public AlphaMenuAnimator(final IEaseFunction pEaseFunction) {
- super(pEaseFunction);
- }
-
- public AlphaMenuAnimator(final HorizontalAlign pHorizontalAlign) {
- super(pHorizontalAlign);
- }
-
- public AlphaMenuAnimator(final HorizontalAlign pHorizontalAlign, final IEaseFunction pEaseFunction) {
- super(pHorizontalAlign, pEaseFunction);
- }
-
- public AlphaMenuAnimator(final float pMenuItemSpacing) {
- super(pMenuItemSpacing);
- }
-
- public AlphaMenuAnimator(final float pMenuItemSpacing, final IEaseFunction pEaseFunction) {
- super(pMenuItemSpacing, pEaseFunction);
- }
-
- public AlphaMenuAnimator(final HorizontalAlign pHorizontalAlign, final float pMenuItemSpacing) {
- super(pHorizontalAlign, pMenuItemSpacing);
- }
-
- public AlphaMenuAnimator(final HorizontalAlign pHorizontalAlign, final float pMenuItemSpacing, final IEaseFunction pEaseFunction) {
- super(pHorizontalAlign, pMenuItemSpacing, pEaseFunction);
- }
-
- // ===========================================================
- // Getter & Setter
- // ===========================================================
-
- // ===========================================================
- // Methods for/from SuperClass/Interfaces
- // ===========================================================
-
- @Override
- public void buildAnimations(final ArrayList pMenuItems, final float pCameraWidth, final float pCameraHeight) {
- final IEaseFunction easeFunction = this.mEaseFunction;
- final int menuItemCount = pMenuItems.size();
- for(int i = menuItemCount - 1; i >= 0; i--) {
- final AlphaModifier alphaModifier = new AlphaModifier(DURATION, ALPHA_FROM, ALPHA_TO, easeFunction);
- alphaModifier.setAutoUnregisterWhenFinished(false);
- pMenuItems.get(i).registerEntityModifier(alphaModifier);
- }
- }
-
- @Override
- public void prepareAnimations(final ArrayList pMenuItems, final float pCameraWidth, final float pCameraHeight) {
- final float maximumWidth = this.getMaximumWidth(pMenuItems);
- final float overallHeight = this.getOverallHeight(pMenuItems);
-
- final float baseX = (pCameraWidth - maximumWidth) * 0.5f;
- final float baseY = (pCameraHeight - overallHeight) * 0.5f;
-
- final float menuItemSpacing = this.mMenuItemSpacing;
-
- float offsetY = 0;
- final int menuItemCount = pMenuItems.size();
- for(int i = 0; i < menuItemCount; i++) {
- final IMenuItem menuItem = pMenuItems.get(i);
-
- final float offsetX;
- switch(this.mHorizontalAlign) {
- case LEFT:
- offsetX = 0;
- break;
- case RIGHT:
- offsetX = maximumWidth - menuItem.getWidthScaled();
- break;
- case CENTER:
- default:
- offsetX = (maximumWidth - menuItem.getWidthScaled()) * 0.5f;
- break;
- }
- menuItem.setPosition(baseX + offsetX , baseY + offsetY);
-
- menuItem.setAlpha(ALPHA_FROM);
-
- offsetY += menuItem.getHeight() + menuItemSpacing;
- }
- }
-
- // ===========================================================
- // Methods
- // ===========================================================
-
- // ===========================================================
- // Inner and Anonymous Classes
- // ===========================================================
-}
diff --git a/src/org/andengine/entity/scene/menu/animator/AlphaMenuSceneAnimator.java b/src/org/andengine/entity/scene/menu/animator/AlphaMenuSceneAnimator.java
new file mode 100644
index 000000000..55e05ce21
--- /dev/null
+++ b/src/org/andengine/entity/scene/menu/animator/AlphaMenuSceneAnimator.java
@@ -0,0 +1,99 @@
+package org.andengine.entity.scene.menu.animator;
+
+import org.andengine.entity.modifier.AlphaModifier;
+import org.andengine.entity.scene.menu.MenuScene;
+import org.andengine.entity.scene.menu.item.IMenuItem;
+import org.andengine.util.adt.align.HorizontalAlign;
+import org.andengine.util.adt.align.VerticalAlign;
+import org.andengine.util.modifier.ease.EaseLinear;
+import org.andengine.util.modifier.ease.IEaseFunction;
+
+/**
+ * (c) 2010 Nicolas Gramlich
+ * (c) 2011 Zynga Inc.
+ *
+ * @author Nicolas Gramlich
+ * @since 11:04:35 - 02.04.2010
+ */
+public class AlphaMenuSceneAnimator extends MenuSceneAnimator {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ private static final float DURATION = 1.0f;
+ private static final float ALPHA_FROM = 0.0f;
+ private static final float ALPHA_TO = 1.0f;
+
+ private static final IEaseFunction EASEFUNCTION_DEFAULT = EaseLinear.getInstance();
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ private IEaseFunction mEaseFunction;
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ public AlphaMenuSceneAnimator() {
+ this(AlphaMenuSceneAnimator.EASEFUNCTION_DEFAULT);
+ }
+
+ public AlphaMenuSceneAnimator(final IEaseFunction pEaseFunction) {
+ super();
+
+ this.mEaseFunction = pEaseFunction;
+ }
+
+ public AlphaMenuSceneAnimator(final HorizontalAlign pHorizontalAlign, final VerticalAlign pVerticalAlign) {
+ this(pHorizontalAlign, pVerticalAlign, AlphaMenuSceneAnimator.EASEFUNCTION_DEFAULT);
+ }
+
+ public AlphaMenuSceneAnimator(final HorizontalAlign pHorizontalAlign, final VerticalAlign pVerticalAlign, final IEaseFunction pEaseFunction) {
+ super(pHorizontalAlign, pVerticalAlign);
+
+ this.mEaseFunction = pEaseFunction;
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ public IEaseFunction getEaseFunction() {
+ return this.mEaseFunction;
+ }
+
+ public void setEaseFunction(final IEaseFunction pEaseFunction) {
+ this.mEaseFunction = pEaseFunction;
+ }
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ @Override
+ protected void onMenuItemPositionBuilt(final MenuScene pMenuScene, final int pIndex, final IMenuItem pMenuItem, final float pX, final float pY) {
+ pMenuItem.setPosition(pX, pY);
+
+ final AlphaModifier alphaModifier = new AlphaModifier(AlphaMenuSceneAnimator.DURATION, AlphaMenuSceneAnimator.ALPHA_FROM, AlphaMenuSceneAnimator.ALPHA_TO, this.mEaseFunction);
+ alphaModifier.setAutoUnregisterWhenFinished(false);
+ pMenuItem.registerEntityModifier(alphaModifier);
+ }
+
+ @Override
+ protected void onMenuItemPositionReset(final MenuScene pMenuScene, final int pIndex, final IMenuItem pMenuItem, final float pX, final float pY) {
+ pMenuItem.setPosition(pX, pY);
+
+ pMenuItem.resetEntityModifiers();
+ pMenuItem.setAlpha(AlphaMenuSceneAnimator.ALPHA_FROM);
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
diff --git a/src/org/andengine/entity/scene/menu/animator/BaseMenuAnimator.java b/src/org/andengine/entity/scene/menu/animator/BaseMenuAnimator.java
deleted file mode 100644
index 083a7c120..000000000
--- a/src/org/andengine/entity/scene/menu/animator/BaseMenuAnimator.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package org.andengine.entity.scene.menu.animator;
-
-import java.util.ArrayList;
-
-import org.andengine.entity.scene.menu.item.IMenuItem;
-import org.andengine.util.HorizontalAlign;
-import org.andengine.util.modifier.ease.EaseLinear;
-import org.andengine.util.modifier.ease.IEaseFunction;
-
-/**
- * (c) 2010 Nicolas Gramlich
- * (c) 2011 Zynga Inc.
- *
- * @author Nicolas Gramlich
- * @since 11:17:32 - 02.04.2010
- */
-public abstract class BaseMenuAnimator implements IMenuAnimator {
- // ===========================================================
- // Constants
- // ===========================================================
-
- protected static final float DURATION = 1.0f;
-
- private static final float MENUITEMSPACING_DEFAULT = 1.0f;
-
- private static final HorizontalAlign HORIZONTALALIGN_DEFAULT = HorizontalAlign.CENTER;
-
- // ===========================================================
- // Fields
- // ===========================================================
-
- protected final float mMenuItemSpacing;
- protected final HorizontalAlign mHorizontalAlign;
- protected final IEaseFunction mEaseFunction;
-
- // ===========================================================
- // Constructors
- // ===========================================================
-
- public BaseMenuAnimator() {
- this(MENUITEMSPACING_DEFAULT);
- }
-
- public BaseMenuAnimator(final IEaseFunction pEaseFunction) {
- this(MENUITEMSPACING_DEFAULT, pEaseFunction);
- }
-
- public BaseMenuAnimator(final float pMenuItemSpacing) {
- this(HORIZONTALALIGN_DEFAULT, pMenuItemSpacing);
- }
-
- public BaseMenuAnimator(final float pMenuItemSpacing, final IEaseFunction pEaseFunction) {
- this(HORIZONTALALIGN_DEFAULT, pMenuItemSpacing, pEaseFunction);
- }
-
- public BaseMenuAnimator(final HorizontalAlign pHorizontalAlign) {
- this(pHorizontalAlign, MENUITEMSPACING_DEFAULT);
- }
-
- public BaseMenuAnimator(final HorizontalAlign pHorizontalAlign, final IEaseFunction pEaseFunction) {
- this(pHorizontalAlign, MENUITEMSPACING_DEFAULT, pEaseFunction);
- }
-
- public BaseMenuAnimator(final HorizontalAlign pHorizontalAlign, final float pMenuItemSpacing) {
- this(pHorizontalAlign, pMenuItemSpacing, EaseLinear.getInstance());
- }
-
- public BaseMenuAnimator(final HorizontalAlign pHorizontalAlign, final float pMenuItemSpacing, final IEaseFunction pEaseFunction) {
- this.mHorizontalAlign = pHorizontalAlign;
- this.mMenuItemSpacing = pMenuItemSpacing;
- this.mEaseFunction = pEaseFunction;
- }
-
- // ===========================================================
- // Getter & Setter
- // ===========================================================
-
- protected float getMaximumWidth(final ArrayList pMenuItems) {
- float maximumWidth = Float.MIN_VALUE;
- for(int i = pMenuItems.size() - 1; i >= 0; i--) {
- final IMenuItem menuItem = pMenuItems.get(i);
- maximumWidth = Math.max(maximumWidth, menuItem.getWidthScaled());
- }
- return maximumWidth;
- }
-
- protected float getOverallHeight(final ArrayList pMenuItems) {
- float overallHeight = 0;
- for(int i = pMenuItems.size() - 1; i >= 0; i--) {
- final IMenuItem menuItem = pMenuItems.get(i);
- overallHeight += menuItem.getHeight();
- }
-
- overallHeight += (pMenuItems.size() - 1) * this.mMenuItemSpacing;
- return overallHeight;
- }
-
- // ===========================================================
- // Methods for/from SuperClass/Interfaces
- // ===========================================================
-
- // ===========================================================
- // Methods
- // ===========================================================
-
- // ===========================================================
- // Inner and Anonymous Classes
- // ===========================================================
-}
diff --git a/src/org/andengine/entity/scene/menu/animator/DirectMenuAnimator.java b/src/org/andengine/entity/scene/menu/animator/DirectMenuAnimator.java
deleted file mode 100644
index 7d0639292..000000000
--- a/src/org/andengine/entity/scene/menu/animator/DirectMenuAnimator.java
+++ /dev/null
@@ -1,98 +0,0 @@
-package org.andengine.entity.scene.menu.animator;
-
-import java.util.ArrayList;
-
-import org.andengine.entity.scene.menu.item.IMenuItem;
-import org.andengine.util.HorizontalAlign;
-
-/**
- * (c) 2010 Nicolas Gramlich
- * (c) 2011 Zynga Inc.
- *
- * @author Nicolas Gramlich
- * @since 10:46:34 - 14.05.2010
- */
-public class DirectMenuAnimator extends BaseMenuAnimator {
- // ===========================================================
- // Constants
- // ===========================================================
-
- // ===========================================================
- // Fields
- // ===========================================================
-
- // ===========================================================
- // Constructors
- // ===========================================================
-
- public DirectMenuAnimator(){
- super();
- }
-
- public DirectMenuAnimator(final HorizontalAlign pHorizontalAlign) {
- super(pHorizontalAlign);
- }
-
- public DirectMenuAnimator(final float pMenuItemSpacing) {
- super(pMenuItemSpacing);
- }
-
- public DirectMenuAnimator(final HorizontalAlign pHorizontalAlign, final float pMenuItemSpacing) {
- super(pHorizontalAlign, pMenuItemSpacing);
- }
-
- // ===========================================================
- // Getter & Setter
- // ===========================================================
-
- // ===========================================================
- // Methods for/from SuperClass/Interfaces
- // ===========================================================
-
- @Override
- public void buildAnimations(final ArrayList pMenuItems, final float pCameraWidth, final float pCameraHeight) {
-
- }
-
- @Override
- public void prepareAnimations(final ArrayList pMenuItems, final float pCameraWidth, final float pCameraHeight) {
- final float maximumWidth = this.getMaximumWidth(pMenuItems);
- final float overallHeight = this.getOverallHeight(pMenuItems);
-
- final float baseX = (pCameraWidth - maximumWidth) * 0.5f;
- final float baseY = (pCameraHeight - overallHeight) * 0.5f;
-
- final float menuItemSpacing = this.mMenuItemSpacing;
-
- float offsetY = 0;
- final int menuItemCount = pMenuItems.size();
- for(int i = 0; i < menuItemCount; i++) {
- final IMenuItem menuItem = pMenuItems.get(i);
-
- final float offsetX;
- switch(this.mHorizontalAlign) {
- case LEFT:
- offsetX = 0;
- break;
- case RIGHT:
- offsetX = maximumWidth - menuItem.getWidthScaled();
- break;
- case CENTER:
- default:
- offsetX = (maximumWidth - menuItem.getWidthScaled()) * 0.5f;
- break;
- }
- menuItem.setPosition(baseX + offsetX , baseY + offsetY);
-
- offsetY += menuItem.getHeight() + menuItemSpacing;
- }
- }
-
- // ===========================================================
- // Methods
- // ===========================================================
-
- // ===========================================================
- // Inner and Anonymous Classes
- // ===========================================================
-}
diff --git a/src/org/andengine/entity/scene/menu/animator/IMenuAnimator.java b/src/org/andengine/entity/scene/menu/animator/IMenuAnimator.java
deleted file mode 100644
index f9cb8df6e..000000000
--- a/src/org/andengine/entity/scene/menu/animator/IMenuAnimator.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package org.andengine.entity.scene.menu.animator;
-
-import java.util.ArrayList;
-
-import org.andengine.entity.scene.menu.item.IMenuItem;
-
-/**
- * (c) 2010 Nicolas Gramlich
- * (c) 2011 Zynga Inc.
- *
- * @author Nicolas Gramlich
- * @since 10:50:36 - 02.04.2010
- */
-public interface IMenuAnimator {
- // ===========================================================
- // Constants
- // ===========================================================
-
- public static final IMenuAnimator DEFAULT = new AlphaMenuAnimator();
-
- // ===========================================================
- // Methods
- // ===========================================================
-
- public void prepareAnimations(final ArrayList pMenuItems, final float pCameraWidth, final float pCameraHeight);
- public void buildAnimations(final ArrayList pMenuItems, final float pCameraWidth, final float pCameraHeight);
-}
diff --git a/src/org/andengine/entity/scene/menu/animator/IMenuSceneAnimator.java b/src/org/andengine/entity/scene/menu/animator/IMenuSceneAnimator.java
new file mode 100644
index 000000000..57c290a3e
--- /dev/null
+++ b/src/org/andengine/entity/scene/menu/animator/IMenuSceneAnimator.java
@@ -0,0 +1,36 @@
+package org.andengine.entity.scene.menu.animator;
+
+import org.andengine.entity.scene.menu.MenuScene;
+import org.andengine.util.adt.align.HorizontalAlign;
+import org.andengine.util.adt.align.VerticalAlign;
+
+/**
+ * (c) 2010 Nicolas Gramlich
+ * (c) 2011 Zynga Inc.
+ *
+ * @author Nicolas Gramlich
+ * @since 10:50:36 - 02.04.2010
+ */
+public interface IMenuSceneAnimator {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ public float getOffsetX();
+ public void setOffsetX(final float pOffsetX);
+ public float getOffsetY();
+ public void setOffsetY(final float pOffsetY);
+ public float getMenuItemSpacing();
+ public void setMenuItemSpacing(final float pMenuItemSpacing);
+ public HorizontalAlign getHorizontalAlign();
+ public void setHorizontalAlign(final HorizontalAlign pHorizontalAlign);
+ public VerticalAlign getVerticalAlign();
+ public void setVerticalAlign(final VerticalAlign pVerticalAlign);
+
+ public void buildMenuSceneAnimations(final MenuScene pMenuScene);
+ public void resetMenuSceneAnimations(final MenuScene pMenuScene);
+}
diff --git a/src/org/andengine/entity/scene/menu/animator/InstantMenuSceneAnimator.java b/src/org/andengine/entity/scene/menu/animator/InstantMenuSceneAnimator.java
new file mode 100644
index 000000000..30728db3d
--- /dev/null
+++ b/src/org/andengine/entity/scene/menu/animator/InstantMenuSceneAnimator.java
@@ -0,0 +1,61 @@
+package org.andengine.entity.scene.menu.animator;
+
+import org.andengine.entity.scene.menu.MenuScene;
+import org.andengine.entity.scene.menu.item.IMenuItem;
+import org.andengine.util.adt.align.HorizontalAlign;
+import org.andengine.util.adt.align.VerticalAlign;
+
+/**
+ * (c) 2010 Nicolas Gramlich
+ * (c) 2011 Zynga Inc.
+ *
+ * @author Nicolas Gramlich
+ * @since 11:04:35 - 02.04.2010
+ */
+public class InstantMenuSceneAnimator extends MenuSceneAnimator {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ public InstantMenuSceneAnimator() {
+ super();
+ }
+
+ public InstantMenuSceneAnimator(final HorizontalAlign pHorizontalAlign, final VerticalAlign pVerticalAlign) {
+ super(pHorizontalAlign, pVerticalAlign);
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ @Override
+ protected void onMenuItemPositionBuilt(final MenuScene pMenuScene, final int pIndex, final IMenuItem pMenuItem, final float pX, final float pY) {
+ pMenuItem.setPosition(pX, pY);
+ }
+
+ @Override
+ protected void onMenuItemPositionReset(final MenuScene pMenuScene, final int pIndex, final IMenuItem pMenuItem, final float pX, final float pY) {
+ pMenuItem.setPosition(pX, pY);
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
diff --git a/src/org/andengine/entity/scene/menu/animator/MenuSceneAnimator.java b/src/org/andengine/entity/scene/menu/animator/MenuSceneAnimator.java
new file mode 100644
index 000000000..cafc6bdf8
--- /dev/null
+++ b/src/org/andengine/entity/scene/menu/animator/MenuSceneAnimator.java
@@ -0,0 +1,214 @@
+package org.andengine.entity.scene.menu.animator;
+
+import org.andengine.entity.scene.menu.MenuScene;
+import org.andengine.entity.scene.menu.item.IMenuItem;
+import org.andengine.util.adt.align.HorizontalAlign;
+import org.andengine.util.adt.align.VerticalAlign;
+
+/**
+ * (c) 2010 Nicolas Gramlich
+ * (c) 2011 Zynga Inc.
+ *
+ * @author Nicolas Gramlich
+ * @since 11:17:32 - 02.04.2010
+ */
+public abstract class MenuSceneAnimator implements IMenuSceneAnimator {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ private static final HorizontalAlign HORIZONTALALIGN_DEFAULT = HorizontalAlign.CENTER;
+ private static final VerticalAlign VERTICALALIGN_DEFAULT = VerticalAlign.CENTER;
+ private static final float SPACING_DEFAULT = 1.0f;
+ private static final float OFFSET_X_DEFAULT = 0.0f;
+ private static final float OFFSET_Y_DEFAULT = 0.0f;
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ protected HorizontalAlign mHorizontalAlign;
+ protected VerticalAlign mVerticalAlign;
+
+ protected float mOffsetX = MenuSceneAnimator.OFFSET_X_DEFAULT;
+ protected float mOffsetY = MenuSceneAnimator.OFFSET_Y_DEFAULT;
+
+ protected float mMenuItemSpacing = MenuSceneAnimator.SPACING_DEFAULT;
+ protected float mOverallHeight;
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ public MenuSceneAnimator() {
+ this(MenuSceneAnimator.HORIZONTALALIGN_DEFAULT, MenuSceneAnimator.VERTICALALIGN_DEFAULT);
+ }
+
+ public MenuSceneAnimator(final HorizontalAlign pHorizontalAlign, final VerticalAlign pVerticalAlign) {
+ this.mHorizontalAlign = pHorizontalAlign;
+ this.mVerticalAlign = pVerticalAlign;
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ @Override
+ public float getOffsetX() {
+ return this.mOffsetX;
+ }
+
+ @Override
+ public void setOffsetX(final float pOffsetX) {
+ this.mOffsetX = pOffsetX;
+ }
+
+ @Override
+ public float getOffsetY() {
+ return this.mOffsetY;
+ }
+
+ @Override
+ public void setOffsetY(final float pOffsetY) {
+ this.mOffsetY = pOffsetY;
+ }
+
+ @Override
+ public float getMenuItemSpacing() {
+ return this.mMenuItemSpacing;
+ }
+
+ @Override
+ public void setMenuItemSpacing(final float pMenuItemSpacing) {
+ this.mMenuItemSpacing = pMenuItemSpacing;
+ }
+
+ @Override
+ public HorizontalAlign getHorizontalAlign() {
+ return this.mHorizontalAlign;
+ }
+
+ @Override
+ public void setHorizontalAlign(final HorizontalAlign pHorizontalAlign) {
+ this.mHorizontalAlign = pHorizontalAlign;
+ }
+
+ @Override
+ public VerticalAlign getVerticalAlign() {
+ return this.mVerticalAlign;
+ }
+
+ @Override
+ public void setVerticalAlign(final VerticalAlign pVerticalAlign) {
+ this.mVerticalAlign = pVerticalAlign;
+ }
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ protected abstract void onMenuItemPositionBuilt(final MenuScene pMenuScene, final int pIndex, final IMenuItem pMenuItem, final float pX, final float pY);
+ protected abstract void onMenuItemPositionReset(final MenuScene pMenuScene, final int pIndex, final IMenuItem pMenuItem, final float pX, final float pY);
+
+ @Override
+ public void buildMenuSceneAnimations(final MenuScene pMenuScene) {
+ this.updateOverallHeight(pMenuScene);
+
+ final int menuItemCount = pMenuScene.getMenuItemCount();
+
+ for (int i = 0; i < menuItemCount; i++) {
+ final IMenuItem menuItem = pMenuScene.getMenuItem(i);
+
+ final float x = this.getMenuItemX(pMenuScene, i);
+ final float y = this.getMenuItemY(pMenuScene, i);
+ this.onMenuItemPositionBuilt(pMenuScene, i, menuItem, x, y);
+ }
+ }
+
+ @Override
+ public void resetMenuSceneAnimations(final MenuScene pMenuScene) {
+ final int menuItemCount = pMenuScene.getMenuItemCount();
+
+ for (int i = 0; i < menuItemCount; i++) {
+ final IMenuItem menuItem = pMenuScene.getMenuItem(i);
+
+ final float x = this.getMenuItemX(pMenuScene, i);
+ final float y = this.getMenuItemY(pMenuScene, i);
+ this.onMenuItemPositionReset(pMenuScene, i, menuItem, x, y);
+ }
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ protected float getMenuItemX(final MenuScene pMenuScene, final int pIndex) {
+ final float menuSceneWidth = pMenuScene.getWidth();
+
+ final IMenuItem menuItem = pMenuScene.getMenuItem(pIndex);
+ final float menuItemWidth = menuItem.getWidth();
+
+ /* Determine horizontal position. */
+ final float x;
+ switch (this.mHorizontalAlign) {
+ case LEFT:
+ x = menuItemWidth * 0.5f;
+ break;
+ case CENTER:
+ x = menuSceneWidth * 0.5f;
+ break;
+ case RIGHT:
+ x = menuSceneWidth - (menuItemWidth * 0.5f);
+ break;
+ default:
+ throw new IllegalArgumentException("Unexpected " + HorizontalAlign.class.getSimpleName() + " with value: '" + this.mHorizontalAlign + "'.");
+ }
+
+ return x + this.mOffsetX;
+ }
+
+ protected float getMenuItemY(final MenuScene pMenuScene, final int pIndex) {
+ final float menuSceneHeight = pMenuScene.getHeight();
+
+ final IMenuItem menuItem = pMenuScene.getMenuItem(pIndex);
+
+ /* Prepare vertical position. */
+ float baseY;
+ switch (this.mVerticalAlign) {
+ case TOP:
+ baseY = menuSceneHeight;
+ break;
+ case CENTER:
+ baseY = (0.5f * menuSceneHeight) + (this.mOverallHeight * 0.5f);
+ break;
+ case BOTTOM:
+ baseY = this.mOverallHeight;
+ break;
+ default:
+ throw new IllegalArgumentException("Unexpected " + VerticalAlign.class.getSimpleName() + " with value: '" + this.mVerticalAlign + "'.");
+ }
+
+ final float menuItemHeight = menuItem.getHeight();
+
+ /* Determine vertical position. */
+ final float y = baseY - (menuItemHeight * 0.5f) - (pIndex * (menuItemHeight + this.mMenuItemSpacing));
+
+ return y + this.mOffsetY;
+ }
+
+ private void updateOverallHeight(final MenuScene pMenuScene) {
+ final int menuItemCount = pMenuScene.getMenuItemCount();
+
+ float overallHeight = 0;
+ for (int i = menuItemCount - 1; i >= 0; i--) {
+ final IMenuItem menuItem = pMenuScene.getMenuItem(i);
+ overallHeight += menuItem.getHeight();
+ }
+
+ this.mOverallHeight = overallHeight + ((menuItemCount - 1) * this.mMenuItemSpacing);
+ }
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
diff --git a/src/org/andengine/entity/scene/menu/animator/SlideMenuAnimator.java b/src/org/andengine/entity/scene/menu/animator/SlideMenuAnimator.java
deleted file mode 100644
index fe7e72664..000000000
--- a/src/org/andengine/entity/scene/menu/animator/SlideMenuAnimator.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package org.andengine.entity.scene.menu.animator;
-
-import java.util.ArrayList;
-
-import org.andengine.entity.modifier.MoveModifier;
-import org.andengine.entity.scene.menu.item.IMenuItem;
-import org.andengine.util.HorizontalAlign;
-import org.andengine.util.modifier.ease.IEaseFunction;
-
-/**
- * (c) 2010 Nicolas Gramlich
- * (c) 2011 Zynga Inc.
- *
- * @author Nicolas Gramlich
- * @since 11:04:35 - 02.04.2010
- */
-public class SlideMenuAnimator extends BaseMenuAnimator {
- // ===========================================================
- // Constants
- // ===========================================================
-
- // ===========================================================
- // Fields
- // ===========================================================
-
- // ===========================================================
- // Constructors
- // ===========================================================
-
- public SlideMenuAnimator(){
- super();
- }
-
- public SlideMenuAnimator(final IEaseFunction pEaseFunction) {
- super(pEaseFunction);
- }
-
- public SlideMenuAnimator(final HorizontalAlign pHorizontalAlign) {
- super(pHorizontalAlign);
- }
-
- public SlideMenuAnimator(final HorizontalAlign pHorizontalAlign, final IEaseFunction pEaseFunction) {
- super(pHorizontalAlign, pEaseFunction);
- }
-
- public SlideMenuAnimator(final float pMenuItemSpacing) {
- super(pMenuItemSpacing);
- }
-
- public SlideMenuAnimator(final float pMenuItemSpacing, final IEaseFunction pEaseFunction) {
- super(pMenuItemSpacing, pEaseFunction);
- }
-
- public SlideMenuAnimator(final HorizontalAlign pHorizontalAlign, final float pMenuItemSpacing) {
- super(pHorizontalAlign, pMenuItemSpacing);
- }
-
- public SlideMenuAnimator(final HorizontalAlign pHorizontalAlign, final float pMenuItemSpacing, final IEaseFunction pEaseFunction) {
- super(pHorizontalAlign, pMenuItemSpacing, pEaseFunction);
- }
-
- // ===========================================================
- // Getter & Setter
- // ===========================================================
-
- // ===========================================================
- // Methods for/from SuperClass/Interfaces
- // ===========================================================
-
- @Override
- public void buildAnimations(final ArrayList pMenuItems, final float pCameraWidth, final float pCameraHeight) {
- final IEaseFunction easeFunction = this.mEaseFunction;
- final float maximumWidth = this.getMaximumWidth(pMenuItems);
- final float overallHeight = this.getOverallHeight(pMenuItems);
-
- final float baseX = (pCameraWidth - maximumWidth) * 0.5f;
- final float baseY = (pCameraHeight - overallHeight) * 0.5f;
-
- float offsetY = 0;
- final int menuItemCount = pMenuItems.size();
- for(int i = 0; i < menuItemCount; i++) {
- final IMenuItem menuItem = pMenuItems.get(i);
-
- final float offsetX;
- switch(this.mHorizontalAlign) {
- case LEFT:
- offsetX = 0;
- break;
- case RIGHT:
- offsetX = maximumWidth - menuItem.getWidthScaled();
- break;
- case CENTER:
- default:
- offsetX = (maximumWidth - menuItem.getWidthScaled()) * 0.5f;
- break;
- }
-
- final MoveModifier moveModifier = new MoveModifier(DURATION, -maximumWidth, baseX + offsetX, baseY + offsetY, baseY + offsetY, easeFunction);
- moveModifier.setAutoUnregisterWhenFinished(false);
- menuItem.registerEntityModifier(moveModifier);
-
- offsetY += menuItem.getHeight() + this.mMenuItemSpacing;
- }
- }
-
- @Override
- public void prepareAnimations(final ArrayList pMenuItems, final float pCameraWidth, final float pCameraHeight) {
- final float maximumWidth = this.getMaximumWidth(pMenuItems);
- final float overallHeight = this.getOverallHeight(pMenuItems);
-
- final float baseY = (pCameraHeight - overallHeight) * 0.5f;
-
- final float menuItemSpacing = this.mMenuItemSpacing;
-
- float offsetY = 0;
- final int menuItemCount = pMenuItems.size();
- for(int i = 0; i < menuItemCount; i++) {
- final IMenuItem menuItem = pMenuItems.get(i);
-
- menuItem.setPosition(-maximumWidth, baseY + offsetY);
-
- offsetY += menuItem.getHeight() + menuItemSpacing;
- }
- }
-
- // ===========================================================
- // Methods
- // ===========================================================
-
- // ===========================================================
- // Inner and Anonymous Classes
- // ===========================================================
-}
diff --git a/src/org/andengine/entity/scene/menu/animator/SlideMenuSceneAnimator.java b/src/org/andengine/entity/scene/menu/animator/SlideMenuSceneAnimator.java
new file mode 100644
index 000000000..5fa2c5f60
--- /dev/null
+++ b/src/org/andengine/entity/scene/menu/animator/SlideMenuSceneAnimator.java
@@ -0,0 +1,168 @@
+package org.andengine.entity.scene.menu.animator;
+
+import org.andengine.entity.modifier.MoveModifier;
+import org.andengine.entity.scene.menu.MenuScene;
+import org.andengine.entity.scene.menu.item.IMenuItem;
+import org.andengine.util.adt.align.HorizontalAlign;
+import org.andengine.util.adt.align.VerticalAlign;
+import org.andengine.util.adt.spatial.Direction;
+import org.andengine.util.modifier.ease.EaseLinear;
+import org.andengine.util.modifier.ease.IEaseFunction;
+
+/**
+ * (c) 2010 Nicolas Gramlich
+ * (c) 2011 Zynga Inc.
+ *
+ * @author Nicolas Gramlich
+ * @since 11:04:35 - 02.04.2010
+ */
+public class SlideMenuSceneAnimator extends MenuSceneAnimator {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ private static final float DURATION = 1.0f;
+
+ private static final IEaseFunction EASEFUNCTION_DEFAULT = EaseLinear.getInstance();
+
+ private static final Direction DIRECTION_DEFAULT = Direction.RIGHT;
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ private IEaseFunction mEaseFunction;
+ private Direction mDirection;
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ public SlideMenuSceneAnimator() {
+ this(SlideMenuSceneAnimator.DIRECTION_DEFAULT, SlideMenuSceneAnimator.EASEFUNCTION_DEFAULT);
+ }
+
+ public SlideMenuSceneAnimator(final IEaseFunction pEaseFunction) {
+ this(SlideMenuSceneAnimator.DIRECTION_DEFAULT, pEaseFunction);
+ }
+
+ public SlideMenuSceneAnimator(final Direction pDirection) {
+ this(pDirection, SlideMenuSceneAnimator.EASEFUNCTION_DEFAULT);
+ }
+
+ public SlideMenuSceneAnimator(final Direction pDirection, final IEaseFunction pEaseFunction) {
+ super();
+
+ this.mDirection = pDirection;
+ this.mEaseFunction = pEaseFunction;
+ }
+
+ public SlideMenuSceneAnimator(final HorizontalAlign pHorizontalAlign, final VerticalAlign pVerticalAlign) {
+ this(pHorizontalAlign, pVerticalAlign, SlideMenuSceneAnimator.DIRECTION_DEFAULT, SlideMenuSceneAnimator.EASEFUNCTION_DEFAULT);
+ }
+
+ public SlideMenuSceneAnimator(final HorizontalAlign pHorizontalAlign, final VerticalAlign pVerticalAlign, final IEaseFunction pEaseFunction) {
+ this(pHorizontalAlign, pVerticalAlign, SlideMenuSceneAnimator.DIRECTION_DEFAULT, pEaseFunction);
+ }
+
+ public SlideMenuSceneAnimator(final HorizontalAlign pHorizontalAlign, final VerticalAlign pVerticalAlign, final Direction pDirection) {
+ this(pHorizontalAlign, pVerticalAlign, pDirection, SlideMenuSceneAnimator.EASEFUNCTION_DEFAULT);
+ }
+
+ public SlideMenuSceneAnimator(final HorizontalAlign pHorizontalAlign, final VerticalAlign pVerticalAlign, final Direction pDirection, final IEaseFunction pEaseFunction) {
+ super(pHorizontalAlign, pVerticalAlign);
+
+ this.mDirection = pDirection;
+ this.mEaseFunction = pEaseFunction;
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ public IEaseFunction getEaseFunction() {
+ return this.mEaseFunction;
+ }
+
+ public void setEaseFunction(final IEaseFunction pEaseFunction) {
+ this.mEaseFunction = pEaseFunction;
+ }
+
+ public Direction getDirection() {
+ return this.mDirection;
+ }
+
+ public void setDirection(final Direction pDirection) {
+ this.mDirection = pDirection;
+ }
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ @Override
+ protected void onMenuItemPositionBuilt(final MenuScene pMenuScene, final int pIndex, final IMenuItem pMenuItem, final float pX, final float pY) {
+ final float fromX = getFromX(pMenuScene, pMenuItem, pX);
+ final float fromY = getFromY(pMenuScene, pMenuItem, pY);
+
+ pMenuItem.setPosition(fromX, fromY);
+
+ final MoveModifier moveModifier = new MoveModifier(SlideMenuSceneAnimator.DURATION, fromX, fromY, pX, pY, this.mEaseFunction);
+ moveModifier.setAutoUnregisterWhenFinished(false);
+ pMenuItem.registerEntityModifier(moveModifier);
+ }
+
+ @Override
+ protected void onMenuItemPositionReset(final MenuScene pMenuScene, final int pIndex, final IMenuItem pMenuItem, final float pX, final float pY) {
+ final float fromX = getFromX(pMenuScene, pMenuItem, pX);
+ final float fromY = getFromY(pMenuScene, pMenuItem, pY);
+
+ pMenuItem.setPosition(fromX, fromY);
+
+ pMenuItem.resetEntityModifiers();
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ protected float getFromX(final MenuScene pMenuScene, final IMenuItem pMenuItem, final float pX) {
+ switch (this.mDirection) {
+ case UP:
+ case DOWN:
+ return pX;
+ case DOWN_LEFT:
+ case UP_LEFT:
+ case LEFT:
+ return pMenuScene.getWidth() + (pMenuItem.getWidth() * 0.5f);
+ case DOWN_RIGHT:
+ case UP_RIGHT:
+ case RIGHT:
+ return -(pMenuItem.getWidth() * 0.5f);
+ default:
+ throw new IllegalArgumentException();
+ }
+ }
+
+ protected float getFromY(final MenuScene pMenuScene, final IMenuItem pMenuItem, final float pY) {
+ switch (this.mDirection) {
+ case DOWN_LEFT:
+ case DOWN:
+ case DOWN_RIGHT:
+ return pMenuScene.getHeight() + (pMenuItem.getHeight() * 0.5f);
+ case LEFT:
+ case RIGHT:
+ return pY;
+ case UP_LEFT:
+ case UP:
+ case UP_RIGHT:
+ return -(pMenuItem.getHeight() * 0.5f);
+ default:
+ throw new IllegalArgumentException();
+ }
+ }
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
diff --git a/src/org/andengine/entity/scene/menu/item/AnimatedSpriteMenuItem.java b/src/org/andengine/entity/scene/menu/item/AnimatedSpriteMenuItem.java
index 34593a4e2..2ff796544 100644
--- a/src/org/andengine/entity/scene/menu/item/AnimatedSpriteMenuItem.java
+++ b/src/org/andengine/entity/scene/menu/item/AnimatedSpriteMenuItem.java
@@ -10,7 +10,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:44:39 - 07.07.2010
*/
diff --git a/src/org/andengine/entity/scene/menu/item/IMenuItem.java b/src/org/andengine/entity/scene/menu/item/IMenuItem.java
index 77b340cf5..3e8d5b787 100644
--- a/src/org/andengine/entity/scene/menu/item/IMenuItem.java
+++ b/src/org/andengine/entity/scene/menu/item/IMenuItem.java
@@ -1,15 +1,15 @@
package org.andengine.entity.scene.menu.item;
-import org.andengine.entity.shape.IAreaShape;
+import org.andengine.entity.shape.IShape;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 13:27:16 - 07.07.2010
*/
-public interface IMenuItem extends IAreaShape {
+public interface IMenuItem extends IShape {
// ===========================================================
// Constants
// ===========================================================
diff --git a/src/org/andengine/entity/scene/menu/item/SpriteMenuItem.java b/src/org/andengine/entity/scene/menu/item/SpriteMenuItem.java
index df733a96b..69968bc85 100644
--- a/src/org/andengine/entity/scene/menu/item/SpriteMenuItem.java
+++ b/src/org/andengine/entity/scene/menu/item/SpriteMenuItem.java
@@ -10,7 +10,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 20:15:20 - 01.04.2010
*/
diff --git a/src/org/andengine/entity/scene/menu/item/TextMenuItem.java b/src/org/andengine/entity/scene/menu/item/TextMenuItem.java
index 8ef0ae031..716975b34 100644
--- a/src/org/andengine/entity/scene/menu/item/TextMenuItem.java
+++ b/src/org/andengine/entity/scene/menu/item/TextMenuItem.java
@@ -11,7 +11,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 20:15:20 - 01.04.2010
*/
diff --git a/src/org/andengine/entity/scene/menu/item/decorator/BaseMenuItemDecorator.java b/src/org/andengine/entity/scene/menu/item/decorator/BaseMenuItemDecorator.java
index 33a5b26e6..55361136d 100644
--- a/src/org/andengine/entity/scene/menu/item/decorator/BaseMenuItemDecorator.java
+++ b/src/org/andengine/entity/scene/menu/item/decorator/BaseMenuItemDecorator.java
@@ -12,21 +12,20 @@
import org.andengine.entity.modifier.IEntityModifier;
import org.andengine.entity.modifier.IEntityModifier.IEntityModifierMatcher;
import org.andengine.entity.scene.menu.item.IMenuItem;
-import org.andengine.entity.shape.IShape;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.shader.ShaderProgram;
import org.andengine.opengl.util.GLState;
import org.andengine.opengl.vbo.IVertexBufferObject;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
+import org.andengine.util.adt.color.Color;
import org.andengine.util.adt.transformation.Transformation;
-import org.andengine.util.color.Color;
/**
* I HATE THIS CLASS!
- *
+ *
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:05:44 - 18.11.2010
*/
@@ -122,7 +121,8 @@ public void setPosition(final float pX, final float pY) {
public float getWidth() {
return this.mMenuItem.getWidth();
}
-
+
+ @Deprecated
@Override
public float getWidthScaled() {
return this.mMenuItem.getWidthScaled();
@@ -132,7 +132,8 @@ public float getWidthScaled() {
public float getHeight() {
return this.mMenuItem.getHeight();
}
-
+
+ @Deprecated
@Override
public float getHeightScaled() {
return this.mMenuItem.getHeightScaled();
@@ -203,6 +204,11 @@ public void setColor(final Color pColor) {
this.mMenuItem.setColor(pColor);
}
+ @Override
+ public void setColor(final int pARGBPackedInt) {
+ this.mMenuItem.setColor(pARGBPackedInt);
+ }
+
@Override
public void setColor(final float pRed, final float pGreen, final float pBlue) {
this.mMenuItem.setColor(pRed, pGreen, pBlue);
@@ -213,6 +219,31 @@ public void setColor(final float pRed, final float pGreen, final float pBlue, fi
this.mMenuItem.setColor(pRed, pGreen, pBlue, pAlpha);
}
+ @Override
+ public float getOffsetCenterX() {
+ return this.mMenuItem.getOffsetCenterX();
+ }
+
+ @Override
+ public float getOffsetCenterY() {
+ return this.mMenuItem.getOffsetCenterY();
+ }
+
+ @Override
+ public void setOffsetCenterX(final float pOffsetCenterX) {
+ this.mMenuItem.setOffsetCenterX(pOffsetCenterX);
+ }
+
+ @Override
+ public void setOffsetCenterY(final float pOffsetCenterY) {
+ this.mMenuItem.setOffsetCenterY(pOffsetCenterY);
+ }
+
+ @Override
+ public void setOffsetCenter(final float pOffsetCenterX, final float pOffsetCenterY) {
+ this.mMenuItem.setOffsetCenter(pOffsetCenterX, pOffsetCenterY);
+ }
+
@Override
public boolean isRotated() {
return this.mMenuItem.isRotated();
@@ -312,62 +343,62 @@ public void setScaleCenterY(final float pScaleCenterY) {
public void setScaleCenter(final float pScaleCenterX, final float pScaleCenterY) {
this.mMenuItem.setScaleCenter(pScaleCenterX, pScaleCenterY);
}
-
+
@Override
public boolean isSkewed() {
return this.mMenuItem.isSkewed();
}
-
+
@Override
public float getSkewX() {
return this.mMenuItem.getSkewX();
}
-
+
@Override
public float getSkewY() {
return this.mMenuItem.getSkewY();
}
-
+
@Override
public void setSkew(final float pSkew) {
this.mMenuItem.setSkew(pSkew);
}
-
+
@Override
public void setSkew(final float pSkewX, final float pSkewY) {
this.mMenuItem.setSkew(pSkewX, pSkewY);
}
-
+
@Override
public void setSkewX(final float pSkewX) {
this.mMenuItem.setSkewX(pSkewX);
}
-
+
@Override
public void setSkewY(final float pSkewY) {
this.mMenuItem.setSkewY(pSkewY);
}
-
+
@Override
public float getSkewCenterX() {
return this.mMenuItem.getSkewCenterX();
}
-
+
@Override
public float getSkewCenterY() {
return this.mMenuItem.getSkewCenterY();
}
-
+
@Override
public void setSkewCenterX(final float pSkewCenterX) {
this.mMenuItem.setSkewCenterX(pSkewCenterX);
}
-
+
@Override
public void setSkewCenterY(final float pSkewCenterY) {
this.mMenuItem.setSkewCenterY(pSkewCenterY);
}
-
+
@Override
public void setSkewCenter(final float pSkewCenterX, final float pSkewCenterY) {
this.mMenuItem.setSkewCenter(pSkewCenterX, pSkewCenterY);
@@ -377,10 +408,25 @@ public void setSkewCenter(final float pSkewCenterX, final float pSkewCenterY) {
public boolean isRotatedOrScaledOrSkewed() {
return this.mMenuItem.isRotatedOrScaledOrSkewed();
}
-
+
@Override
- public boolean collidesWith(final IShape pOtherShape) {
- return this.mMenuItem.collidesWith(pOtherShape);
+ public void setAnchorCenterX(final float pAnchorCenterX) {
+ this.setAnchorCenterX(pAnchorCenterX);
+ }
+
+ @Override
+ public void setAnchorCenterY(final float pAnchorCenterY) {
+ this.setAnchorCenterY(pAnchorCenterY);
+ }
+
+ @Override
+ public void setAnchorCenter(final float pAnchorCenterX, final float pAnchorCenterY) {
+ this.mMenuItem.setAnchorCenter(pAnchorCenterX, pAnchorCenterY);
+ }
+
+ @Override
+ public boolean collidesWith(final IEntity pOtherEntity) {
+ return this.mMenuItem.collidesWith(pOtherEntity);
}
@Override
@@ -413,11 +459,21 @@ public boolean unregisterEntityModifiers(final IEntityModifierMatcher pEntityMod
return this.mMenuItem.unregisterEntityModifiers(pEntityModifierMatcher);
}
+ @Override
+ public int getEntityModifierCount() {
+ return this.mMenuItem.getEntityModifierCount();
+ }
+
@Override
public void clearEntityModifiers() {
this.mMenuItem.clearEntityModifiers();
}
+ @Override
+ public void resetEntityModifiers() {
+ this.mMenuItem.resetEntityModifiers();
+ }
+
@Override
public boolean isBlendingEnabled() {
return this.mMenuItem.isBlendingEnabled();
@@ -520,43 +576,83 @@ public boolean contains(final float pX, final float pY) {
}
@Override
- public float[] convertLocalToSceneCoordinates(final float pX, final float pY) {
- return this.mMenuItem.convertLocalToSceneCoordinates(pX, pY);
+ public float[] convertLocalCoordinatesToParentCoordinates(final float pX, final float pY) {
+ return this.mMenuItem.convertLocalCoordinatesToParentCoordinates(pX, pY);
+ }
+
+ @Override
+ public float[] convertLocalCoordinatesToParentCoordinates(final float pX, final float pY, final float[] pReuse) {
+ return this.mMenuItem.convertLocalCoordinatesToParentCoordinates(pX, pY, pReuse);
+ }
+
+ @Override
+ public float[] convertLocalCoordinatesToParentCoordinates(final float[] pCoordinates) {
+ return this.mMenuItem.convertLocalCoordinatesToParentCoordinates(pCoordinates);
+ }
+
+ @Override
+ public float[] convertLocalCoordinatesToParentCoordinates(final float[] pCoordinates, final float[] pReuse) {
+ return this.mMenuItem.convertLocalCoordinatesToParentCoordinates(pCoordinates, pReuse);
+ }
+
+ @Override
+ public float[] convertParentCoordinatesToLocalCoordinates(final float pX, final float pY) {
+ return this.mMenuItem.convertParentCoordinatesToLocalCoordinates(pX, pY);
+ }
+
+ @Override
+ public float[] convertParentCoordinatesToLocalCoordinates(final float pX, final float pY, final float[] pReuse) {
+ return this.mMenuItem.convertParentCoordinatesToLocalCoordinates(pX, pY, pReuse);
+ }
+
+ @Override
+ public float[] convertParentCoordinatesToLocalCoordinates(final float[] pCoordinates) {
+ return this.mMenuItem.convertParentCoordinatesToLocalCoordinates(pCoordinates);
+ }
+
+ @Override
+ public float[] convertParentCoordinatesToLocalCoordinates(final float[] pCoordinates, final float[] pReuse) {
+ return this.mMenuItem.convertParentCoordinatesToLocalCoordinates(pCoordinates, pReuse);
+ }
+
+ @Override
+ public float[] convertLocalCoordinatesToSceneCoordinates(final float pX, final float pY) {
+ return this.mMenuItem.convertLocalCoordinatesToSceneCoordinates(pX, pY);
}
@Override
- public float[] convertLocalToSceneCoordinates(final float pX, final float pY, final float[] pReuse) {
- return this.mMenuItem.convertLocalToSceneCoordinates(pX, pY, pReuse);
+ public float[] convertLocalCoordinatesToSceneCoordinates(final float pX, final float pY, final float[] pReuse) {
+ return this.mMenuItem.convertLocalCoordinatesToSceneCoordinates(pX, pY, pReuse);
}
@Override
- public float[] convertLocalToSceneCoordinates(final float[] pCoordinates) {
- return this.mMenuItem.convertLocalToSceneCoordinates(pCoordinates);
+ public float[] convertLocalCoordinatesToSceneCoordinates(final float[] pCoordinates) {
+ return this.mMenuItem.convertLocalCoordinatesToSceneCoordinates(pCoordinates);
}
@Override
- public float[] convertLocalToSceneCoordinates(final float[] pCoordinates, final float[] pReuse) {
- return this.mMenuItem.convertLocalToSceneCoordinates(pCoordinates, pReuse);
+ public float[] convertLocalCoordinatesToSceneCoordinates(final float[] pCoordinates, final float[] pReuse) {
+ return this.mMenuItem.convertLocalCoordinatesToSceneCoordinates(pCoordinates, pReuse);
}
@Override
- public float[] convertSceneToLocalCoordinates(final float pX, final float pY) {
- return this.mMenuItem.convertSceneToLocalCoordinates(pX, pY);
+ public float[] convertSceneCoordinatesToLocalCoordinates(final float pX, final float pY) {
+ return this.mMenuItem.convertSceneCoordinatesToLocalCoordinates(pX, pY);
}
@Override
- public float[] convertSceneToLocalCoordinates(final float pX, final float pY, final float[] pReuse) {
- return this.mMenuItem.convertSceneToLocalCoordinates(pX, pY, pReuse);
+ public float[] convertSceneCoordinatesToLocalCoordinates(final float pX, final float pY, final float[] pReuse) {
+ return this.mMenuItem.convertSceneCoordinatesToLocalCoordinates(pX, pY, pReuse);
}
@Override
- public float[] convertSceneToLocalCoordinates(final float[] pCoordinates) {
- return this.mMenuItem.convertSceneToLocalCoordinates(pCoordinates);
+ public float[] convertSceneCoordinatesToLocalCoordinates(final float[] pCoordinates) {
+ return this.mMenuItem.convertSceneCoordinatesToLocalCoordinates(pCoordinates);
}
@Override
- public float[] convertSceneToLocalCoordinates(final float[] pCoordinates, final float[] pReuse) {
- return this.mMenuItem.convertSceneToLocalCoordinates(pCoordinates, pReuse);
+ public float[] convertSceneCoordinatesToLocalCoordinates(final float[] pCoordinates, final float[] pReuse) {
+ return this.mMenuItem.convertSceneCoordinatesToLocalCoordinates(pCoordinates, pReuse);
}
@Override
@@ -589,13 +685,12 @@ public IEntity getChildByTag(final int pTag) {
return this.mMenuItem.getChildByTag(pTag);
}
- @Override
public IEntity getChildByIndex(final int pIndex) {
return this.mMenuItem.getChildByIndex(pIndex);
}
@Override
- public IEntity getChildByMatcher(IEntityMatcher pEntityMatcher) {
+ public IEntity getChildByMatcher(final IEntityMatcher pEntityMatcher) {
return this.mMenuItem.getChildByMatcher(pEntityMatcher);
}
@@ -624,6 +719,7 @@ public ArrayList queryForSubclass(final IEntityMatcher pE
return this.mMenuItem.queryForSubclass(pEntityMatcher);
}
+ @Override
public , S extends IEntity> L queryForSubclass(final IEntityMatcher pEntityMatcher, final L pResult) throws ClassCastException {
return this.mMenuItem.queryForSubclass(pEntityMatcher, pResult);
}
@@ -632,7 +728,7 @@ public , S extends IEntity> L queryForSubclass(final IEntityMa
public void sortChildren() {
this.mMenuItem.sortChildren();
}
-
+
@Override
public void sortChildren(final boolean pImmediate) {
this.mMenuItem.sortChildren(pImmediate);
@@ -718,6 +814,11 @@ public void setParent(final IEntity pEntity) {
this.mMenuItem.setParent(pEntity);
}
+ @Override
+ public IEntity getRootEntity() {
+ return this.mMenuItem.getRootEntity();
+ }
+
@Override
public boolean isVisible() {
return this.mMenuItem.isVisible();
@@ -793,6 +894,11 @@ public boolean unregisterUpdateHandler(final IUpdateHandler pUpdateHandler) {
return this.mMenuItem.unregisterUpdateHandler(pUpdateHandler);
}
+ @Override
+ public int getUpdateHandlerCount() {
+ return this.mMenuItem.getUpdateHandlerCount();
+ }
+
@Override
public void clearUpdateHandlers() {
this.mMenuItem.clearUpdateHandlers();
diff --git a/src/org/andengine/entity/scene/menu/item/decorator/ColorMenuItemDecorator.java b/src/org/andengine/entity/scene/menu/item/decorator/ColorMenuItemDecorator.java
index 05b0f7fe1..edfa41201 100644
--- a/src/org/andengine/entity/scene/menu/item/decorator/ColorMenuItemDecorator.java
+++ b/src/org/andengine/entity/scene/menu/item/decorator/ColorMenuItemDecorator.java
@@ -1,12 +1,12 @@
package org.andengine.entity.scene.menu.item.decorator;
import org.andengine.entity.scene.menu.item.IMenuItem;
-import org.andengine.util.color.Color;
+import org.andengine.util.adt.color.Color;
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 14:25:35 - 07.07.2010
*/
diff --git a/src/org/andengine/entity/scene/menu/item/decorator/ScaleMenuItemDecorator.java b/src/org/andengine/entity/scene/menu/item/decorator/ScaleMenuItemDecorator.java
index a41071df6..80031924a 100644
--- a/src/org/andengine/entity/scene/menu/item/decorator/ScaleMenuItemDecorator.java
+++ b/src/org/andengine/entity/scene/menu/item/decorator/ScaleMenuItemDecorator.java
@@ -3,9 +3,9 @@
import org.andengine.entity.scene.menu.item.IMenuItem;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:04:29 - 18.11.2010
*/
diff --git a/src/org/andengine/entity/shape/IAreaShape.java b/src/org/andengine/entity/shape/IAreaShape.java
deleted file mode 100644
index 429b829cb..000000000
--- a/src/org/andengine/entity/shape/IAreaShape.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.andengine.entity.shape;
-
-
-/**
- * (c) Zynga 2011
- *
- * @author Nicolas Gramlich
- * @since 19:01:16 - 07.08.2011
- */
-public interface IAreaShape extends IShape {
- // ===========================================================
- // Constants
- // ===========================================================
-
- // ===========================================================
- // Methods
- // ===========================================================
-
- public float getWidth();
- public float getHeight();
-
- public float getWidthScaled();
- public float getHeightScaled();
-
- public void setHeight(final float pHeight);
- public void setWidth(final float pWidth);
- public void setSize(final float pWidth, final float pHeight);
-}
diff --git a/src/org/andengine/entity/shape/IShape.java b/src/org/andengine/entity/shape/IShape.java
index 04692d2e6..008c3be52 100644
--- a/src/org/andengine/entity/shape/IShape.java
+++ b/src/org/andengine/entity/shape/IShape.java
@@ -1,7 +1,6 @@
package org.andengine.entity.shape;
import org.andengine.entity.IEntity;
-import org.andengine.entity.scene.ITouchArea;
import org.andengine.opengl.shader.ShaderProgram;
import org.andengine.opengl.vbo.IVertexBufferObject;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
@@ -9,13 +8,13 @@
import android.opengl.GLES20;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 13:32:52 - 07.07.2010
*/
-public interface IShape extends IEntity, ITouchArea {
+public interface IShape extends IEntity {
// ===========================================================
// Constants
// ===========================================================
@@ -30,8 +29,6 @@ public interface IShape extends IEntity, ITouchArea {
// Methods
// ===========================================================
- public boolean collidesWith(final IShape pOtherShape);
-
public boolean isBlendingEnabled();
public void setBlendingEnabled(final boolean pBlendingEnabled);
public int getBlendFunctionSource();
diff --git a/src/org/andengine/entity/shape/RectangularShape.java b/src/org/andengine/entity/shape/RectangularShape.java
deleted file mode 100644
index b94d40d05..000000000
--- a/src/org/andengine/entity/shape/RectangularShape.java
+++ /dev/null
@@ -1,150 +0,0 @@
-package org.andengine.entity.shape;
-
-import org.andengine.engine.camera.Camera;
-import org.andengine.entity.primitive.Line;
-import org.andengine.opengl.shader.ShaderProgram;
-import org.andengine.util.algorithm.collision.RectangularShapeCollisionChecker;
-
-/**
- * (c) 2010 Nicolas Gramlich
- * (c) 2011 Zynga Inc.
- *
- * @author Nicolas Gramlich
- * @since 11:37:50 - 04.04.2010
- */
-public abstract class RectangularShape extends Shape implements IAreaShape {
- // ===========================================================
- // Constants
- // ===========================================================
-
- // ===========================================================
- // Fields
- // ===========================================================
-
- protected float mWidth;
- protected float mHeight;
-
- // ===========================================================
- // Constructors
- // ===========================================================
-
- public RectangularShape(final float pX, final float pY, final float pWidth, final float pHeight, final ShaderProgram pShaderProgram) {
- super(pX, pY, pShaderProgram);
-
- this.mWidth = pWidth;
- this.mHeight = pHeight;
-
- this.resetRotationCenter();
- this.resetScaleCenter();
- this.resetSkewCenter();
- }
-
- // ===========================================================
- // Getter & Setter
- // ===========================================================
-
- @Override
- public float getWidth() {
- return this.mWidth;
- }
-
- @Override
- public float getHeight() {
- return this.mHeight;
- }
-
- @Override
- public void setWidth(final float pWidth) {
- this.mWidth = pWidth;
- this.onUpdateVertices();
- }
-
- @Override
- public void setHeight(final float pHeight) {
- this.mHeight = pHeight;
- this.onUpdateVertices();
- }
-
- @Override
- public void setSize(final float pWidth, final float pHeight) {
- this.mWidth = pWidth;
- this.mHeight = pHeight;
- this.onUpdateVertices();
- }
-
- @Override
- public float getWidthScaled() {
- return this.getWidth() * this.mScaleX;
- }
-
- @Override
- public float getHeightScaled() {
- return this.getHeight() * this.mScaleY;
- }
-
- // ===========================================================
- // Methods for/from SuperClass/Interfaces
- // ===========================================================
-
- @Override
- public boolean isCulled(final Camera pCamera) {
- return !RectangularShapeCollisionChecker.isVisible(pCamera, this);
- }
-
- @Override
- public void reset() {
- super.reset();
-
- this.resetRotationCenter();
- this.resetSkewCenter();
- this.resetScaleCenter();
- }
-
- @Override
- public boolean contains(final float pX, final float pY) {
- return RectangularShapeCollisionChecker.checkContains(this, pX, pY);
- }
-
- @Override
- public float[] getSceneCenterCoordinates() {
- return this.convertLocalToSceneCoordinates(this.mWidth * 0.5f, this.mHeight * 0.5f);
- }
-
- public float[] getSceneCenterCoordinates(final float[] pReuse) {
- return this.convertLocalToSceneCoordinates(this.mWidth * 0.5f, this.mHeight * 0.5f, pReuse);
- }
-
- @Override
- public boolean collidesWith(final IShape pOtherShape) {
- if(pOtherShape instanceof RectangularShape) {
- return RectangularShapeCollisionChecker.checkCollision(this, (RectangularShape) pOtherShape);
- } else if(pOtherShape instanceof Line) {
- return RectangularShapeCollisionChecker.checkCollision(this, (Line) pOtherShape);
- } else {
- return false;
- }
- }
-
- // ===========================================================
- // Methods
- // ===========================================================
-
- public void resetRotationCenter() {
- this.mRotationCenterX = this.mWidth * 0.5f;
- this.mRotationCenterY = this.mHeight * 0.5f;
- }
-
- public void resetScaleCenter() {
- this.mScaleCenterX = this.mWidth * 0.5f;
- this.mScaleCenterY = this.mHeight * 0.5f;
- }
-
- public void resetSkewCenter() {
- this.mSkewCenterX = this.mWidth * 0.5f;
- this.mSkewCenterY = this.mHeight * 0.5f;
- }
-
- // ===========================================================
- // Inner and Anonymous Classes
- // ===========================================================
-}
diff --git a/src/org/andengine/entity/shape/Shape.java b/src/org/andengine/entity/shape/Shape.java
index 850491e2a..2bff0c0b3 100644
--- a/src/org/andengine/entity/shape/Shape.java
+++ b/src/org/andengine/entity/shape/Shape.java
@@ -2,7 +2,6 @@
import org.andengine.engine.camera.Camera;
import org.andengine.entity.Entity;
-import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.shader.ShaderProgram;
import org.andengine.opengl.texture.ITexture;
import org.andengine.opengl.texture.TextureOptions;
@@ -14,7 +13,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 11:51:27 - 13.03.2010
*/
@@ -30,7 +29,7 @@ public abstract class Shape extends Entity implements IShape {
protected int mBlendFunctionSource = IShape.BLENDFUNCTION_SOURCE_DEFAULT;
protected int mBlendFunctionDestination = IShape.BLENDFUNCTION_DESTINATION_DEFAULT;
- protected boolean mBlendingEnabled = false;
+ protected boolean mBlendingEnabled;
protected ShaderProgram mShaderProgram;
@@ -44,6 +43,12 @@ public Shape(final float pX, final float pY, final ShaderProgram pShaderProgram)
this.mShaderProgram = pShaderProgram;
}
+ public Shape(final float pX, final float pY, final float pWidth, final float pHeight, final ShaderProgram pShaderProgram) {
+ super(pX, pY, pWidth, pHeight);
+
+ this.mShaderProgram = pShaderProgram;
+ }
+
// ===========================================================
// Getter & Setter
// ===========================================================
@@ -107,7 +112,7 @@ public VertexBufferObjectManager getVertexBufferObjectManager() {
@Override
protected void preDraw(final GLState pGLState, final Camera pCamera) {
- if(this.mBlendingEnabled) {
+ if (this.mBlendingEnabled) {
pGLState.enableBlend();
pGLState.blendFunction(this.mBlendFunctionSource, this.mBlendFunctionDestination);
}
@@ -115,14 +120,30 @@ protected void preDraw(final GLState pGLState, final Camera pCamera) {
@Override
protected void postDraw(final GLState pGLState, final Camera pCamera) {
- if(this.mBlendingEnabled) {
+ if (this.mBlendingEnabled) {
pGLState.disableBlend();
}
}
@Override
- public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
- return false;
+ public void setWidth(final float pWidth) {
+ super.setWidth(pWidth);
+
+ this.onUpdateVertices();
+ }
+
+ @Override
+ public void setHeight(final float pHeight) {
+ super.setHeight(pHeight);
+
+ this.onUpdateVertices();
+ }
+
+ @Override
+ public void setSize(final float pWidth, final float pHeight) {
+ super.setSize(pWidth, pHeight);
+
+ this.onUpdateVertices();
}
@Override
@@ -138,7 +159,7 @@ public void dispose() {
super.dispose();
final IVertexBufferObject vertexBufferObject = this.getVertexBufferObject();
- if((vertexBufferObject != null) && vertexBufferObject.isAutoDispose() && !vertexBufferObject.isDisposed()) {
+ if ((vertexBufferObject != null) && vertexBufferObject.isAutoDispose() && !vertexBufferObject.isDisposed()) {
vertexBufferObject.dispose();
}
}
@@ -156,7 +177,7 @@ protected void initBlendFunction(final ITexture pTexture) {
}
protected void initBlendFunction(final TextureOptions pTextureOptions) {
- if(pTextureOptions.mPreMultiplyAlpha) {
+ if (pTextureOptions.mPreMultiplyAlpha) {
this.setBlendFunction(IShape.BLENDFUNCTION_SOURCE_PREMULTIPLYALPHA_DEFAULT, IShape.BLENDFUNCTION_DESTINATION_PREMULTIPLYALPHA_DEFAULT);
}
}
diff --git a/src/org/andengine/entity/sprite/AnimatedSprite.java b/src/org/andengine/entity/sprite/AnimatedSprite.java
index a35c8f668..40fb4bb40 100644
--- a/src/org/andengine/entity/sprite/AnimatedSprite.java
+++ b/src/org/andengine/entity/sprite/AnimatedSprite.java
@@ -11,7 +11,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:25:46 - 10.03.2010
*/
@@ -105,20 +105,20 @@ public boolean isAnimationRunning() {
protected void onManagedUpdate(final float pSecondsElapsed) {
super.onManagedUpdate(pSecondsElapsed);
- if(this.mAnimationRunning) {
+ if (this.mAnimationRunning) {
final int loopCount = this.mAnimationData.getLoopCount();
final int[] frames = this.mAnimationData.getFrames();
final long animationDuration = this.mAnimationData.getAnimationDuration();
- if(!this.mAnimationStartedFired && (this.mAnimationProgress == 0)) {
+ if (!this.mAnimationStartedFired && (this.mAnimationProgress == 0)) {
this.mAnimationStartedFired = true;
- if(frames == null) {
+ if (frames == null) {
this.setCurrentTileIndex(this.mAnimationData.getFirstFrameIndex());
} else {
this.setCurrentTileIndex(frames[0]);
}
this.mCurrentFrameIndex = 0;
- if(this.mAnimationListener != null) {
+ if (this.mAnimationListener != null) {
this.mAnimationListener.onAnimationStarted(this, loopCount);
this.mAnimationListener.onAnimationFrameChanged(this, AnimatedSprite.FRAMEINDEX_INVALID, 0);
}
@@ -126,42 +126,42 @@ protected void onManagedUpdate(final float pSecondsElapsed) {
final long nanoSecondsElapsed = (long) (pSecondsElapsed * TimeConstants.NANOSECONDS_PER_SECOND);
this.mAnimationProgress += nanoSecondsElapsed;
- if(loopCount == IAnimationData.LOOP_CONTINUOUS) {
- while(this.mAnimationProgress > animationDuration ) {
+ if (loopCount == IAnimationData.LOOP_CONTINUOUS) {
+ while (this.mAnimationProgress > animationDuration) {
this.mAnimationProgress -= animationDuration;
- if(this.mAnimationListener != null) {
+ if (this.mAnimationListener != null) {
this.mAnimationListener.onAnimationLoopFinished(this, this.mRemainingLoopCount, loopCount);
}
}
} else {
- while(this.mAnimationProgress > animationDuration) {
+ while (this.mAnimationProgress > animationDuration) {
this.mAnimationProgress -= animationDuration;
this.mRemainingLoopCount--;
- if(this.mRemainingLoopCount < 0) {
+ if (this.mRemainingLoopCount < 0) {
break;
- } else if(this.mAnimationListener != null) {
+ } else if (this.mAnimationListener != null) {
this.mAnimationListener.onAnimationLoopFinished(this, this.mRemainingLoopCount, loopCount);
}
}
}
- if((loopCount == IAnimationData.LOOP_CONTINUOUS) || (this.mRemainingLoopCount >= 0)) {
+ if ((loopCount == IAnimationData.LOOP_CONTINUOUS) || (this.mRemainingLoopCount >= 0)) {
final int newFrameIndex = this.mAnimationData.calculateCurrentFrameIndex(this.mAnimationProgress);
- if(this.mCurrentFrameIndex != newFrameIndex) {
- if(frames == null) {
+ if (this.mCurrentFrameIndex != newFrameIndex) {
+ if (frames == null) {
this.setCurrentTileIndex(this.mAnimationData.getFirstFrameIndex() + newFrameIndex);
} else {
this.setCurrentTileIndex(frames[newFrameIndex]);
}
- if(this.mAnimationListener != null) {
+ if (this.mAnimationListener != null) {
this.mAnimationListener.onAnimationFrameChanged(this, this.mCurrentFrameIndex, newFrameIndex);
}
}
this.mCurrentFrameIndex = newFrameIndex;
} else {
this.mAnimationRunning = false;
- if(this.mAnimationListener != null) {
+ if (this.mAnimationListener != null) {
this.mAnimationListener.onAnimationFinished(this);
}
}
@@ -212,7 +212,7 @@ public void animate(final long pFrameDurationEach, final int pLoopCount, final I
}
public void animate(final long[] pFrameDurations) {
- this.animate(pFrameDurations, (IAnimationListener)null);
+ this.animate(pFrameDurations, (IAnimationListener) null);
}
public void animate(final long[] pFrameDurations, final IAnimationListener pAnimationListener) {
@@ -263,7 +263,7 @@ public void animate(final long[] pFrameDurations, final int pFirstTileIndex, fin
/**
* Animate specifics frames.
- *
+ *
* @param pFrameDurations must have the same length as pFrames.
* @param pFrames indices of the frames to animate.
*/
@@ -273,7 +273,7 @@ public void animate(final long[] pFrameDurations, final int[] pFrames) {
/**
* Animate specifics frames.
- *
+ *
* @param pFrameDurations must have the same length as pFrames.
* @param pFrames indices of the frames to animate.
* @param pAnimationListener
@@ -286,7 +286,7 @@ public void animate(final long[] pFrameDurations, final int[] pFrames, final IAn
/**
* Animate specifics frames.
- *
+ *
* @param pFrameDurations must have the same length as pFrames.
* @param pFrames indices of the frames to animate.
* @param pLoop
@@ -297,7 +297,7 @@ public void animate(final long[] pFrameDurations, final int[] pFrames, final boo
/**
* Animate specifics frames.
- *
+ *
* @param pFrameDurations must have the same length as pFrames.
* @param pFrames indices of the frames to animate.
* @param pLoop
@@ -311,7 +311,7 @@ public void animate(final long[] pFrameDurations, final int[] pFrames, final boo
/**
* Animate specifics frames.
- *
+ *
* @param pFrameDurations must have the same length as pFrames.
* @param pFrames indices of the frames to animate.
* @param pLoopCount
@@ -322,7 +322,7 @@ public void animate(final long[] pFrameDurations, final int[] pFrames, final int
/**
* Animate specifics frames.
- *
+ *
* @param pFrameDurations must have the same length as pFrames.
* @param pFrames indices of the frames to animate.
* @param pLoopCount
diff --git a/src/org/andengine/entity/sprite/AnimationData.java b/src/org/andengine/entity/sprite/AnimationData.java
index 32d5a7f70..0c9ab47c9 100644
--- a/src/org/andengine/entity/sprite/AnimationData.java
+++ b/src/org/andengine/entity/sprite/AnimationData.java
@@ -2,12 +2,12 @@
import java.util.Arrays;
-import org.andengine.util.math.MathUtils;
+import org.andengine.util.adt.array.ArrayUtils;
import org.andengine.util.modifier.IModifier.DeepCopyNotSupportedException;
import org.andengine.util.time.TimeConstants;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 11:43:01 - 04.05.2012
@@ -70,7 +70,7 @@ public AnimationData(final long[] pFrameDurations, final int pFirstFrameIndex, f
/**
* Animate specifics frames.
- *
+ *
* @param pFrameDurations must have the same length as pFrames.
* @param pFrames indices of the frames to animate.
* @param pLoopCount
@@ -102,6 +102,10 @@ public IAnimationData deepCopy() throws DeepCopyNotSupportedException {
// Getter & Setter
// ===========================================================
+ public void setLoopCount(final int pLoopCount) {
+ this.mLoopCount = pLoopCount;
+ }
+
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@@ -144,8 +148,8 @@ public long getAnimationDuration() {
public int calculateCurrentFrameIndex(final long pAnimationProgress) {
final long[] frameEnds = this.mFrameEndsInNanoseconds;
final int frameCount = this.mFrameCount;
- for(int i = 0; i < frameCount; i++) {
- if(frameEnds[i] > pAnimationProgress) {
+ for (int i = 0; i < frameCount; i++) {
+ if (frameEnds[i] > pAnimationProgress) {
return i;
}
}
@@ -203,14 +207,14 @@ public void set(final long[] pFrameDurations, final int pFirstFrameIndex, final
public void set(final long[] pFrameDurations, final int pFirstFrameIndex, final int pLastFrameIndex, final int pLoopCount) {
this.set(pFrameDurations, (pLastFrameIndex - pFirstFrameIndex) + 1, null, pFirstFrameIndex, pLoopCount);
- if((pFirstFrameIndex + 1) > pLastFrameIndex) {
+ if ((pFirstFrameIndex + 1) > pLastFrameIndex) {
throw new IllegalArgumentException("An animation needs at least two tiles to animate between.");
}
}
/**
* Animate specifics frames.
- *
+ *
* @param pFrameDurations must have the same length as pFrames.
* @param pFrames indices of the frames to animate.
*/
@@ -221,7 +225,7 @@ public void set(final long[] pFrameDurations, final int[] pFrames) {
/**
* Animate specifics frames.
- *
+ *
* @param pFrameDurations must have the same length as pFrames.
* @param pFrames indices of the frames to animate.
* @param pLoop
@@ -233,7 +237,7 @@ public void set(final long[] pFrameDurations, final int[] pFrames, final boolean
/**
* Animate specifics frames.
- *
+ *
* @param pFrameDurations must have the same length as pFrames.
* @param pFrames indices of the frames to animate.
* @param pLoopCount
@@ -249,7 +253,7 @@ public void set(final IAnimationData pAnimationData) {
}
private void set(final long[] pFrameDurations, final int pFrameCount, final int[] pFrames, final int pFirstFrameIndex, final int pLoopCount) {
- if(pFrameDurations.length != pFrameCount) {
+ if (pFrameDurations.length != pFrameCount) {
throw new IllegalArgumentException("pFrameDurations does not equal pFrameCount!");
}
@@ -259,12 +263,12 @@ private void set(final long[] pFrameDurations, final int pFrameCount, final int[
this.mFirstFrameIndex = pFirstFrameIndex;
this.mLoopCount = pLoopCount;
- if((this.mFrameEndsInNanoseconds == null) || (this.mFrameCount > this.mFrameEndsInNanoseconds.length)) {
+ if ((this.mFrameEndsInNanoseconds == null) || (this.mFrameCount > this.mFrameEndsInNanoseconds.length)) {
this.mFrameEndsInNanoseconds = new long[this.mFrameCount];
}
final long[] frameEndsInNanoseconds = this.mFrameEndsInNanoseconds;
- MathUtils.arraySumInto(this.mFrameDurations, frameEndsInNanoseconds, TimeConstants.NANOSECONDS_PER_MILLISECOND);
+ ArrayUtils.sumCummulative(this.mFrameDurations, TimeConstants.NANOSECONDS_PER_MILLISECOND, frameEndsInNanoseconds);
final long lastFrameEnd = frameEndsInNanoseconds[this.mFrameCount - 1];
this.mAnimationDuration = lastFrameEnd;
@@ -274,6 +278,17 @@ private void set(final long[] pFrameDurations, final int pFrameCount, final int[
// Methods
// ===========================================================
+ /**
+ * Scales the duration of this {@link AnimationData} by a given pFactor.
+ *
+ * @param pScale
+ */
+ public void scale(final float pScale) {
+ ArrayUtils.multiply(this.mFrameDurations, pScale);
+ ArrayUtils.multiply(this.mFrameEndsInNanoseconds, pScale);
+ this.mAnimationDuration *= pScale;
+ }
+
private static long[] fillFrameDurations(final long pFrameDurationEach, final int pFrameCount) {
final long[] frameDurations = new long[pFrameCount];
Arrays.fill(frameDurations, pFrameDurationEach);
diff --git a/src/org/andengine/entity/sprite/ButtonSprite.java b/src/org/andengine/entity/sprite/ButtonSprite.java
index a97484d9b..fc6fbb9fd 100644
--- a/src/org/andengine/entity/sprite/ButtonSprite.java
+++ b/src/org/andengine/entity/sprite/ButtonSprite.java
@@ -13,7 +13,7 @@
* Note: {@link ButtonSprite} needs to be registered as a {@link ITouchArea} to the {@link Scene} via {@link Scene#registerTouchArea(ITouchArea)}, otherwise it won't be clickable.
* To make {@link ButtonSprite} function properly, you should consider setting {@link Scene#setTouchAreaBindingOnActionDownEnabled(boolean)} to true.
*
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Scott Kennedy
* @author Nicolas Gramlich
@@ -72,7 +72,7 @@ public ButtonSprite(final float pX, final float pY, final ITiledTextureRegion pT
this.mOnClickListener = pOnClickListener;
this.mStateCount = pTiledTextureRegion.getTileCount();
- switch(this.mStateCount) {
+ switch (this.mStateCount) {
case 1:
Debug.w("No " + ITextureRegion.class.getSimpleName() + " supplied for " + State.class.getSimpleName() + "." + State.PRESSED + ".");
case 2:
@@ -98,9 +98,9 @@ public boolean isEnabled() {
public void setEnabled(final boolean pEnabled) {
this.mEnabled = pEnabled;
- if(this.mEnabled && this.mState == State.DISABLED) {
+ if (this.mEnabled && this.mState == State.DISABLED) {
this.changeState(State.NORMAL);
- } else if(!this.mEnabled) {
+ } else if (!this.mEnabled) {
this.changeState(State.DISABLED);
}
}
@@ -123,16 +123,16 @@ public void setOnClickListener(final OnClickListener pOnClickListener) {
@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
- if(!this.isEnabled()) {
+ if (!this.isEnabled()) {
this.changeState(State.DISABLED);
- } else if(pSceneTouchEvent.isActionDown()) {
+ } else if (pSceneTouchEvent.isActionDown()) {
this.changeState(State.PRESSED);
- } else if(pSceneTouchEvent.isActionCancel() || !this.contains(pSceneTouchEvent.getX(), pSceneTouchEvent.getY())) {
+ } else if (pSceneTouchEvent.isActionCancel() || !this.contains(pSceneTouchEvent.getX(), pSceneTouchEvent.getY())) {
this.changeState(State.NORMAL);
- } else if(pSceneTouchEvent.isActionUp() && this.mState == State.PRESSED) {
+ } else if (pSceneTouchEvent.isActionUp() && this.mState == State.PRESSED) {
this.changeState(State.NORMAL);
- if(this.mOnClickListener != null) {
+ if (this.mOnClickListener != null) {
this.mOnClickListener.onClick(this, pTouchAreaLocalX, pTouchAreaLocalY);
}
}
@@ -142,7 +142,7 @@ public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTou
@Override
public boolean contains(final float pX, final float pY) {
- if(!this.isVisible()) {
+ if (!this.isVisible()) {
return false;
} else {
return super.contains(pX, pY);
@@ -154,14 +154,14 @@ public boolean contains(final float pX, final float pY) {
// ===========================================================
private void changeState(final State pState) {
- if(pState == this.mState) {
+ if (pState == this.mState) {
return;
}
this.mState = pState;
final int stateTiledTextureRegionIndex = this.mState.getTiledTextureRegionIndex();
- if(stateTiledTextureRegionIndex >= this.mStateCount) {
+ if (stateTiledTextureRegionIndex >= this.mStateCount) {
this.setCurrentTileIndex(0);
Debug.w(this.getClass().getSimpleName() + " changed its " + State.class.getSimpleName() + " to " + pState.toString() + ", which doesn't have a " + ITextureRegion.class.getSimpleName() + " supplied. Applying default " + ITextureRegion.class.getSimpleName() + ".");
} else {
diff --git a/src/org/andengine/entity/sprite/DiamondSprite.java b/src/org/andengine/entity/sprite/DiamondSprite.java
index 2047c516f..2d6eaaa1b 100644
--- a/src/org/andengine/entity/sprite/DiamondSprite.java
+++ b/src/org/andengine/entity/sprite/DiamondSprite.java
@@ -22,7 +22,7 @@
* +--------+
*
*
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 20:26:32 - 24.10.2011
diff --git a/src/org/andengine/entity/sprite/IAnimationData.java b/src/org/andengine/entity/sprite/IAnimationData.java
index e2c77a6f1..952a4f685 100644
--- a/src/org/andengine/entity/sprite/IAnimationData.java
+++ b/src/org/andengine/entity/sprite/IAnimationData.java
@@ -3,7 +3,7 @@
import org.andengine.util.modifier.IModifier.DeepCopyNotSupportedException;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 16:59:57 - 03.05.2012
@@ -18,7 +18,7 @@ public interface IAnimationData {
// ===========================================================
// Methods
// ===========================================================
-
+
public int[] getFrames();
public long[] getFrameDurations();
public int getLoopCount();
@@ -51,14 +51,14 @@ public interface IAnimationData {
/**
* Animate specifics frames.
- *
+ *
* @param pFrameDurations must have the same length as pFrames.
* @param pFrames indices of the frames to animate.
*/
public void set(final long[] pFrameDurations, final int[] pFrames);
/**
* Animate specifics frames.
- *
+ *
* @param pFrameDurations must have the same length as pFrames.
* @param pFrames indices of the frames to animate.
* @param pLoop
@@ -66,7 +66,7 @@ public interface IAnimationData {
public void set(final long[] pFrameDurations, final int[] pFrames, final boolean pLoop);
/**
* Animate specifics frames.
- *
+ *
* @param pFrameDurations must have the same length as pFrames.
* @param pFrames indices of the frames to animate.
* @param pLoopCount
diff --git a/src/org/andengine/entity/sprite/NineSliceSprite.java b/src/org/andengine/entity/sprite/NineSliceSprite.java
new file mode 100644
index 000000000..a6ac414ef
--- /dev/null
+++ b/src/org/andengine/entity/sprite/NineSliceSprite.java
@@ -0,0 +1,261 @@
+package org.andengine.entity.sprite;
+
+import org.andengine.entity.Entity;
+import org.andengine.entity.sprite.batch.SpriteBatch;
+import org.andengine.opengl.shader.PositionColorTextureCoordinatesShaderProgram;
+import org.andengine.opengl.shader.ShaderProgram;
+import org.andengine.opengl.texture.ITexture;
+import org.andengine.opengl.texture.region.ITextureRegion;
+import org.andengine.opengl.texture.region.TextureRegion;
+import org.andengine.opengl.vbo.VertexBufferObjectManager;
+
+/**
+ * (c) 2012 Zynga Inc.
+ *
+ * @author Nicolas Gramlich
+ * @since 16:50:42 - 25.04.2012
+ */
+public class NineSliceSprite extends Entity {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ private static final int NINESLICESPRITE_CHILD_COUNT = 9;
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ protected final ITextureRegion mTextureRegion;
+
+ protected final ITextureRegion mTopLeftTextureRegion;
+ protected final ITextureRegion mTopCenterTextureRegion;
+ protected final ITextureRegion mTopRightTextureRegion;
+ protected final ITextureRegion mCenterLeftTextureRegion;
+ protected final ITextureRegion mCenterTextureRegion;
+ protected final ITextureRegion mCenterRightTextureRegion;
+ protected final ITextureRegion mBottomLeftTextureRegion;
+ protected final ITextureRegion mBottomCenterTextureRegion;
+ protected final ITextureRegion mBottomRightTextureRegion;
+
+ protected final SpriteBatch mSpriteBatch;
+
+ protected float mInsetLeft;
+ protected float mInsetTop;
+ protected float mInsetRight;
+ protected float mInsetBottom;
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ public NineSliceSprite(final float pX, final float pY, final ITextureRegion pTextureRegion, final float pInsetLeft, final float pInsetTop, final float pInsetRight, final float pInsetBottom, final VertexBufferObjectManager pVertexBufferObjectManager) {
+ this(pX, pY, pTextureRegion, pInsetLeft, pInsetTop, pInsetRight, pInsetBottom, pVertexBufferObjectManager, PositionColorTextureCoordinatesShaderProgram.getInstance());
+ }
+
+ public NineSliceSprite(final float pX, final float pY, final ITextureRegion pTextureRegion, final float pInsetLeft, final float pInsetTop, final float pInsetRight, final float pInsetBottom, final VertexBufferObjectManager pVertexBufferObjectManager, final ShaderProgram pShaderProgram) {
+ this(pX, pY, pTextureRegion.getWidth(), pTextureRegion.getHeight(), pTextureRegion, pInsetLeft, pInsetTop, pInsetRight, pInsetBottom, pVertexBufferObjectManager, pShaderProgram);
+ }
+
+ public NineSliceSprite(final float pX, final float pY, final float pWidth, final float pHeight, final ITextureRegion pTextureRegion, final float pInsetLeft, final float pInsetTop, final float pInsetRight, final float pInsetBottom, final VertexBufferObjectManager pVertexBufferObjectManager) {
+ this(pX, pY, pWidth, pHeight, pTextureRegion, pInsetLeft, pInsetTop, pInsetRight, pInsetBottom, pVertexBufferObjectManager, PositionColorTextureCoordinatesShaderProgram.getInstance());
+ }
+
+ public NineSliceSprite(final float pX, final float pY, final float pWidth, final float pHeight, final ITextureRegion pTextureRegion, final float pInsetLeft, final float pInsetTop, final float pInsetRight, final float pInsetBottom, final VertexBufferObjectManager pVertexBufferObjectManager, final ShaderProgram pShaderProgram) {
+ super(pX, pY, pWidth, pHeight);
+
+ this.mTextureRegion = pTextureRegion;
+ this.mInsetLeft = pInsetLeft;
+ this.mInsetTop = pInsetTop;
+ this.mInsetRight = pInsetRight;
+ this.mInsetBottom = pInsetBottom;
+
+ final ITexture texture = pTextureRegion.getTexture();
+ this.mSpriteBatch = new SpriteBatch(texture, NINESLICESPRITE_CHILD_COUNT, pVertexBufferObjectManager, pShaderProgram);
+
+ this.mTopLeftTextureRegion = new TextureRegion(texture, 0, 0, 0, 0);
+ this.mTopCenterTextureRegion = new TextureRegion(texture, 0, 0, 0, 0);
+ this.mTopRightTextureRegion = new TextureRegion(texture, 0, 0, 0, 0);
+ this.mCenterLeftTextureRegion = new TextureRegion(texture, 0, 0, 0, 0);
+ this.mCenterTextureRegion = new TextureRegion(texture, 0, 0, 0, 0);
+ this.mCenterRightTextureRegion = new TextureRegion(texture, 0, 0, 0, 0);
+ this.mBottomLeftTextureRegion = new TextureRegion(texture, 0, 0, 0, 0);
+ this.mBottomCenterTextureRegion = new TextureRegion(texture, 0, 0, 0, 0);
+ this.mBottomRightTextureRegion = new TextureRegion(texture, 0, 0, 0, 0);
+
+ this.updateTextureRegions();
+ this.updateVertices();
+
+ this.attachChild(this.mSpriteBatch);
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ public float getInsetLeft() {
+ return this.mInsetLeft;
+ }
+
+ public void setInsetLeft(final float pInsetLeft) {
+ this.mInsetLeft = pInsetLeft;
+
+ this.updateTextureRegions();
+ this.updateVertices();
+ }
+
+ public float getInsetTop() {
+ return this.mInsetTop;
+ }
+
+ public void setInsetTop(final float pInsetTop) {
+ this.mInsetTop = pInsetTop;
+
+ this.updateTextureRegions();
+ this.updateVertices();
+ }
+
+ public float getInsetRight() {
+ return this.mInsetRight;
+ }
+
+ public void setInsetRight(final float pInsetRight) {
+ this.mInsetRight = pInsetRight;
+
+ this.updateTextureRegions();
+ this.updateVertices();
+ }
+
+ public float getInsetBottom() {
+ return this.mInsetBottom;
+ }
+
+ public void setInsetBottom(final float pInsetBottom) {
+ this.mInsetBottom = pInsetBottom;
+
+ this.updateTextureRegions();
+ this.updateVertices();
+ }
+
+ public void setInsets(final float pInsetLeft, final float pInsetTop, final float pInsetRight, final float pInsetBottom) {
+ this.mInsetLeft = pInsetLeft;
+ this.mInsetTop = pInsetTop;
+ this.mInsetRight = pInsetRight;
+ this.mInsetBottom = pInsetBottom;
+
+ this.updateTextureRegions();
+ this.updateVertices();
+ }
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ @Override
+ public void setWidth(final float pWidth) {
+ super.setWidth(pWidth);
+
+ this.updateVertices();
+ }
+
+ @Override
+ public void setHeight(final float pHeight) {
+ super.setHeight(pHeight);
+
+ this.updateVertices();
+ }
+
+ @Override
+ public void setSize(final float pWidth, final float pHeight) {
+ super.setSize(pWidth, pHeight);
+
+ this.updateVertices();
+ }
+
+ @Override
+ protected void onUpdateColor() {
+ this.updateVertices();
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+
+ this.mSpriteBatch.dispose();
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ private void updateTextureRegions() {
+ final float baseX = this.mTextureRegion.getTextureX();
+ final float baseY = this.mTextureRegion.getTextureY();
+ final float baseWidth = this.mTextureRegion.getWidth();
+ final float baseHeight = this.mTextureRegion.getHeight();
+
+ final float centerWidth = baseWidth - this.mInsetLeft - this.mInsetRight;
+ final float centerHeight = baseHeight - this.mInsetTop - this.mInsetBottom;
+
+ /* Cache some variables. */
+ final float leftX = baseX;
+ final float centerX = baseX + this.mInsetLeft;
+ final float rightX = (baseX + baseWidth) - this.mInsetRight;
+
+ /* Top. */
+ final float topY = baseY;
+ this.mTopLeftTextureRegion.set(leftX, topY, this.mInsetLeft, this.mInsetTop);
+ this.mTopCenterTextureRegion.set(centerX, topY, centerWidth, this.mInsetTop);
+ this.mTopRightTextureRegion.set(rightX, topY, this.mInsetRight, this.mInsetTop);
+
+ /* Center. */
+ final float centerY = baseY + this.mInsetTop;
+ this.mCenterLeftTextureRegion.set(leftX, centerY, this.mInsetLeft, centerHeight);
+ this.mCenterTextureRegion.set(centerX, centerY, centerWidth, centerHeight);
+ this.mCenterRightTextureRegion.set(rightX, centerY, this.mInsetRight, centerHeight);
+
+ /* Bottom. */
+ final float bottomY = (baseY + baseHeight) - this.mInsetBottom;
+ this.mBottomLeftTextureRegion.set(leftX, bottomY, this.mInsetLeft, this.mInsetBottom);
+ this.mBottomCenterTextureRegion.set(centerX, bottomY, centerWidth, this.mInsetBottom);
+ this.mBottomRightTextureRegion.set(rightX, bottomY, this.mInsetRight, this.mInsetBottom);
+ }
+
+ private void updateVertices() {
+ this.mSpriteBatch.reset();
+
+ final float color = this.mColor.getABGRPackedFloat();
+
+ final float centerWidth = this.mWidth - this.mInsetLeft - this.mInsetRight;
+ final float centerHeight = this.mHeight - this.mInsetTop - this.mInsetBottom;
+
+ /* Cache some variables. */
+ final float leftX = 0;
+ final float centerX = this.mInsetLeft;
+ final float rightX = this.mWidth - this.mInsetRight;
+
+ /* Top. */
+ final float topY = this.mHeight - this.mInsetTop;
+ this.mSpriteBatch.draw(this.mTopLeftTextureRegion, leftX, topY, this.mInsetLeft, this.mInsetTop, color);
+ this.mSpriteBatch.draw(this.mTopCenterTextureRegion, centerX, topY, centerWidth, this.mInsetTop, color);
+ this.mSpriteBatch.draw(this.mTopRightTextureRegion, rightX, topY, this.mInsetRight, this.mInsetTop, color);
+
+ /* Center. */
+ final float centerY = this.mInsetBottom;
+ this.mSpriteBatch.draw(this.mCenterLeftTextureRegion, leftX, centerY, this.mInsetLeft, centerHeight, color);
+ this.mSpriteBatch.draw(this.mCenterTextureRegion, centerX, centerY, centerWidth, centerHeight, color);
+ this.mSpriteBatch.draw(this.mCenterRightTextureRegion, rightX, centerY, this.mInsetRight, centerHeight, color);
+
+ /* Bottom. */
+ final float bottomY = 0;
+ this.mSpriteBatch.draw(this.mBottomLeftTextureRegion, leftX, bottomY, this.mInsetLeft, this.mInsetBottom, color);
+ this.mSpriteBatch.draw(this.mBottomCenterTextureRegion, centerX, bottomY, centerWidth, this.mInsetBottom, color);
+ this.mSpriteBatch.draw(this.mBottomRightTextureRegion, rightX, bottomY, this.mInsetRight, this.mInsetBottom, color);
+
+ this.mSpriteBatch.submit();
+ }
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
diff --git a/src/org/andengine/entity/sprite/Sprite.java b/src/org/andengine/entity/sprite/Sprite.java
index 12c7fa25e..c4bb4135a 100644
--- a/src/org/andengine/entity/sprite/Sprite.java
+++ b/src/org/andengine/entity/sprite/Sprite.java
@@ -1,7 +1,7 @@
package org.andengine.entity.sprite;
import org.andengine.engine.camera.Camera;
-import org.andengine.entity.shape.RectangularShape;
+import org.andengine.entity.shape.Shape;
import org.andengine.entity.sprite.vbo.HighPerformanceSpriteVertexBufferObject;
import org.andengine.entity.sprite.vbo.ISpriteVertexBufferObject;
import org.andengine.opengl.shader.PositionColorTextureCoordinatesShaderProgram;
@@ -19,11 +19,11 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 19:22:38 - 09.03.2010
*/
-public class Sprite extends RectangularShape {
+public class Sprite extends Shape {
// ===========================================================
// Constants
// ===========================================================
@@ -103,15 +103,16 @@ public Sprite(final float pX, final float pY, final float pWidth, final float pH
}
public Sprite(final float pX, final float pY, final float pWidth, final float pHeight, final ITextureRegion pTextureRegion, final ISpriteVertexBufferObject pSpriteVertexBufferObject, final ShaderProgram pShaderProgram) {
- super(pX, pY, pWidth, pHeight, pShaderProgram);
-
+ super(pX, pY, pShaderProgram);
+
this.mTextureRegion = pTextureRegion;
this.mSpriteVertexBufferObject = pSpriteVertexBufferObject;
this.setBlendingEnabled(true);
this.initBlendFunction(pTextureRegion);
-
- this.onUpdateVertices();
+
+ this.setSize(pWidth, pHeight);
+
this.onUpdateColor();
this.onUpdateTextureCoordinates();
}
@@ -129,7 +130,7 @@ public boolean isFlippedHorizontal() {
}
public void setFlippedHorizontal(final boolean pFlippedHorizontal) {
- if(this.mFlippedHorizontal != pFlippedHorizontal) {
+ if (this.mFlippedHorizontal != pFlippedHorizontal) {
this.mFlippedHorizontal = pFlippedHorizontal;
this.onUpdateTextureCoordinates();
@@ -141,7 +142,7 @@ public boolean isFlippedVertical() {
}
public void setFlippedVertical(final boolean pFlippedVertical) {
- if(this.mFlippedVertical != pFlippedVertical) {
+ if (this.mFlippedVertical != pFlippedVertical) {
this.mFlippedVertical = pFlippedVertical;
this.onUpdateTextureCoordinates();
@@ -149,7 +150,7 @@ public void setFlippedVertical(final boolean pFlippedVertical) {
}
public void setFlipped(final boolean pFlippedHorizontal, final boolean pFlippedVertical) {
- if((this.mFlippedHorizontal != pFlippedHorizontal) || (this.mFlippedVertical != pFlippedVertical)) {
+ if ((this.mFlippedHorizontal != pFlippedHorizontal) || (this.mFlippedVertical != pFlippedVertical)) {
this.mFlippedHorizontal = pFlippedHorizontal;
this.mFlippedVertical = pFlippedVertical;
diff --git a/src/org/andengine/entity/sprite/TiledSprite.java b/src/org/andengine/entity/sprite/TiledSprite.java
index 5290fd710..0bf979d8d 100644
--- a/src/org/andengine/entity/sprite/TiledSprite.java
+++ b/src/org/andengine/entity/sprite/TiledSprite.java
@@ -16,7 +16,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 19:30:13 - 09.03.2010
*/
diff --git a/src/org/andengine/entity/sprite/UncoloredSprite.java b/src/org/andengine/entity/sprite/UncoloredSprite.java
index 5f97a4fee..915f3629c 100644
--- a/src/org/andengine/entity/sprite/UncoloredSprite.java
+++ b/src/org/andengine/entity/sprite/UncoloredSprite.java
@@ -16,7 +16,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 19:22:38 - 09.03.2010
*/
diff --git a/src/org/andengine/entity/sprite/UniformColorSprite.java b/src/org/andengine/entity/sprite/UniformColorSprite.java
index a37e4013c..0135749a0 100644
--- a/src/org/andengine/entity/sprite/UniformColorSprite.java
+++ b/src/org/andengine/entity/sprite/UniformColorSprite.java
@@ -18,7 +18,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 19:22:38 - 09.03.2010
*/
@@ -60,7 +60,7 @@ public UniformColorSprite(final float pX, final float pY, final ITextureRegion p
public UniformColorSprite(final float pX, final float pY, final ITextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
this(pX, pY, pTextureRegion.getWidth(), pTextureRegion.getHeight(), pTextureRegion, pVertexBufferObjectManager, pDrawType);
}
-
+
public UniformColorSprite(final float pX, final float pY, final ITextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType, final ShaderProgram pShaderProgram) {
this(pX, pY, pTextureRegion.getWidth(), pTextureRegion.getHeight(), pTextureRegion, pVertexBufferObjectManager, pDrawType, pShaderProgram);
}
@@ -68,7 +68,7 @@ public UniformColorSprite(final float pX, final float pY, final ITextureRegion p
public UniformColorSprite(final float pX, final float pY, final ITextureRegion pTextureRegion, final IUniformColorSpriteVertexBufferObject pVertexBufferObject) {
this(pX, pY, pTextureRegion.getWidth(), pTextureRegion.getHeight(), pTextureRegion, pVertexBufferObject);
}
-
+
public UniformColorSprite(final float pX, final float pY, final ITextureRegion pTextureRegion, final IUniformColorSpriteVertexBufferObject pVertexBufferObject, final ShaderProgram pShaderProgram) {
this(pX, pY, pTextureRegion.getWidth(), pTextureRegion.getHeight(), pTextureRegion, pVertexBufferObject, pShaderProgram);
}
@@ -76,7 +76,7 @@ public UniformColorSprite(final float pX, final float pY, final ITextureRegion p
public UniformColorSprite(final float pX, final float pY, final float pWidth, final float pHeight, final ITextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager) {
this(pX, pY, pWidth, pHeight, pTextureRegion, pVertexBufferObjectManager, DrawType.STATIC);
}
-
+
public UniformColorSprite(final float pX, final float pY, final float pWidth, final float pHeight, final ITextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager, final ShaderProgram pShaderProgram) {
this(pX, pY, pWidth, pHeight, pTextureRegion, pVertexBufferObjectManager, DrawType.STATIC, pShaderProgram);
}
@@ -105,6 +105,11 @@ public UniformColorSprite(final float pX, final float pY, final float pWidth, fi
// Methods for/from SuperClass/Interfaces
// ===========================================================
+ @Override
+ protected void onUpdateColor() {
+ /* Nothing. */
+ }
+
@Override
protected void preDraw(final GLState pGLState, final Camera pCamera) {
super.preDraw(pGLState, pCamera);
diff --git a/src/org/andengine/entity/sprite/batch/DynamicSpriteBatch.java b/src/org/andengine/entity/sprite/batch/DynamicSpriteBatch.java
index 75a8720eb..a0ccf03fd 100644
--- a/src/org/andengine/entity/sprite/batch/DynamicSpriteBatch.java
+++ b/src/org/andengine/entity/sprite/batch/DynamicSpriteBatch.java
@@ -7,7 +7,7 @@
import org.andengine.opengl.vbo.VertexBufferObjectManager;
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 21:48:21 - 27.07.2011
@@ -90,7 +90,7 @@ public DynamicSpriteBatch(final float pX, final float pY, final ITexture pTextur
protected void begin() {
super.begin();
- if(this.onUpdateSpriteBatch()) {
+ if (this.onUpdateSpriteBatch()) {
this.submit();
}
}
diff --git a/src/org/andengine/entity/sprite/batch/SpriteBatch.java b/src/org/andengine/entity/sprite/batch/SpriteBatch.java
index efff62b7a..e5b2e93d8 100644
--- a/src/org/andengine/entity/sprite/batch/SpriteBatch.java
+++ b/src/org/andengine/entity/sprite/batch/SpriteBatch.java
@@ -1,7 +1,7 @@
package org.andengine.entity.sprite.batch;
import org.andengine.engine.camera.Camera;
-import org.andengine.entity.shape.IShape;
+import org.andengine.entity.IEntity;
import org.andengine.entity.shape.Shape;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.sprite.batch.vbo.HighPerformanceSpriteBatchVertexBufferObject;
@@ -16,18 +16,18 @@
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributesBuilder;
+import org.andengine.util.adt.color.ColorUtils;
import org.andengine.util.adt.transformation.Transformation;
-import org.andengine.util.color.ColorUtils;
import android.opengl.GLES20;
/**
* TODO TRY DEGENERATE TRIANGLES!
* TODO Check if there is this multiple-of-X-byte(?) alignment optimization?
- *
+ *
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 11:45:48 - 14.06.2011
*/
@@ -130,6 +130,10 @@ public SpriteBatch(final float pX, final float pY, final ITexture pTexture, fina
// Getter & Setter
// ===========================================================
+ public int getCapacity() {
+ return this.mCapacity;
+ }
+
public int getIndex() {
return this.mIndex;
}
@@ -162,7 +166,7 @@ public ISpriteBatchVertexBufferObject getVertexBufferObject() {
}
@Override
- public boolean collidesWith(final IShape pOtherShape) {
+ public boolean collidesWith(final IEntity pOtherEntity) {
return false;
}
@@ -180,7 +184,7 @@ protected void onUpdateVertices() {
protected void preDraw(final GLState pGLState, final Camera pCamera) {
super.preDraw(pGLState, pCamera);
- if(this.mBlendingEnabled) {
+ if (this.mBlendingEnabled) {
pGLState.enableBlend();
pGLState.blendFunction(this.mBlendFunctionSource, this.mBlendFunctionDestination);
}
@@ -203,7 +207,7 @@ protected void draw(final GLState pGLState, final Camera pCamera) {
protected void postDraw(final GLState pGLState, final Camera pCamera) {
this.mSpriteBatchVertexBufferObject.unbind(pGLState, this.mShaderProgram);
- if(this.mBlendingEnabled) {
+ if (this.mBlendingEnabled) {
pGLState.disableBlend();
}
@@ -221,7 +225,7 @@ public void reset() {
public void dispose() {
super.dispose();
- if(this.mSpriteBatchVertexBufferObject != null && this.mSpriteBatchVertexBufferObject.isAutoDispose() && !this.mSpriteBatchVertexBufferObject.isDisposed()) {
+ if (this.mSpriteBatchVertexBufferObject != null && this.mSpriteBatchVertexBufferObject.isAutoDispose() && !this.mSpriteBatchVertexBufferObject.isDisposed()) {
this.mSpriteBatchVertexBufferObject.dispose();
}
}
@@ -250,6 +254,12 @@ public void draw(final ITextureRegion pTextureRegion, final float pX, final floa
this.mIndex++;
}
+ public void drawWithoutChecks(final ITextureRegion pTextureRegion, final float pX, final float pY, final float pWidth, final float pHeight, final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
+ this.add(pTextureRegion, pX, pY, pWidth, pHeight, pRed, pGreen, pBlue, pAlpha);
+
+ this.mIndex++;
+ }
+
/**
* @see {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, float, float, float)}.
*/
@@ -262,21 +272,12 @@ public void draw(final ITextureRegion pTextureRegion, final float pX, final floa
this.mIndex++;
}
- /**
- * @see {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, float, float, float)}.
- */
public void drawWithoutChecks(final ITextureRegion pTextureRegion, final float pX, final float pY, final float pWidth, final float pHeight, final float pColorABGRPackedInt) {
this.add(pTextureRegion, pX, pY, pWidth, pHeight, pColorABGRPackedInt);
this.mIndex++;
}
- public void drawWithoutChecks(final ITextureRegion pTextureRegion, final float pX, final float pY, final float pWidth, final float pHeight, final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
- this.add(pTextureRegion, pX, pY, pWidth, pHeight, pRed, pGreen, pBlue, pAlpha);
-
- this.mIndex++;
- }
-
/**
* @see {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, float, float, float, float, float, float)}.
*/
@@ -353,75 +354,102 @@ public void drawWithoutChecks(final ITextureRegion pTextureRegion, final float p
* @see {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, float, float, float)} {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, Transformation, float)}.
*/
public void draw(final Sprite pSprite) {
- this.draw(pSprite, pSprite.getColor().getABGRPackedFloat());
+ this.draw(pSprite.getTextureRegion(), pSprite, pSprite.getColor().getABGRPackedFloat());
+ }
+
+ public void drawWithoutChecks(final Sprite pSprite) {
+ this.drawWithoutChecks(pSprite.getTextureRegion(), pSprite, pSprite.getColor().getABGRPackedFloat());
}
/**
* @see {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, float, float, float, float, float, float)} {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, Transformation, float, float, float, float)}.
*/
public void draw(final Sprite pSprite, final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
- if(pSprite.isVisible()) {
- this.assertCapacity();
-
- final ITextureRegion textureRegion = pSprite.getTextureRegion();
- this.assertTexture(textureRegion);
-
- if(pSprite.isRotatedOrScaledOrSkewed()) {
- this.add(textureRegion, pSprite.getWidth(), pSprite.getHeight(), pSprite.getLocalToParentTransformation(), pRed, pGreen, pBlue, pAlpha);
- } else {
- this.add(textureRegion, pSprite.getX(), pSprite.getY(), pSprite.getWidth(), pSprite.getHeight(), pRed, pGreen, pBlue, pAlpha);
- }
+ this.draw(pSprite.getTextureRegion(), pSprite, pRed, pGreen, pBlue, pAlpha);
+ }
- this.mIndex++;
- }
+ public void drawWithoutChecks(final Sprite pSprite, final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
+ this.drawWithoutChecks(pSprite.getTextureRegion(), pSprite, pRed, pGreen, pBlue, pAlpha);
}
/**
* @see {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, float, float, float)} {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, Transformation, float, float, float, float)}.
*/
public void draw(final Sprite pSprite, final float pColorABGRPackedInt) {
- if(pSprite.isVisible()) {
+ this.draw(pSprite.getTextureRegion(), pSprite, pColorABGRPackedInt);
+ }
+
+ public void drawWithoutChecks(final Sprite pSprite, final float pColorABGRPackedInt) {
+ this.drawWithoutChecks(pSprite.getTextureRegion(), pSprite, pColorABGRPackedInt);
+ }
+
+ /**
+ * @see {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, float, float, float)} {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, Transformation, float)}.
+ */
+ public void draw(final ITextureRegion pTextureRegion, final IEntity pEntity) {
+ this.draw(pTextureRegion, pEntity, pEntity.getColor().getABGRPackedFloat());
+ }
+
+ public void drawWithoutChecks(final ITextureRegion pTextureRegion, final IEntity pEntity) {
+ this.drawWithoutChecks(pTextureRegion, pEntity, pEntity.getColor().getABGRPackedFloat());
+ }
+
+ /**
+ * @see {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, float, float, float, float, float, float)} {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, Transformation, float, float, float, float)}.
+ */
+ public void draw(final ITextureRegion pTextureRegion, final IEntity pEntity, final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
+ if (pEntity.isVisible()) {
this.assertCapacity();
- final ITextureRegion textureRegion = pSprite.getTextureRegion();
- this.assertTexture(textureRegion);
+ this.assertTexture(pTextureRegion);
- if(pSprite.isRotatedOrScaledOrSkewed()) {
- this.addWithPackedColor(textureRegion, pSprite.getWidth(), pSprite.getHeight(), pSprite.getLocalToParentTransformation(), pColorABGRPackedInt);
+ if (pEntity.isRotatedOrScaledOrSkewed()) {
+ this.add(pTextureRegion, pEntity.getWidth(), pEntity.getHeight(), pEntity.getLocalToParentTransformation(), pRed, pGreen, pBlue, pAlpha);
} else {
- this.addWithPackedColor(textureRegion, pSprite.getX(), pSprite.getY(), pSprite.getWidth(), pSprite.getHeight(), pColorABGRPackedInt);
+ this.add(pTextureRegion, pEntity.getX(), pEntity.getY(), pEntity.getWidth(), pEntity.getHeight(), pRed, pGreen, pBlue, pAlpha);
}
this.mIndex++;
}
}
- public void drawWithoutChecks(final Sprite pSprite) {
- this.drawWithoutChecks(pSprite, pSprite.getColor().getABGRPackedFloat());
+ public void drawWithoutChecks(final ITextureRegion pTextureRegion, final IEntity pEntity, final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
+ if (pEntity.isVisible()) {
+ if (pEntity.isRotatedOrScaledOrSkewed()) {
+ this.add(pTextureRegion, pEntity.getWidth(), pEntity.getHeight(), pEntity.getLocalToParentTransformation(), pRed, pGreen, pBlue, pAlpha);
+ } else {
+ this.add(pTextureRegion, pEntity.getX(), pEntity.getY(), pEntity.getWidth(), pEntity.getHeight(), pRed, pGreen, pBlue, pAlpha);
+ }
+
+ this.mIndex++;
+ }
}
- public void drawWithoutChecks(final Sprite pSprite, final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
- if(pSprite.isVisible()) {
- final ITextureRegion textureRegion = pSprite.getTextureRegion();
+ /**
+ * @see {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, float, float, float)} {@link SpriteBatchVertexBufferObject#add(ITextureRegion, float, float, Transformation, float, float, float, float)}.
+ */
+ public void draw(final ITextureRegion pTextureRegion, final IEntity pEntity, final float pColorABGRPackedInt) {
+ if (pEntity.isVisible()) {
+ this.assertCapacity();
- if(pSprite.isRotatedOrScaledOrSkewed()) {
- this.add(textureRegion, pSprite.getWidth(), pSprite.getHeight(), pSprite.getLocalToParentTransformation(), pRed, pGreen, pBlue, pAlpha);
+ this.assertTexture(pTextureRegion);
+
+ if (pEntity.isRotatedOrScaledOrSkewed()) {
+ this.addWithPackedColor(pTextureRegion, pEntity.getWidth(), pEntity.getHeight(), pEntity.getLocalToParentTransformation(), pColorABGRPackedInt);
} else {
- this.add(textureRegion, pSprite.getX(), pSprite.getY(), pSprite.getWidth(), pSprite.getHeight(), pRed, pGreen, pBlue, pAlpha);
+ this.addWithPackedColor(pTextureRegion, pEntity.getX(), pEntity.getY(), pEntity.getWidth(), pEntity.getHeight(), pColorABGRPackedInt);
}
this.mIndex++;
}
}
- public void drawWithoutChecks(final Sprite pSprite, final float pColorABGRPackedInt) {
- if(pSprite.isVisible()) {
- final ITextureRegion textureRegion = pSprite.getTextureRegion();
-
- if(pSprite.isRotatedOrScaledOrSkewed()) {
- this.addWithPackedColor(textureRegion, pSprite.getWidth(), pSprite.getHeight(), pSprite.getLocalToParentTransformation(), pColorABGRPackedInt);
+ public void drawWithoutChecks(final ITextureRegion pTextureRegion, final IEntity pEntity, final float pColorABGRPackedInt) {
+ if (pEntity.isVisible()) {
+ if (pEntity.isRotatedOrScaledOrSkewed()) {
+ this.addWithPackedColor(pTextureRegion, pEntity.getWidth(), pEntity.getHeight(), pEntity.getLocalToParentTransformation(), pColorABGRPackedInt);
} else {
- this.addWithPackedColor(textureRegion, pSprite.getX(), pSprite.getY(), pSprite.getWidth(), pSprite.getHeight(), pColorABGRPackedInt);
+ this.addWithPackedColor(pTextureRegion, pEntity.getX(), pEntity.getY(), pEntity.getWidth(), pEntity.getHeight(), pColorABGRPackedInt);
}
this.mIndex++;
@@ -442,20 +470,20 @@ protected void onSubmit() {
}
private void assertCapacity(final int pIndex) {
- if(pIndex >= this.mCapacity) {
- throw new IllegalStateException("This supplied pIndex: '" + pIndex + "' is exceeding the capacity: '" + this.mCapacity + "' of this SpriteBatch!");
+ if (pIndex >= this.mCapacity) {
+ throw new IllegalStateException("This supplied pIndex: '" + pIndex + "' is exceeding the capacity: '" + this.mCapacity + "' of this " + this.getClass().getSimpleName() + "!");
}
}
private void assertCapacity() {
- if(this.mIndex == this.mCapacity) {
- throw new IllegalStateException("This SpriteBatch has already reached its capacity (" + this.mCapacity + ") !");
+ if (this.mIndex == this.mCapacity) {
+ throw new IllegalStateException("This " + this.getClass().getSimpleName() + " has already reached its capacity (" + this.mCapacity + ") !");
}
}
protected void assertTexture(final ITextureRegion pTextureRegion) {
- if(pTextureRegion.getTexture() != this.mTexture) {
- throw new IllegalArgumentException("The supplied Texture does match the Texture of this SpriteBatch!");
+ if (pTextureRegion.getTexture() != this.mTexture) {
+ throw new IllegalArgumentException("The supplied Texture does match the Texture of this " + this.getClass().getSimpleName() + "!");
}
}
@@ -641,7 +669,7 @@ protected void add(final ITextureRegion pTextureRegion, final float pWidth, fina
pTransformation.transform(SpriteBatch.VERTICES_TMP);
- this.addInner(pTextureRegion, SpriteBatch.VERTICES_TMP[0], SpriteBatch.VERTICES_TMP[1], SpriteBatch.VERTICES_TMP[2], SpriteBatch.VERTICES_TMP[3], SpriteBatch.VERTICES_TMP[4], SpriteBatch.VERTICES_TMP[5], SpriteBatch.VERTICES_TMP[6], SpriteBatch.VERTICES_TMP[7], pRed, pGreen, pBlue, pAlpha);
+ this.addInner(pTextureRegion, SpriteBatch.VERTICES_TMP[0], SpriteBatch.VERTICES_TMP[1], SpriteBatch.VERTICES_TMP[2], SpriteBatch.VERTICES_TMP[3], SpriteBatch.VERTICES_TMP[4], SpriteBatch.VERTICES_TMP[5], SpriteBatch.VERTICES_TMP[6], SpriteBatch.VERTICES_TMP[7], pRed, pGreen, pBlue, pAlpha);
}
/**
@@ -666,7 +694,7 @@ protected void addWithPackedColor(final ITextureRegion pTextureRegion, final flo
pTransformation.transform(SpriteBatch.VERTICES_TMP);
- this.mSpriteBatchVertexBufferObject.addWithPackedColor(pTextureRegion, SpriteBatch.VERTICES_TMP[0], SpriteBatch.VERTICES_TMP[1], SpriteBatch.VERTICES_TMP[2], SpriteBatch.VERTICES_TMP[3], SpriteBatch.VERTICES_TMP[4], SpriteBatch.VERTICES_TMP[5], SpriteBatch.VERTICES_TMP[6], SpriteBatch.VERTICES_TMP[7], pColorABGRPackedInt);
+ this.mSpriteBatchVertexBufferObject.addWithPackedColor(pTextureRegion, SpriteBatch.VERTICES_TMP[0], SpriteBatch.VERTICES_TMP[1], SpriteBatch.VERTICES_TMP[2], SpriteBatch.VERTICES_TMP[3], SpriteBatch.VERTICES_TMP[4], SpriteBatch.VERTICES_TMP[5], SpriteBatch.VERTICES_TMP[6], SpriteBatch.VERTICES_TMP[7], pColorABGRPackedInt);
}
/**
diff --git a/src/org/andengine/entity/sprite/batch/SpriteGroup.java b/src/org/andengine/entity/sprite/batch/SpriteGroup.java
index d645ad690..85264c622 100644
--- a/src/org/andengine/entity/sprite/batch/SpriteGroup.java
+++ b/src/org/andengine/entity/sprite/batch/SpriteGroup.java
@@ -14,7 +14,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 12:10:35 - 15.06.2011
*/
@@ -124,13 +124,13 @@ public SpriteGroup(final float pX, final float pY, final ITexture pTexture, fina
// ===========================================================
/**
- * Instead use {@link SpriteGroup#attachChild(BaseSprite)}.
+ * Instead use {@link #attachChild(BaseSprite)}.
*/
@Override
@Deprecated
public void attachChild(final IEntity pEntity) throws IllegalArgumentException {
- if(pEntity instanceof Sprite) {
- this.attachChild((Sprite)pEntity);
+ if (pEntity instanceof Sprite) {
+ this.attachChild((Sprite) pEntity);
} else {
throw new IllegalArgumentException("A " + SpriteGroup.class.getSimpleName() + " can only handle children of type Sprite or subclasses of Sprite, like TiledSprite or AnimatedSprite.");
}
@@ -144,7 +144,7 @@ public void attachChild(final Sprite pSprite) {
public void attachChildren(final ArrayList extends Sprite> pSprites) {
final int baseSpriteCount = pSprites.size();
- for(int i = 0; i < baseSpriteCount; i++) {
+ for (int i = 0; i < baseSpriteCount; i++) {
this.attachChild(pSprites.get(i));
}
}
@@ -152,12 +152,12 @@ public void attachChildren(final ArrayList extends Sprite> pSprites) {
@Override
protected boolean onUpdateSpriteBatch() {
final SmartList children = this.mChildren;
- if(children == null) {
+ if (children == null) {
return false;
} else {
final int childCount = children.size();
- for(int i = 0; i < childCount; i++) {
- this.drawWithoutChecks((Sprite)children.get(i));
+ for (int i = 0; i < childCount; i++) {
+ this.drawWithoutChecks((Sprite) children.get(i));
}
return true;
}
@@ -168,7 +168,7 @@ protected boolean onUpdateSpriteBatch() {
// ===========================================================
private void assertCapacity() {
- if(this.getChildCount() >= this.mCapacity) {
+ if (this.getChildCount() >= this.mCapacity) {
throw new IllegalStateException("This " + SpriteGroup.class.getSimpleName() + " has already reached its capacity (" + this.mCapacity + ") !");
}
}
diff --git a/src/org/andengine/entity/sprite/batch/vbo/HighPerformanceSpriteBatchVertexBufferObject.java b/src/org/andengine/entity/sprite/batch/vbo/HighPerformanceSpriteBatchVertexBufferObject.java
index 037f0f799..38d67a88a 100644
--- a/src/org/andengine/entity/sprite/batch/vbo/HighPerformanceSpriteBatchVertexBufferObject.java
+++ b/src/org/andengine/entity/sprite/batch/vbo/HighPerformanceSpriteBatchVertexBufferObject.java
@@ -8,7 +8,7 @@
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 12:35:28 - 29.03.2012
@@ -73,78 +73,78 @@ public void addWithPackedColor(final ITextureRegion pTextureRegion, final float
final float u2 = pTextureRegion.getU2();
final float v2 = pTextureRegion.getV2();
- if(pTextureRegion.isRotated()) {
+ if (pTextureRegion.isRotated()) {
bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x1;
bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y1;
bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
- bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u2;
+ bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v;
bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x2;
bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y2;
bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
- bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u;
+ bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v;
bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x3;
bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y3;
bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
- bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u2;
+ bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x3;
bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y3;
bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
- bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u2;
+ bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x2;
bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y2;
bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
- bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u;
+ bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v;
bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x4;
bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y4;
bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
- bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u;
+ bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v2;
} else {
bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x1;
bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y1;
bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u;
- bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v;
+ bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x2;
bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y2;
bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u;
- bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v2;
+ bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v;
bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x3;
bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y3;
bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u2;
- bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v;
+ bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x3;
bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y3;
bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u2;
- bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v;
+ bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x2;
bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y2;
bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u;
- bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v2;
+ bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v;
bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x4;
bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y4;
bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u2;
- bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v2;
+ bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v;
}
this.mBufferDataOffset += SpriteBatch.SPRITE_SIZE;
@@ -170,78 +170,78 @@ public void addWithPackedColor(final ITextureRegion pTextureRegion, final float
final float u2 = pTextureRegion.getU2();
final float v2 = pTextureRegion.getV2();
- if(pTextureRegion.isRotated()) {
+ if (pTextureRegion.isRotated()) {
bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x1;
bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y1;
bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
- bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u2;
+ bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v;
bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x1;
bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y2;
bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
- bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u;
+ bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v;
bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x2;
bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y1;
bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
- bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u2;
+ bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x2;
bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y1;
bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
- bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u2;
+ bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x1;
bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y2;
bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
- bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u;
+ bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v;
bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x2;
bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y2;
bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
- bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u;
+ bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v2;
} else {
bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x1;
bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y1;
bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u;
- bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v;
+ bufferData[bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x1;
bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y2;
bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u;
- bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v2;
+ bufferData[bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v;
bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x2;
bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y1;
bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u2;
- bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v;
+ bufferData[bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x2;
bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y1;
bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u2;
- bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v;
+ bufferData[bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x1;
bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y2;
bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u;
- bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v2;
+ bufferData[bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v;
bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X] = x2;
bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y] = y2;
bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX] = pColorABGRPackedInt;
bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U] = u2;
- bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v2;
+ bufferData[bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V] = v;
}
this.mBufferDataOffset += SpriteBatch.SPRITE_SIZE;
diff --git a/src/org/andengine/entity/sprite/batch/vbo/ISpriteBatchVertexBufferObject.java b/src/org/andengine/entity/sprite/batch/vbo/ISpriteBatchVertexBufferObject.java
index 8e85de1e7..b59d6c97e 100644
--- a/src/org/andengine/entity/sprite/batch/vbo/ISpriteBatchVertexBufferObject.java
+++ b/src/org/andengine/entity/sprite/batch/vbo/ISpriteBatchVertexBufferObject.java
@@ -4,7 +4,7 @@
import org.andengine.opengl.vbo.IVertexBufferObject;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 12:35:06 - 29.03.2012
diff --git a/src/org/andengine/entity/sprite/batch/vbo/LowMemorySpriteBatchVertexBufferObject.java b/src/org/andengine/entity/sprite/batch/vbo/LowMemorySpriteBatchVertexBufferObject.java
index b9e00ae7f..cf3b755d7 100644
--- a/src/org/andengine/entity/sprite/batch/vbo/LowMemorySpriteBatchVertexBufferObject.java
+++ b/src/org/andengine/entity/sprite/batch/vbo/LowMemorySpriteBatchVertexBufferObject.java
@@ -10,7 +10,7 @@
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 12:34:46 - 29.03.2012
@@ -75,7 +75,7 @@ public void addWithPackedColor(final ITextureRegion pTextureRegion, final float
final float u2 = pTextureRegion.getU2();
final float v2 = pTextureRegion.getV2();
- if(pTextureRegion.isRotated()) {
+ if (pTextureRegion.isRotated()) {
bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x1);
bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y1);
bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
@@ -85,68 +85,68 @@ public void addWithPackedColor(final ITextureRegion pTextureRegion, final float
bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x2);
bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y2);
bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
- bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u2);
bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v);
bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x3);
bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y3);
bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
- bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u2);
+ bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u);
bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v2);
bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x3);
bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y3);
bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
- bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u2);
+ bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u);
bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v2);
bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x2);
bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y2);
bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
- bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u2);
bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v);
bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x4);
bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y4);
bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
- bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u2);
bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v2);
} else {
bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x1);
bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y1);
bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u);
- bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v);
+ bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v2);
bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x2);
bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y2);
bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u);
- bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v2);
+ bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v);
bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x3);
bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y3);
bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u2);
- bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v);
+ bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v2);
bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x3);
bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y3);
bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u2);
- bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v);
+ bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v2);
bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x2);
bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y2);
bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u);
- bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v2);
+ bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v);
bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x4);
bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y4);
bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u2);
- bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v2);
+ bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v);
}
this.mBufferDataOffset += SpriteBatch.SPRITE_SIZE;
@@ -172,78 +172,78 @@ public void addWithPackedColor(final ITextureRegion pTextureRegion, final float
final float u2 = pTextureRegion.getU2();
final float v2 = pTextureRegion.getV2();
- if(pTextureRegion.isRotated()) {
+ if (pTextureRegion.isRotated()) {
bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x1);
bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y1);
bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
- bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u2);
+ bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u);
bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v);
bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x1);
bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y2);
bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
- bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u2);
bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v);
bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x2);
bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y1);
bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
- bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u2);
+ bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u);
bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v2);
bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x2);
bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y1);
bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
- bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u2);
+ bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u);
bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v2);
bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x1);
bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y2);
bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
- bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u2);
bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v);
bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x2);
bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y2);
bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
- bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u2);
bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v2);
} else {
bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x1);
bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y1);
bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u);
- bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v);
+ bufferData.put(bufferDataOffset + 0 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v2);
bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x1);
bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y2);
bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u);
- bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v2);
+ bufferData.put(bufferDataOffset + 1 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v);
bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x2);
bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y1);
bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u2);
- bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v);
+ bufferData.put(bufferDataOffset + 2 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v2);
bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x2);
bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y1);
bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u2);
- bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v);
+ bufferData.put(bufferDataOffset + 3 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v2);
bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x1);
bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y2);
bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u);
- bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v2);
+ bufferData.put(bufferDataOffset + 4 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v);
bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_X, x2);
bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.VERTEX_INDEX_Y, y2);
bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.COLOR_INDEX, pColorABGRPackedInt);
bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_U, u2);
- bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v2);
+ bufferData.put(bufferDataOffset + 5 * SpriteBatch.VERTEX_SIZE + SpriteBatch.TEXTURECOORDINATES_INDEX_V, v);
}
this.mBufferDataOffset += SpriteBatch.SPRITE_SIZE;
diff --git a/src/org/andengine/entity/sprite/vbo/HighPerformanceDiamondSpriteVertexBufferObject.java b/src/org/andengine/entity/sprite/vbo/HighPerformanceDiamondSpriteVertexBufferObject.java
index 943817973..a3efc4c7c 100644
--- a/src/org/andengine/entity/sprite/vbo/HighPerformanceDiamondSpriteVertexBufferObject.java
+++ b/src/org/andengine/entity/sprite/vbo/HighPerformanceDiamondSpriteVertexBufferObject.java
@@ -7,7 +7,7 @@
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:43:22 - 28.03.2012
@@ -41,25 +41,23 @@ public HighPerformanceDiamondSpriteVertexBufferObject(final VertexBufferObjectMa
public void onUpdateVertices(final Sprite pSprite) {
final float[] bufferData = this.mBufferData;
- final float x = 0;
- final float y = 0;
- final float x2 = pSprite.getWidth(); // TODO Optimize with field access?
- final float y2 = pSprite.getHeight(); // TODO Optimize with field access?
+ final float width = pSprite.getWidth(); // TODO Optimize with field access?
+ final float height = pSprite.getHeight(); // TODO Optimize with field access?
- final float xCenter = (x + x2) * 0.5f;
- final float yCenter = (y + y2) * 0.5f;
+ final float halfWidth = width * 0.5f;
+ final float halfHeight = height * 0.5f;
- bufferData[0 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = x;
- bufferData[0 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = yCenter;
+ bufferData[0 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = halfWidth;
+ bufferData[0 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = 0;
- bufferData[1 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = xCenter;
- bufferData[1 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = y2;
+ bufferData[1 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = 0;
+ bufferData[1 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = halfHeight;
- bufferData[2 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = xCenter;
- bufferData[2 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = y;
+ bufferData[2 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = width;
+ bufferData[2 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = halfHeight;
- bufferData[3 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = x2;
- bufferData[3 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = yCenter;
+ bufferData[3 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = halfWidth;
+ bufferData[3 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = height;
this.setDirtyOnHardware();
}
@@ -75,8 +73,8 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
final float u2;
final float v2;
- if(pSprite.isFlippedVertical()) { // TODO Optimize with field access?
- if(pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedVertical()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV2();
@@ -88,7 +86,7 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
v2 = textureRegion.getV();
}
} else {
- if(pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV();
@@ -104,9 +102,21 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
final float uCenter = (u + u2) * 0.5f;
final float vCenter = (v + v2) * 0.5f;
- if(textureRegion.isRotated()) {
+ if (textureRegion.isRotated()) {
+ bufferData[0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
+ bufferData[0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = vCenter;
+
+ bufferData[1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = uCenter;
+ bufferData[1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
+
+ bufferData[2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = uCenter;
+ bufferData[2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
+
+ bufferData[3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
+ bufferData[3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = vCenter;
+ } else {
bufferData[0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = uCenter;
- bufferData[0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
+ bufferData[0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = vCenter;
@@ -115,19 +125,7 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
bufferData[2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = vCenter;
bufferData[3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = uCenter;
- bufferData[3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
- } else {
- bufferData[0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
- bufferData[0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = vCenter;
-
- bufferData[1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = uCenter;
- bufferData[1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
-
- bufferData[2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = uCenter;
- bufferData[2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
-
- bufferData[3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
- bufferData[3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = vCenter;
+ bufferData[3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
}
this.setDirtyOnHardware();
diff --git a/src/org/andengine/entity/sprite/vbo/HighPerformanceSpriteVertexBufferObject.java b/src/org/andengine/entity/sprite/vbo/HighPerformanceSpriteVertexBufferObject.java
index 2e0ba3dde..300054da3 100644
--- a/src/org/andengine/entity/sprite/vbo/HighPerformanceSpriteVertexBufferObject.java
+++ b/src/org/andengine/entity/sprite/vbo/HighPerformanceSpriteVertexBufferObject.java
@@ -8,7 +8,7 @@
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:40:47 - 28.03.2012
@@ -56,22 +56,20 @@ public void onUpdateColor(final Sprite pSprite) {
public void onUpdateVertices(final Sprite pSprite) {
final float[] bufferData = this.mBufferData;
- final float x = 0;
- final float y = 0;
- final float x2 = pSprite.getWidth(); // TODO Optimize with field access?
- final float y2 = pSprite.getHeight(); // TODO Optimize with field access?
+ final float width = pSprite.getWidth(); // TODO Optimize with field access?
+ final float height = pSprite.getHeight(); // TODO Optimize with field access?
- bufferData[0 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = x;
- bufferData[0 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = y;
+ bufferData[0 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = 0;
+ bufferData[0 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = 0;
- bufferData[1 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = x;
- bufferData[1 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = y2;
+ bufferData[1 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = 0;
+ bufferData[1 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = height;
- bufferData[2 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = x2;
- bufferData[2 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = y;
+ bufferData[2 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = width;
+ bufferData[2 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = 0;
- bufferData[3 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = x2;
- bufferData[3 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = y2;
+ bufferData[3 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = width;
+ bufferData[3 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = height;
this.setDirtyOnHardware();
}
@@ -87,8 +85,8 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
final float u2;
final float v2;
- if(pSprite.isFlippedVertical()) { // TODO Optimize with field access?
- if(pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedVertical()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV2();
@@ -100,7 +98,7 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
v2 = textureRegion.getV();
}
} else {
- if(pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV();
@@ -113,30 +111,30 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
}
}
- if(textureRegion.isRotated()) {
- bufferData[0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
+ if (textureRegion.isRotated()) {
+ bufferData[0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
- bufferData[1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
+ bufferData[1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
- bufferData[2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
+ bufferData[2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
- bufferData[3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
+ bufferData[3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
} else {
bufferData[0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
- bufferData[0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
+ bufferData[0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
- bufferData[1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
+ bufferData[1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
bufferData[2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
- bufferData[2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
+ bufferData[2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
- bufferData[3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
+ bufferData[3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
}
this.setDirtyOnHardware();
diff --git a/src/org/andengine/entity/sprite/vbo/HighPerformanceTiledSpriteVertexBufferObject.java b/src/org/andengine/entity/sprite/vbo/HighPerformanceTiledSpriteVertexBufferObject.java
index 6a536496c..9cc8dfc7a 100644
--- a/src/org/andengine/entity/sprite/vbo/HighPerformanceTiledSpriteVertexBufferObject.java
+++ b/src/org/andengine/entity/sprite/vbo/HighPerformanceTiledSpriteVertexBufferObject.java
@@ -9,7 +9,7 @@
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:39:06 - 28.03.2012
@@ -47,7 +47,7 @@ public void onUpdateColor(final TiledSprite pTiledSprite) {
final int tileCount = pTiledSprite.getTileCount();
int bufferDataOffset = 0;
- for(int i = 0; i < tileCount; i++) {
+ for (int i = 0; i < tileCount; i++) {
bufferData[bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.COLOR_INDEX] = packedColor;
bufferData[bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.COLOR_INDEX] = packedColor;
bufferData[bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.COLOR_INDEX] = packedColor;
@@ -65,31 +65,29 @@ public void onUpdateColor(final TiledSprite pTiledSprite) {
public void onUpdateVertices(final TiledSprite pTiledSprite) {
final float[] bufferData = this.mBufferData;
- final float x = 0;
- final float y = 0;
- final float x2 = pTiledSprite.getWidth(); // TODO Optimize with field access?
- final float y2 = pTiledSprite.getHeight(); // TODO Optimize with field access?
+ final float width = pTiledSprite.getWidth(); // TODO Optimize with field access?
+ final float height = pTiledSprite.getHeight(); // TODO Optimize with field access?
final int tileCount = pTiledSprite.getTileCount();
int bufferDataOffset = 0;
- for(int i = 0; i < tileCount; i++) {
- bufferData[bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = x;
- bufferData[bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = y;
+ for (int i = 0; i < tileCount; i++) {
+ bufferData[bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = 0;
+ bufferData[bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = 0;
- bufferData[bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = x;
- bufferData[bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = y2;
+ bufferData[bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = 0;
+ bufferData[bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = height;
- bufferData[bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = x2;
- bufferData[bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = y;
+ bufferData[bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = width;
+ bufferData[bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = 0;
- bufferData[bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = x2;
- bufferData[bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = y;
+ bufferData[bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = width;
+ bufferData[bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = 0;
- bufferData[bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = x;
- bufferData[bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = y2;
+ bufferData[bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = 0;
+ bufferData[bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = height;
- bufferData[bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = x2;
- bufferData[bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = y2;
+ bufferData[bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X] = width;
+ bufferData[bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y] = height;
bufferDataOffset += TiledSprite.TILEDSPRITE_SIZE;
}
@@ -105,7 +103,7 @@ public void onUpdateTextureCoordinates(final TiledSprite pTiledSprite) {
final int tileCount = pTiledSprite.getTileCount();
int bufferDataOffset = 0;
- for(int i = 0; i < tileCount; i++) {
+ for (int i = 0; i < tileCount; i++) {
final ITextureRegion textureRegion = tiledTextureRegion.getTextureRegion(i);
final float u;
@@ -113,8 +111,8 @@ public void onUpdateTextureCoordinates(final TiledSprite pTiledSprite) {
final float u2;
final float v2;
- if(pTiledSprite.isFlippedVertical()) { // TODO Optimize with field access?
- if(pTiledSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pTiledSprite.isFlippedVertical()) { // TODO Optimize with field access?
+ if (pTiledSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV2();
@@ -126,7 +124,7 @@ public void onUpdateTextureCoordinates(final TiledSprite pTiledSprite) {
v2 = textureRegion.getV();
}
} else {
- if(pTiledSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pTiledSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV();
@@ -139,42 +137,42 @@ public void onUpdateTextureCoordinates(final TiledSprite pTiledSprite) {
}
}
- if(textureRegion.isRotated()) {
- bufferData[bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
+ if (textureRegion.isRotated()) {
+ bufferData[bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
- bufferData[bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
+ bufferData[bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
- bufferData[bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
+ bufferData[bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
- bufferData[bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
+ bufferData[bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
- bufferData[bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
+ bufferData[bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
- bufferData[bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
+ bufferData[bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
} else {
bufferData[bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
- bufferData[bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
+ bufferData[bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
- bufferData[bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
+ bufferData[bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
bufferData[bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
- bufferData[bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
+ bufferData[bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
- bufferData[bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
+ bufferData[bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u;
- bufferData[bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
+ bufferData[bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
bufferData[bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U] = u2;
- bufferData[bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v2;
+ bufferData[bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V] = v;
}
bufferDataOffset += TiledSprite.TILEDSPRITE_SIZE;
diff --git a/src/org/andengine/entity/sprite/vbo/HighPerformanceUncoloredSpriteVertexBufferObject.java b/src/org/andengine/entity/sprite/vbo/HighPerformanceUncoloredSpriteVertexBufferObject.java
index bab9b28a0..b16a34438 100644
--- a/src/org/andengine/entity/sprite/vbo/HighPerformanceUncoloredSpriteVertexBufferObject.java
+++ b/src/org/andengine/entity/sprite/vbo/HighPerformanceUncoloredSpriteVertexBufferObject.java
@@ -8,7 +8,7 @@
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:37:49 - 28.03.2012
@@ -38,26 +38,29 @@ public HighPerformanceUncoloredSpriteVertexBufferObject(final VertexBufferObject
// Methods for/from SuperClass/Interfaces
// ===========================================================
+ @Override
+ public void onUpdateColor(final Sprite pSprite) {
+ /* Nothing. */
+ }
+
@Override
public void onUpdateVertices(final Sprite pSprite) {
final float[] bufferData = this.mBufferData;
- final float x = 0;
- final float y = 0;
- final float x2 = pSprite.getWidth(); // TODO Optimize with field access?
- final float y2 = pSprite.getHeight(); // TODO Optimize with field access?
+ final float width = pSprite.getWidth(); // TODO Optimize with field access?
+ final float height = pSprite.getHeight(); // TODO Optimize with field access?
- bufferData[0 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_X] = x;
- bufferData[0 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_Y] = y;
+ bufferData[0 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_X] = 0;
+ bufferData[0 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_Y] = 0;
- bufferData[1 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_X] = x;
- bufferData[1 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_Y] = y2;
+ bufferData[1 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_X] = 0;
+ bufferData[1 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_Y] = height;
- bufferData[2 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_X] = x2;
- bufferData[2 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_Y] = y;
+ bufferData[2 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_X] = width;
+ bufferData[2 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_Y] = 0;
- bufferData[3 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_X] = x2;
- bufferData[3 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_Y] = y2;
+ bufferData[3 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_X] = width;
+ bufferData[3 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_Y] = height;
this.setDirtyOnHardware();
}
@@ -73,8 +76,8 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
final float u2;
final float v2;
- if(pSprite.isFlippedVertical()) { // TODO Optimize with field access?
- if(pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedVertical()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV2();
@@ -86,7 +89,7 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
v2 = textureRegion.getV();
}
} else {
- if(pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV();
@@ -99,30 +102,30 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
}
}
- if(textureRegion.isRotated()) {
- bufferData[0 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U] = u2;
+ if (textureRegion.isRotated()) {
+ bufferData[0 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[0 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V] = v;
- bufferData[1 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U] = u;
+ bufferData[1 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[1 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V] = v;
- bufferData[2 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U] = u2;
+ bufferData[2 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[2 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V] = v2;
- bufferData[3 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U] = u;
+ bufferData[3 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[3 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V] = v2;
} else {
bufferData[0 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U] = u;
- bufferData[0 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V] = v;
+ bufferData[0 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[1 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U] = u;
- bufferData[1 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V] = v2;
+ bufferData[1 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V] = v;
bufferData[2 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U] = u2;
- bufferData[2 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V] = v;
+ bufferData[2 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[3 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U] = u2;
- bufferData[3 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V] = v2;
+ bufferData[3 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V] = v;
}
this.setDirtyOnHardware();
diff --git a/src/org/andengine/entity/sprite/vbo/HighPerformanceUniformColorSpriteVertexBufferObject.java b/src/org/andengine/entity/sprite/vbo/HighPerformanceUniformColorSpriteVertexBufferObject.java
index 9ade337b7..993da081f 100644
--- a/src/org/andengine/entity/sprite/vbo/HighPerformanceUniformColorSpriteVertexBufferObject.java
+++ b/src/org/andengine/entity/sprite/vbo/HighPerformanceUniformColorSpriteVertexBufferObject.java
@@ -9,7 +9,7 @@
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:37:01 - 28.03.2012
@@ -48,22 +48,20 @@ public void onUpdateColor(final Sprite pSprite) {
public void onUpdateVertices(final Sprite pSprite) {
final float[] bufferData = this.mBufferData;
- final float x = 0;
- final float y = 0;
- final float x2 = pSprite.getWidth(); // TODO Optimize with field access?
- final float y2 = pSprite.getHeight(); // TODO Optimize with field access?
+ final float width = pSprite.getWidth(); // TODO Optimize with field access?
+ final float height = pSprite.getHeight(); // TODO Optimize with field access?
- bufferData[0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_X] = x;
- bufferData[0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_Y] = y;
+ bufferData[0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_X] = 0;
+ bufferData[0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_Y] = 0;
- bufferData[1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_X] = x;
- bufferData[1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_Y] = y2;
+ bufferData[1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_X] = 0;
+ bufferData[1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_Y] = height;
- bufferData[2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_X] = x2;
- bufferData[2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_Y] = y;
+ bufferData[2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_X] = width;
+ bufferData[2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_Y] = 0;
- bufferData[3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_X] = x2;
- bufferData[3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_Y] = y2;
+ bufferData[3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_X] = width;
+ bufferData[3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_Y] = height;
this.setDirtyOnHardware();
}
@@ -79,8 +77,8 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
final float u2;
final float v2;
- if(pSprite.isFlippedVertical()) { // TODO Optimize with field access?
- if(pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedVertical()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV2();
@@ -92,7 +90,7 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
v2 = textureRegion.getV();
}
} else {
- if(pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV();
@@ -105,30 +103,30 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
}
}
- if(textureRegion.isRotated()) {
- bufferData[0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U] = u2;
+ if (textureRegion.isRotated()) {
+ bufferData[0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V] = v;
- bufferData[1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U] = u;
+ bufferData[1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V] = v;
- bufferData[2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U] = u2;
+ bufferData[2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V] = v2;
- bufferData[3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U] = u;
+ bufferData[3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V] = v2;
} else {
bufferData[0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U] = u;
- bufferData[0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V] = v;
+ bufferData[0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U] = u;
- bufferData[1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V] = v2;
+ bufferData[1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V] = v;
bufferData[2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U] = u2;
- bufferData[2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V] = v;
+ bufferData[2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U] = u2;
- bufferData[3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V] = v2;
+ bufferData[3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V] = v;
}
this.setDirtyOnHardware();
diff --git a/src/org/andengine/entity/sprite/vbo/IDiamondSpriteVertexBufferObject.java b/src/org/andengine/entity/sprite/vbo/IDiamondSpriteVertexBufferObject.java
index c29e23511..c2e1f0686 100644
--- a/src/org/andengine/entity/sprite/vbo/IDiamondSpriteVertexBufferObject.java
+++ b/src/org/andengine/entity/sprite/vbo/IDiamondSpriteVertexBufferObject.java
@@ -1,7 +1,7 @@
package org.andengine.entity.sprite.vbo;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:43:22 - 28.03.2012
diff --git a/src/org/andengine/entity/sprite/vbo/ISpriteVertexBufferObject.java b/src/org/andengine/entity/sprite/vbo/ISpriteVertexBufferObject.java
index 92e678b4e..79565bddb 100644
--- a/src/org/andengine/entity/sprite/vbo/ISpriteVertexBufferObject.java
+++ b/src/org/andengine/entity/sprite/vbo/ISpriteVertexBufferObject.java
@@ -4,7 +4,7 @@
import org.andengine.opengl.vbo.IVertexBufferObject;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:40:47 - 28.03.2012
diff --git a/src/org/andengine/entity/sprite/vbo/ITiledSpriteVertexBufferObject.java b/src/org/andengine/entity/sprite/vbo/ITiledSpriteVertexBufferObject.java
index e06337bf3..7bd8fdc7a 100644
--- a/src/org/andengine/entity/sprite/vbo/ITiledSpriteVertexBufferObject.java
+++ b/src/org/andengine/entity/sprite/vbo/ITiledSpriteVertexBufferObject.java
@@ -3,7 +3,7 @@
import org.andengine.entity.sprite.TiledSprite;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:39:06 - 28.03.2012
diff --git a/src/org/andengine/entity/sprite/vbo/IUncoloredSpriteVertexBufferObject.java b/src/org/andengine/entity/sprite/vbo/IUncoloredSpriteVertexBufferObject.java
index f692aec0b..63682dc17 100644
--- a/src/org/andengine/entity/sprite/vbo/IUncoloredSpriteVertexBufferObject.java
+++ b/src/org/andengine/entity/sprite/vbo/IUncoloredSpriteVertexBufferObject.java
@@ -2,7 +2,7 @@
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:37:49 - 28.03.2012
diff --git a/src/org/andengine/entity/sprite/vbo/IUniformColorSpriteVertexBufferObject.java b/src/org/andengine/entity/sprite/vbo/IUniformColorSpriteVertexBufferObject.java
index 04db6f88c..aebdd6ab7 100644
--- a/src/org/andengine/entity/sprite/vbo/IUniformColorSpriteVertexBufferObject.java
+++ b/src/org/andengine/entity/sprite/vbo/IUniformColorSpriteVertexBufferObject.java
@@ -2,7 +2,7 @@
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:35:57 - 28.03.2012
diff --git a/src/org/andengine/entity/sprite/vbo/LowMemoryDiamondSpriteVertexBufferObject.java b/src/org/andengine/entity/sprite/vbo/LowMemoryDiamondSpriteVertexBufferObject.java
index bf9af4997..53ad6070c 100644
--- a/src/org/andengine/entity/sprite/vbo/LowMemoryDiamondSpriteVertexBufferObject.java
+++ b/src/org/andengine/entity/sprite/vbo/LowMemoryDiamondSpriteVertexBufferObject.java
@@ -9,7 +9,7 @@
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:43:22 - 28.03.2012
@@ -43,25 +43,23 @@ public LowMemoryDiamondSpriteVertexBufferObject(final VertexBufferObjectManager
public void onUpdateVertices(final Sprite pSprite) {
final FloatBuffer bufferData = this.mFloatBuffer;
- final float x = 0;
- final float y = 0;
- final float x2 = pSprite.getWidth(); // TODO Optimize with field access?
- final float y2 = pSprite.getHeight(); // TODO Optimize with field access?
+ final float width = pSprite.getWidth(); // TODO Optimize with field access?
+ final float height = pSprite.getHeight(); // TODO Optimize with field access?
- final float xCenter = (x + x2) * 0.5f;
- final float yCenter = (y + y2) * 0.5f;
+ final float halfWidth = width * 0.5f;
+ final float halfHeight = height * 0.5f;
- bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, x);
- bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, yCenter);
+ bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, halfWidth);
+ bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, 0);
- bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, xCenter);
- bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, y2);
+ bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, 0);
+ bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, halfHeight);
- bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, xCenter);
- bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, y);
+ bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, width);
+ bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, halfHeight);
- bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, x2);
- bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, yCenter);
+ bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, halfWidth);
+ bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, height);
this.setDirtyOnHardware();
}
@@ -77,8 +75,8 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
final float u2;
final float v2;
- if(pSprite.isFlippedVertical()) { // TODO Optimize with field access?
- if(pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedVertical()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV2();
@@ -90,7 +88,7 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
v2 = textureRegion.getV();
}
} else {
- if(pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV();
@@ -106,9 +104,21 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
final float uCenter = (u + u2) * 0.5f;
final float vCenter = (v + v2) * 0.5f;
- if(textureRegion.isRotated()) {
+ if (textureRegion.isRotated()) {
+ bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
+ bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, vCenter);
+
+ bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, uCenter);
+ bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
+
+ bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, uCenter);
+ bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
+
+ bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, vCenter);
+ } else {
bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, uCenter);
- bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
+ bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, vCenter);
@@ -117,19 +127,7 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, vCenter);
bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, uCenter);
- bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
- } else {
- bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
- bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, vCenter);
-
- bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, uCenter);
- bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
-
- bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, uCenter);
- bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
-
- bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
- bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, vCenter);
+ bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
}
this.setDirtyOnHardware();
diff --git a/src/org/andengine/entity/sprite/vbo/LowMemorySpriteVertexBufferObject.java b/src/org/andengine/entity/sprite/vbo/LowMemorySpriteVertexBufferObject.java
index 5d1574b6b..7ecd1116e 100644
--- a/src/org/andengine/entity/sprite/vbo/LowMemorySpriteVertexBufferObject.java
+++ b/src/org/andengine/entity/sprite/vbo/LowMemorySpriteVertexBufferObject.java
@@ -10,7 +10,7 @@
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:40:47 - 28.03.2012
@@ -58,22 +58,20 @@ public void onUpdateColor(final Sprite pSprite) {
public void onUpdateVertices(final Sprite pSprite) {
final FloatBuffer bufferData = this.mFloatBuffer;
- final float x = 0;
- final float y = 0;
- final float x2 = pSprite.getWidth(); // TODO Optimize with field access?
- final float y2 = pSprite.getHeight(); // TODO Optimize with field access?
+ final float width = pSprite.getWidth(); // TODO Optimize with field access?
+ final float height = pSprite.getHeight(); // TODO Optimize with field access?
- bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, x);
- bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, y);
+ bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, 0);
+ bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, 0);
- bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, x);
- bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, y2);
+ bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, 0);
+ bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, height);
- bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, x2);
- bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, y);
+ bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, width);
+ bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, 0);
- bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, x2);
- bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, y2);
+ bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, width);
+ bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, height);
this.setDirtyOnHardware();
}
@@ -89,8 +87,8 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
final float u2;
final float v2;
- if(pSprite.isFlippedVertical()) { // TODO Optimize with field access?
- if(pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedVertical()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV2();
@@ -102,7 +100,7 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
v2 = textureRegion.getV();
}
} else {
- if(pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV();
@@ -115,30 +113,30 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
}
}
- if(textureRegion.isRotated()) {
- bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
+ if (textureRegion.isRotated()) {
+ bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
- bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
- bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
+ bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
- bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
} else {
bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
- bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
+ bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
- bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
+ bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
- bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
+ bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
- bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
+ bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
}
this.setDirtyOnHardware();
diff --git a/src/org/andengine/entity/sprite/vbo/LowMemoryTiledSpriteVertexBufferObject.java b/src/org/andengine/entity/sprite/vbo/LowMemoryTiledSpriteVertexBufferObject.java
index 28f91e4b5..ffc21da1d 100644
--- a/src/org/andengine/entity/sprite/vbo/LowMemoryTiledSpriteVertexBufferObject.java
+++ b/src/org/andengine/entity/sprite/vbo/LowMemoryTiledSpriteVertexBufferObject.java
@@ -11,7 +11,7 @@
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:39:06 - 28.03.2012
@@ -49,7 +49,7 @@ public void onUpdateColor(final TiledSprite pTiledSprite) {
final int tileCount = pTiledSprite.getTileCount();
int bufferDataOffset = 0;
- for(int i = 0; i < tileCount; i++) {
+ for (int i = 0; i < tileCount; i++) {
bufferData.put(bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.COLOR_INDEX, packedColor);
bufferData.put(bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.COLOR_INDEX, packedColor);
bufferData.put(bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.COLOR_INDEX, packedColor);
@@ -67,31 +67,29 @@ public void onUpdateColor(final TiledSprite pTiledSprite) {
public void onUpdateVertices(final TiledSprite pTiledSprite) {
final FloatBuffer bufferData = this.mFloatBuffer;
- final float x = 0;
- final float y = 0;
- final float x2 = pTiledSprite.getWidth(); // TODO Optimize with field access?
- final float y2 = pTiledSprite.getHeight(); // TODO Optimize with field access?
+ final float width = pTiledSprite.getWidth(); // TODO Optimize with field access?
+ final float height = pTiledSprite.getHeight(); // TODO Optimize with field access?
final int tileCount = pTiledSprite.getTileCount();
int bufferDataOffset = 0;
- for(int i = 0; i < tileCount; i++) {
- bufferData.put(bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, x);
- bufferData.put(bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, y);
+ for (int i = 0; i < tileCount; i++) {
+ bufferData.put(bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, 0);
+ bufferData.put(bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, 0);
- bufferData.put(bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, x);
- bufferData.put(bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, y2);
+ bufferData.put(bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, 0);
+ bufferData.put(bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, height);
- bufferData.put(bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, x2);
- bufferData.put(bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, y);
+ bufferData.put(bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, width);
+ bufferData.put(bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, 0);
- bufferData.put(bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, x2);
- bufferData.put(bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, y);
+ bufferData.put(bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, width);
+ bufferData.put(bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, 0);
- bufferData.put(bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, x);
- bufferData.put(bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, y2);
+ bufferData.put(bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, 0);
+ bufferData.put(bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, height);
- bufferData.put(bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, x2);
- bufferData.put(bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, y2);
+ bufferData.put(bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, width);
+ bufferData.put(bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, height);
bufferDataOffset += TiledSprite.TILEDSPRITE_SIZE;
}
@@ -107,7 +105,7 @@ public void onUpdateTextureCoordinates(final TiledSprite pTiledSprite) {
final int tileCount = pTiledSprite.getTileCount();
int bufferDataOffset = 0;
- for(int i = 0; i < tileCount; i++) {
+ for (int i = 0; i < tileCount; i++) {
final ITextureRegion textureRegion = tiledTextureRegion.getTextureRegion(i);
final float u;
@@ -115,8 +113,8 @@ public void onUpdateTextureCoordinates(final TiledSprite pTiledSprite) {
final float u2;
final float v2;
- if(pTiledSprite.isFlippedVertical()) { // TODO Optimize with field access?
- if(pTiledSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pTiledSprite.isFlippedVertical()) { // TODO Optimize with field access?
+ if (pTiledSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV2();
@@ -128,7 +126,7 @@ public void onUpdateTextureCoordinates(final TiledSprite pTiledSprite) {
v2 = textureRegion.getV();
}
} else {
- if(pTiledSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pTiledSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV();
@@ -141,42 +139,42 @@ public void onUpdateTextureCoordinates(final TiledSprite pTiledSprite) {
}
}
- if(textureRegion.isRotated()) {
- bufferData.put(bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
+ if (textureRegion.isRotated()) {
+ bufferData.put(bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
bufferData.put(bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
- bufferData.put(bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
bufferData.put(bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
- bufferData.put(bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
+ bufferData.put(bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
bufferData.put(bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
- bufferData.put(bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
+ bufferData.put(bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
bufferData.put(bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
- bufferData.put(bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
bufferData.put(bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
- bufferData.put(bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
bufferData.put(bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
} else {
bufferData.put(bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
- bufferData.put(bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
+ bufferData.put(bufferDataOffset + 0 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
bufferData.put(bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
- bufferData.put(bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
+ bufferData.put(bufferDataOffset + 1 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
bufferData.put(bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
- bufferData.put(bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
+ bufferData.put(bufferDataOffset + 2 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
bufferData.put(bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
- bufferData.put(bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
+ bufferData.put(bufferDataOffset + 3 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
bufferData.put(bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
- bufferData.put(bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
+ bufferData.put(bufferDataOffset + 4 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
bufferData.put(bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
- bufferData.put(bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
+ bufferData.put(bufferDataOffset + 5 * TiledSprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
}
bufferDataOffset += TiledSprite.TILEDSPRITE_SIZE;
diff --git a/src/org/andengine/entity/sprite/vbo/LowMemoryUncoloredSpriteVertexBufferObject.java b/src/org/andengine/entity/sprite/vbo/LowMemoryUncoloredSpriteVertexBufferObject.java
index 16b80499e..7b278c9bf 100644
--- a/src/org/andengine/entity/sprite/vbo/LowMemoryUncoloredSpriteVertexBufferObject.java
+++ b/src/org/andengine/entity/sprite/vbo/LowMemoryUncoloredSpriteVertexBufferObject.java
@@ -3,13 +3,14 @@
import java.nio.FloatBuffer;
import org.andengine.entity.sprite.Sprite;
+import org.andengine.entity.sprite.UncoloredSprite;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.vbo.DrawType;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:37:49 - 28.03.2012
@@ -39,29 +40,29 @@ public LowMemoryUncoloredSpriteVertexBufferObject(final VertexBufferObjectManage
// Methods for/from SuperClass/Interfaces
// ===========================================================
+ @Override
+ public void onUpdateColor(final Sprite pSprite) {
+ /* Nothing. */
+ }
+
@Override
public void onUpdateVertices(final Sprite pSprite) {
final FloatBuffer bufferData = this.mFloatBuffer;
- final float x = 0;
- final float y = 0;
- final float x2 = pSprite.getWidth(); // TODO Optimize with field access?
- final float y2 = pSprite.getHeight(); // TODO Optimize with field access?
+ final float width = pSprite.getWidth(); // TODO Optimize with field access?
+ final float height = pSprite.getHeight(); // TODO Optimize with field access?
- final float xCenter = (x + x2) * 0.5f;
- final float yCenter = (y + y2) * 0.5f;
+ bufferData.put(0 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_X, 0);
+ bufferData.put(0 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_Y, 0);
- bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, x);
- bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, yCenter);
+ bufferData.put(1 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_X, 0);
+ bufferData.put(1 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_Y, height);
- bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, xCenter);
- bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, y2);
+ bufferData.put(2 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_X, width);
+ bufferData.put(2 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_Y, 0);
- bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, xCenter);
- bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, y);
-
- bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_X, x2);
- bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.VERTEX_INDEX_Y, yCenter);
+ bufferData.put(3 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_X, width);
+ bufferData.put(3 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.VERTEX_INDEX_Y, height);
this.setDirtyOnHardware();
}
@@ -77,8 +78,8 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
final float u2;
final float v2;
- if(pSprite.isFlippedVertical()) { // TODO Optimize with field access?
- if(pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedVertical()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV2();
@@ -90,7 +91,7 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
v2 = textureRegion.getV();
}
} else {
- if(pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV();
@@ -103,33 +104,30 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
}
}
- final float uCenter = (u + u2) * 0.5f;
- final float vCenter = (v + v2) * 0.5f;
-
- if(textureRegion.isRotated()) {
- bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, uCenter);
- bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
+ if (textureRegion.isRotated()) {
+ bufferData.put(0 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(0 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V, v);
- bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
- bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, vCenter);
+ bufferData.put(1 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U, u2);
+ bufferData.put(1 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V, v);
- bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
- bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, vCenter);
+ bufferData.put(2 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(2 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V, v2);
- bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, uCenter);
- bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
+ bufferData.put(3 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U, u2);
+ bufferData.put(3 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V, v2);
} else {
- bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u);
- bufferData.put(0 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, vCenter);
+ bufferData.put(0 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(0 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V, v2);
- bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, uCenter);
- bufferData.put(1 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v2);
+ bufferData.put(1 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(1 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V, v);
- bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, uCenter);
- bufferData.put(2 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, v);
+ bufferData.put(2 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U, u2);
+ bufferData.put(2 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V, v2);
- bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_U, u2);
- bufferData.put(3 * Sprite.VERTEX_SIZE + Sprite.TEXTURECOORDINATES_INDEX_V, vCenter);
+ bufferData.put(3 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_U, u2);
+ bufferData.put(3 * UncoloredSprite.VERTEX_SIZE + UncoloredSprite.TEXTURECOORDINATES_INDEX_V, v);
}
this.setDirtyOnHardware();
diff --git a/src/org/andengine/entity/sprite/vbo/LowMemoryUniformColorSpriteVertexBufferObject.java b/src/org/andengine/entity/sprite/vbo/LowMemoryUniformColorSpriteVertexBufferObject.java
index b12ec7718..15dc83797 100644
--- a/src/org/andengine/entity/sprite/vbo/LowMemoryUniformColorSpriteVertexBufferObject.java
+++ b/src/org/andengine/entity/sprite/vbo/LowMemoryUniformColorSpriteVertexBufferObject.java
@@ -11,7 +11,7 @@
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 18:36:31 - 28.03.2012
@@ -50,22 +50,20 @@ public void onUpdateColor(final Sprite pSprite) {
public void onUpdateVertices(final Sprite pSprite) {
final FloatBuffer bufferData = this.mFloatBuffer;
- final float x = 0;
- final float y = 0;
- final float x2 = pSprite.getWidth(); // TODO Optimize with field access?
- final float y2 = pSprite.getHeight(); // TODO Optimize with field access?
+ final float width = pSprite.getWidth(); // TODO Optimize with field access?
+ final float height = pSprite.getHeight(); // TODO Optimize with field access?
- bufferData.put(0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_X, x);
- bufferData.put(0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_Y, y);
+ bufferData.put(0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_X, 0);
+ bufferData.put(0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_Y, 0);
- bufferData.put(1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_X, x);
- bufferData.put(1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_Y, y2);
+ bufferData.put(1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_X, 0);
+ bufferData.put(1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_Y, height);
- bufferData.put(2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_X, x2);
- bufferData.put(2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_Y, y);
+ bufferData.put(2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_X, width);
+ bufferData.put(2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_Y, 0);
- bufferData.put(3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_X, x2);
- bufferData.put(3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_Y, y2);
+ bufferData.put(3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_X, width);
+ bufferData.put(3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.VERTEX_INDEX_Y, height);
this.setDirtyOnHardware();
}
@@ -81,8 +79,8 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
final float u2;
final float v2;
- if(pSprite.isFlippedVertical()) { // TODO Optimize with field access?
- if(pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedVertical()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV2();
@@ -94,7 +92,7 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
v2 = textureRegion.getV();
}
} else {
- if(pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
+ if (pSprite.isFlippedHorizontal()) { // TODO Optimize with field access?
u = textureRegion.getU2();
u2 = textureRegion.getU();
v = textureRegion.getV();
@@ -107,30 +105,30 @@ public void onUpdateTextureCoordinates(final Sprite pSprite) {
}
}
- if(textureRegion.isRotated()) {
- bufferData.put(0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U, u2);
+ if (textureRegion.isRotated()) {
+ bufferData.put(0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U, u);
bufferData.put(0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V, v);
- bufferData.put(1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U, u2);
bufferData.put(1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V, v);
- bufferData.put(2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U, u2);
+ bufferData.put(2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U, u);
bufferData.put(2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V, v2);
- bufferData.put(3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U, u2);
bufferData.put(3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V, v2);
} else {
bufferData.put(0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U, u);
- bufferData.put(0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V, v);
+ bufferData.put(0 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V, v2);
- bufferData.put(1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U, u);
- bufferData.put(1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V, v2);
+ bufferData.put(1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U, u2);
+ bufferData.put(1 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V, v);
bufferData.put(2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U, u2);
- bufferData.put(2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V, v);
+ bufferData.put(2 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V, v2);
bufferData.put(3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_U, u2);
- bufferData.put(3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V, v2);
+ bufferData.put(3 * UniformColorSprite.VERTEX_SIZE + UniformColorSprite.TEXTURECOORDINATES_INDEX_V, v);
}
this.setDirtyOnHardware();
diff --git a/src/org/andengine/entity/text/AutoWrap.java b/src/org/andengine/entity/text/AutoWrap.java
index ebc6141cc..faf5e4e1a 100644
--- a/src/org/andengine/entity/text/AutoWrap.java
+++ b/src/org/andengine/entity/text/AutoWrap.java
@@ -1,7 +1,7 @@
package org.andengine.entity.text;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 12:36:44 - 29.03.2012
diff --git a/src/org/andengine/entity/text/Text.java b/src/org/andengine/entity/text/Text.java
index 6e9a88043..94c5b832b 100644
--- a/src/org/andengine/entity/text/Text.java
+++ b/src/org/andengine/entity/text/Text.java
@@ -3,7 +3,7 @@
import java.util.ArrayList;
import org.andengine.engine.camera.Camera;
-import org.andengine.entity.shape.RectangularShape;
+import org.andengine.entity.shape.Shape;
import org.andengine.entity.text.exception.OutOfCharactersException;
import org.andengine.entity.text.vbo.HighPerformanceTextVertexBufferObject;
import org.andengine.entity.text.vbo.ITextVertexBufferObject;
@@ -17,8 +17,8 @@
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributesBuilder;
-import org.andengine.util.HorizontalAlign;
-import org.andengine.util.adt.DataConstants;
+import org.andengine.util.adt.align.HorizontalAlign;
+import org.andengine.util.adt.data.constants.DataConstants;
import org.andengine.util.adt.list.FloatArrayList;
import org.andengine.util.adt.list.IFloatList;
@@ -29,11 +29,11 @@
*
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 10:54:59 - 03.04.2010
*/
-public class Text extends RectangularShape {
+public class Text extends Shape {
// ===========================================================
// Constants
// ===========================================================
@@ -134,6 +134,10 @@ public Text(final float pX, final float pY, final IFont pFont, final CharSequenc
this(pX, pY, pFont, pText, pCharactersMaximum, pTextOptions, pVertexBufferObjectManager, DrawType.STATIC);
}
+ public Text(final float pX, final float pY, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final TextOptions pTextOptions, final VertexBufferObjectManager pVertexBufferObjectManager, final ShaderProgram pShaderProgram) {
+ this(pX, pY, pFont, pText, pCharactersMaximum, pTextOptions, pVertexBufferObjectManager, DrawType.STATIC, pShaderProgram);
+ }
+
public Text(final float pX, final float pY, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final TextOptions pTextOptions, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
this(pX, pY, pFont, pText, pCharactersMaximum, pTextOptions, new HighPerformanceTextVertexBufferObject(pVertexBufferObjectManager, Text.LETTER_SIZE * pCharactersMaximum, pDrawType, true, Text.VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT));
}
@@ -147,7 +151,7 @@ public Text(final float pX, final float pY, final IFont pFont, final CharSequenc
}
public Text(final float pX, final float pY, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final TextOptions pTextOptions, final ITextVertexBufferObject pTextVertexBufferObject, final ShaderProgram pShaderProgram) {
- super(pX, pY, 0, 0, pShaderProgram);
+ super(pX, pY, pShaderProgram);
this.mFont = pFont;
this.mTextOptions = pTextOptions;
@@ -180,7 +184,7 @@ public CharSequence getText() {
/**
* @param pText
- * @throws OutOfCharactersException leaves this {@link Text} object in an undefined state, until {@link Text#setText(CharSequence)} is called again and no {@link OutOfCharactersException} is thrown.
+ * @throws OutOfCharactersException leaves this {@link Text} object in an undefined state, until {@link #setText(CharSequence)} is called again and no {@link OutOfCharactersException} is thrown.
*/
public void setText(final CharSequence pText) throws OutOfCharactersException {
this.mText = pText;
@@ -189,7 +193,7 @@ public void setText(final CharSequence pText) throws OutOfCharactersException {
this.mLines.clear();
this.mLineWidths.clear();
- if(this.mTextOptions.mAutoWrap == AutoWrap.NONE) {
+ if (this.mTextOptions.mAutoWrap == AutoWrap.NONE) {
this.mLines = FontUtils.splitLines(this.mText, this.mLines); // TODO Add whitespace-trimming.
} else {
this.mLines = FontUtils.splitLines(this.mFont, this.mText, this.mLines, this.mTextOptions.mAutoWrap, this.mTextOptions.mAutoWrapWidth);
@@ -205,22 +209,16 @@ public void setText(final CharSequence pText) throws OutOfCharactersException {
}
this.mLineWidthMaximum = maximumLineWidth;
- if(this.mTextOptions.mAutoWrap == AutoWrap.NONE) {
+ if (this.mTextOptions.mAutoWrap == AutoWrap.NONE) {
this.mLineAlignmentWidth = this.mLineWidthMaximum;
} else {
this.mLineAlignmentWidth = this.mTextOptions.mAutoWrapWidth;
}
- super.mWidth = this.mLineAlignmentWidth;
- super.mHeight = lineCount * font.getLineHeight() + (lineCount - 1) * this.mTextOptions.mLeading;
-
- this.mRotationCenterX = super.mWidth * 0.5f;
- this.mRotationCenterY = super.mHeight * 0.5f;
-
- this.mScaleCenterX = this.mRotationCenterX;
- this.mScaleCenterY = this.mRotationCenterY;
+ final float width = this.mLineAlignmentWidth;
+ final float height = lineCount * font.getLineHeight() + (lineCount - 1) * this.mTextOptions.mLeading;
- this.onUpdateVertices();
+ this.setSize(width, height);
}
public ArrayList getLines() {
@@ -288,7 +286,7 @@ public void setTextOptions(final TextOptions pTextOptions) {
}
public void setCharactersToDraw(final int pCharactersToDraw) {
- if(pCharactersToDraw > this.mCharactersMaximum) {
+ if (pCharactersToDraw > this.mCharactersMaximum) {
throw new OutOfCharactersException("Characters: maximum: '" + this.mCharactersMaximum + "' required: '" + pCharactersToDraw + "'.");
}
this.mCharactersToDraw = pCharactersToDraw;
diff --git a/src/org/andengine/entity/text/TextOptions.java b/src/org/andengine/entity/text/TextOptions.java
index 72dbc3638..a07906822 100644
--- a/src/org/andengine/entity/text/TextOptions.java
+++ b/src/org/andengine/entity/text/TextOptions.java
@@ -1,9 +1,9 @@
package org.andengine.entity.text;
-import org.andengine.util.HorizontalAlign;
+import org.andengine.util.adt.align.HorizontalAlign;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 12:37:02 - 29.03.2012
diff --git a/src/org/andengine/entity/text/TickerText.java b/src/org/andengine/entity/text/TickerText.java
index 540149198..4f5a9fc1c 100644
--- a/src/org/andengine/entity/text/TickerText.java
+++ b/src/org/andengine/entity/text/TickerText.java
@@ -5,14 +5,14 @@
import org.andengine.opengl.font.IFont;
import org.andengine.opengl.util.GLState;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
-import org.andengine.util.HorizontalAlign;
+import org.andengine.util.adt.align.HorizontalAlign;
import android.opengl.GLES20;
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 10:02:04 - 05.05.2010
*/
@@ -76,10 +76,10 @@ public int getCharactersVisible() {
}
@Override
- public void setText(CharSequence pText) throws OutOfCharactersException {
+ public void setText(final CharSequence pText) throws OutOfCharactersException {
super.setText(pText);
- if(this.mTickerTextOptions != null) {
+ if (this.mTickerTextOptions != null) {
this.mDuration = this.mCharactersToDraw * this.mTickerTextOptions.mCharactersPerSecond;
}
}
@@ -92,13 +92,13 @@ public void setText(CharSequence pText) throws OutOfCharactersException {
protected void onManagedUpdate(final float pSecondsElapsed) {
super.onManagedUpdate(pSecondsElapsed);
- if(this.mTickerTextOptions.mReverse) {
- if(this.mCharactersVisible < this.mCharactersToDraw) {
+ if (this.mTickerTextOptions.mReverse) {
+ if (this.mCharactersVisible < this.mCharactersToDraw) {
this.mSecondsElapsed = Math.max(0, this.mSecondsElapsed - pSecondsElapsed);
this.mCharactersVisible = (int) (this.mSecondsElapsed * this.mTickerTextOptions.mCharactersPerSecond);
}
} else {
- if(this.mCharactersVisible < this.mCharactersToDraw) {
+ if (this.mCharactersVisible < this.mCharactersToDraw) {
this.mSecondsElapsed = Math.min(this.mDuration, this.mSecondsElapsed + pSecondsElapsed);
this.mCharactersVisible = (int) (this.mSecondsElapsed * this.mTickerTextOptions.mCharactersPerSecond);
}
diff --git a/src/org/andengine/entity/text/exception/OutOfCharactersException.java b/src/org/andengine/entity/text/exception/OutOfCharactersException.java
index 526e1ce4e..c60cb3d6f 100644
--- a/src/org/andengine/entity/text/exception/OutOfCharactersException.java
+++ b/src/org/andengine/entity/text/exception/OutOfCharactersException.java
@@ -2,7 +2,7 @@
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 17:53:31 - 01.11.2011
diff --git a/src/org/andengine/entity/text/exception/TextException.java b/src/org/andengine/entity/text/exception/TextException.java
index b9acb023a..b7e8693af 100644
--- a/src/org/andengine/entity/text/exception/TextException.java
+++ b/src/org/andengine/entity/text/exception/TextException.java
@@ -3,7 +3,7 @@
import org.andengine.util.exception.AndEngineRuntimeException;
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 17:53:31 - 01.11.2011
diff --git a/src/org/andengine/entity/text/vbo/HighPerformanceTextVertexBufferObject.java b/src/org/andengine/entity/text/vbo/HighPerformanceTextVertexBufferObject.java
index 03c276ee4..411ed79cf 100644
--- a/src/org/andengine/entity/text/vbo/HighPerformanceTextVertexBufferObject.java
+++ b/src/org/andengine/entity/text/vbo/HighPerformanceTextVertexBufferObject.java
@@ -9,10 +9,11 @@
import org.andengine.opengl.vbo.HighPerformanceVertexBufferObject;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
+import org.andengine.util.adt.align.HorizontalAlign;
import org.andengine.util.adt.list.IFloatList;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 12:38:43 - 29.03.2012
@@ -50,7 +51,7 @@ public void onUpdateColor(final Text pText) {
int bufferDataOffset = 0;
final int charactersMaximum = pText.getCharactersMaximum();
- for(int i = 0; i < charactersMaximum; i++) {
+ for (int i = 0; i < charactersMaximum; i++) {
bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.COLOR_INDEX] = packedColor;
bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.COLOR_INDEX] = packedColor;
bufferData[bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.COLOR_INDEX] = packedColor;
@@ -68,11 +69,13 @@ public void onUpdateColor(final Text pText) {
public void onUpdateVertices(final Text pText) {
final float[] bufferData = this.mBufferData;
- // TODO Optimize with field access?
final IFont font = pText.getFont();
+ final HorizontalAlign horizontalAlign = pText.getHorizontalAlign();
final ArrayList lines = pText.getLines();
final float lineHeight = font.getLineHeight();
final IFloatList lineWidths = pText.getLineWidths();
+ final float leading = pText.getLeading();
+ final float ascent = font.getAscent();
final float lineAlignmentWidth = pText.getLineAlignmentWidth();
@@ -84,7 +87,7 @@ public void onUpdateVertices(final Text pText) {
final CharSequence line = lines.get(row);
float xBase;
- switch(pText.getHorizontalAlign()) {
+ switch (horizontalAlign) {
case RIGHT:
xBase = lineAlignmentWidth - lineWidths.get(row);
break;
@@ -96,22 +99,22 @@ public void onUpdateVertices(final Text pText) {
xBase = 0;
}
- final float yBase = row * (lineHeight + pText.getLeading());
+ final float yBase = (lineCount - row) * lineHeight + ((lineCount - row - 1) * leading) + ascent;
final int lineLength = line.length();
Letter previousLetter = null;
- for(int i = 0; i < lineLength; i++) {
+ for (int i = 0; i < lineLength; i++) {
final Letter letter = font.getLetter(line.charAt(i));
- if(previousLetter != null) {
+ if (previousLetter != null) {
xBase += previousLetter.getKerning(letter.mCharacter);
}
- if(!letter.isWhitespace()) {
+ if (!letter.isWhitespace()) {
final float x = xBase + letter.mOffsetX;
- final float y = yBase + letter.mOffsetY;
+ final float y = yBase - letter.mOffsetY;
- final float y2 = y + letter.mHeight;
final float x2 = x + letter.mWidth;
+ final float y2 = y - letter.mHeight;
final float u = letter.mU;
final float v = letter.mV;
@@ -119,14 +122,14 @@ public void onUpdateVertices(final Text pText) {
final float v2 = letter.mV2;
bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x;
- bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y;
+ bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y2;
bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u;
- bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v;
+ bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v2;
bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x;
- bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y2;
+ bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y;
bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u;
- bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v2;
+ bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v;
bufferData[bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x2;
bufferData[bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y2;
@@ -138,14 +141,14 @@ public void onUpdateVertices(final Text pText) {
bufferData[bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v2;
- bufferData[bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x2;
+ bufferData[bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x;
bufferData[bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y;
- bufferData[bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u2;
+ bufferData[bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u;
bufferData[bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v;
- bufferData[bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x;
+ bufferData[bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x2;
bufferData[bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y;
- bufferData[bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u;
+ bufferData[bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u2;
bufferData[bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v;
bufferDataOffset += Text.LETTER_SIZE;
diff --git a/src/org/andengine/entity/text/vbo/ITextVertexBufferObject.java b/src/org/andengine/entity/text/vbo/ITextVertexBufferObject.java
index abac08460..a4e49ccef 100644
--- a/src/org/andengine/entity/text/vbo/ITextVertexBufferObject.java
+++ b/src/org/andengine/entity/text/vbo/ITextVertexBufferObject.java
@@ -4,8 +4,8 @@
import org.andengine.opengl.vbo.IVertexBufferObject;
/**
- *
- * (c) Zynga 2012
+ *
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 12:38:05 - 29.03.2012
diff --git a/src/org/andengine/entity/text/vbo/LowMemoryTextVertexBufferObject.java b/src/org/andengine/entity/text/vbo/LowMemoryTextVertexBufferObject.java
index 648c8a0bb..510bd6d74 100644
--- a/src/org/andengine/entity/text/vbo/LowMemoryTextVertexBufferObject.java
+++ b/src/org/andengine/entity/text/vbo/LowMemoryTextVertexBufferObject.java
@@ -10,10 +10,11 @@
import org.andengine.opengl.vbo.LowMemoryVertexBufferObject;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
+import org.andengine.util.adt.align.HorizontalAlign;
import org.andengine.util.adt.list.IFloatList;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 12:38:22 - 29.03.2012
@@ -51,7 +52,7 @@ public void onUpdateColor(final Text pText) {
int bufferDataOffset = 0;
final int charactersMaximum = pText.getCharactersMaximum();
- for(int i = 0; i < charactersMaximum; i++) {
+ for (int i = 0; i < charactersMaximum; i++) {
bufferData.put(bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.COLOR_INDEX, packedColor);
bufferData.put(bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.COLOR_INDEX, packedColor);
bufferData.put(bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.COLOR_INDEX, packedColor);
@@ -69,11 +70,13 @@ public void onUpdateColor(final Text pText) {
public void onUpdateVertices(final Text pText) {
final FloatBuffer bufferData = this.mFloatBuffer;
- // TODO Optimize with field access?
final IFont font = pText.getFont();
+ final HorizontalAlign horizontalAlign = pText.getHorizontalAlign();
final ArrayList lines = pText.getLines();
final float lineHeight = font.getLineHeight();
final IFloatList lineWidths = pText.getLineWidths();
+ final float leading = pText.getLeading();
+ final float ascent = font.getAscent();
final float lineAlignmentWidth = pText.getLineAlignmentWidth();
@@ -81,39 +84,39 @@ public void onUpdateVertices(final Text pText) {
int bufferDataOffset = 0;
final int lineCount = lines.size();
- for (int i = 0; i < lineCount; i++) {
- final CharSequence line = lines.get(i);
+ for (int row = 0; row < lineCount; row++) {
+ final CharSequence line = lines.get(row);
float xBase;
- switch(pText.getHorizontalAlign()) {
+ switch (horizontalAlign) {
case RIGHT:
- xBase = lineAlignmentWidth - lineWidths.get(i);
+ xBase = lineAlignmentWidth - lineWidths.get(row);
break;
case CENTER:
- xBase = (lineAlignmentWidth - lineWidths.get(i)) * 0.5f;
+ xBase = (lineAlignmentWidth - lineWidths.get(row)) * 0.5f;
break;
case LEFT:
default:
xBase = 0;
}
- final float yBase = i * (lineHeight + pText.getLeading());
+ final float yBase = (lineCount - row) * lineHeight + ((lineCount - row - 1) * leading) + ascent;
final int lineLength = line.length();
Letter previousLetter = null;
- for(int j = 0; j < lineLength; j++) {
- final Letter letter = font.getLetter(line.charAt(j));
- if(previousLetter != null) {
+ for (int i = 0; i < lineLength; i++) {
+ final Letter letter = font.getLetter(line.charAt(i));
+ if (previousLetter != null) {
xBase += previousLetter.getKerning(letter.mCharacter);
}
- if(!letter.isWhitespace()) {
+ if (!letter.isWhitespace()) {
final float x = xBase + letter.mOffsetX;
- final float y = yBase + letter.mOffsetY;
+ final float y = yBase - letter.mOffsetY;
- final float y2 = y + letter.mHeight;
final float x2 = x + letter.mWidth;
+ final float y2 = y - letter.mHeight;
final float u = letter.mU;
final float v = letter.mV;
@@ -121,14 +124,14 @@ public void onUpdateVertices(final Text pText) {
final float v2 = letter.mV2;
bufferData.put(bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x);
- bufferData.put(bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y);
+ bufferData.put(bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y2);
bufferData.put(bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u);
- bufferData.put(bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v);
+ bufferData.put(bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v2);
bufferData.put(bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x);
- bufferData.put(bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y2);
+ bufferData.put(bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y);
bufferData.put(bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u);
- bufferData.put(bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v2);
+ bufferData.put(bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v);
bufferData.put(bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x2);
bufferData.put(bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y2);
@@ -140,14 +143,14 @@ public void onUpdateVertices(final Text pText) {
bufferData.put(bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u2);
bufferData.put(bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v2);
- bufferData.put(bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x2);
+ bufferData.put(bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x);
bufferData.put(bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y);
- bufferData.put(bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u2);
+ bufferData.put(bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u);
bufferData.put(bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v);
- bufferData.put(bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x);
+ bufferData.put(bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x2);
bufferData.put(bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y);
- bufferData.put(bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u);
+ bufferData.put(bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u2);
bufferData.put(bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v);
bufferDataOffset += Text.LETTER_SIZE;
diff --git a/src/org/andengine/entity/util/AverageFPSCounter.java b/src/org/andengine/entity/util/AverageFPSCounter.java
index 7dd65ee70..a1bd1a98c 100644
--- a/src/org/andengine/entity/util/AverageFPSCounter.java
+++ b/src/org/andengine/entity/util/AverageFPSCounter.java
@@ -3,9 +3,9 @@
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 19:52:31 - 09.03.2010
*/
@@ -48,7 +48,7 @@ public AverageFPSCounter(final float pAverageDuration) {
public void onUpdate(final float pSecondsElapsed) {
super.onUpdate(pSecondsElapsed);
- if(this.mSecondsElapsed > this.mAverageDuration){
+ if (this.mSecondsElapsed > this.mAverageDuration) {
this.onHandleAverageDurationElapsed(this.getFPS());
this.mSecondsElapsed -= this.mAverageDuration;
diff --git a/src/org/andengine/entity/util/FPSCounter.java b/src/org/andengine/entity/util/FPSCounter.java
index ceeddac26..5b1f813f1 100644
--- a/src/org/andengine/entity/util/FPSCounter.java
+++ b/src/org/andengine/entity/util/FPSCounter.java
@@ -3,9 +3,9 @@
import org.andengine.engine.handler.IUpdateHandler;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 19:52:31 - 09.03.2010
*/
diff --git a/src/org/andengine/entity/util/FPSLogger.java b/src/org/andengine/entity/util/FPSLogger.java
index 71315307f..df02d9f62 100644
--- a/src/org/andengine/entity/util/FPSLogger.java
+++ b/src/org/andengine/entity/util/FPSLogger.java
@@ -2,12 +2,13 @@
import org.andengine.BuildConfig;
import org.andengine.util.debug.Debug;
+import org.andengine.util.debug.Debug.DebugLevel;
import org.andengine.util.time.TimeConstants;
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 19:52:31 - 09.03.2010
*/
@@ -20,6 +21,8 @@ public class FPSLogger extends AverageFPSCounter {
// Fields
// ===========================================================
+ private final DebugLevel mDebugLevel;
+
protected float mShortestFrame = Float.MAX_VALUE;
protected float mLongestFrame = Float.MIN_VALUE;
@@ -28,11 +31,21 @@ public class FPSLogger extends AverageFPSCounter {
// ===========================================================
public FPSLogger() {
- super();
+ this(DebugLevel.DEBUG);
+ }
+
+ public FPSLogger(final DebugLevel pDebugLevel) {
+ this.mDebugLevel = pDebugLevel;
}
public FPSLogger(final float pAverageDuration) {
+ this(pAverageDuration, DebugLevel.DEBUG);
+ }
+
+ public FPSLogger(final float pAverageDuration, final DebugLevel pDebugLevel) {
super(pAverageDuration);
+
+ this.mDebugLevel = pDebugLevel;
}
// ===========================================================
@@ -72,11 +85,12 @@ public void reset() {
// ===========================================================
protected void onLogFPS() {
- if(BuildConfig.DEBUG) {
- Debug.d(String.format("FPS: %.2f (MIN: %.0f ms | MAX: %.0f ms)",
- this.mFrames / this.mSecondsElapsed,
- this.mShortestFrame * TimeConstants.MILLISECONDS_PER_SECOND,
- this.mLongestFrame * TimeConstants.MILLISECONDS_PER_SECOND));
+ if (BuildConfig.DEBUG) {
+ final float framesPerSecond = this.mFrames / this.mSecondsElapsed;
+ final float shortestFrameInMilliseconds = this.mShortestFrame * TimeConstants.MILLISECONDS_PER_SECOND;
+ final float longestFrameInMilliseconds = this.mLongestFrame * TimeConstants.MILLISECONDS_PER_SECOND;
+
+ Debug.log(this.mDebugLevel, String.format("FPS: %.2f (MIN: %.0f ms | MAX: %.0f ms)", framesPerSecond, shortestFrameInMilliseconds, longestFrameInMilliseconds));
}
}
diff --git a/src/org/andengine/entity/util/FrameCountCrasher.java b/src/org/andengine/entity/util/FrameCountCrasher.java
index 5c6175c14..b1d2b31be 100644
--- a/src/org/andengine/entity/util/FrameCountCrasher.java
+++ b/src/org/andengine/entity/util/FrameCountCrasher.java
@@ -5,9 +5,9 @@
import org.andengine.util.debug.Debug;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 19:52:31 - 09.03.2010
*/
@@ -46,11 +46,11 @@ public void onUpdate(final float pSecondsElapsed) {
this.mFramesLeft--;
final float[] frameLengths = this.mFrameLengths;
- if(this.mFramesLeft >= 0) {
+ if (this.mFramesLeft >= 0) {
frameLengths[this.mFramesLeft] = pSecondsElapsed;
} else {
- if(BuildConfig.DEBUG) {
- for(int i = frameLengths.length - 1; i >= 0; i--) {
+ if (BuildConfig.DEBUG) {
+ for (int i = frameLengths.length - 1; i >= 0; i--) {
Debug.d("Elapsed: " + frameLengths[i]);
}
}
diff --git a/src/org/andengine/entity/util/FrameCounter.java b/src/org/andengine/entity/util/FrameCounter.java
index 49a4740b1..5ee3d578f 100644
--- a/src/org/andengine/entity/util/FrameCounter.java
+++ b/src/org/andengine/entity/util/FrameCounter.java
@@ -3,9 +3,9 @@
import org.andengine.engine.handler.IUpdateHandler;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 11:00:55 - 22.06.2010
*/
diff --git a/src/org/andengine/entity/util/MemoryLogger.java b/src/org/andengine/entity/util/MemoryLogger.java
new file mode 100644
index 000000000..7ac265a13
--- /dev/null
+++ b/src/org/andengine/entity/util/MemoryLogger.java
@@ -0,0 +1,242 @@
+package org.andengine.entity.util;
+
+import org.andengine.BuildConfig;
+import org.andengine.engine.handler.IUpdateHandler;
+import org.andengine.util.TextUtils;
+import org.andengine.util.debug.Debug;
+import org.andengine.util.debug.Debug.DebugLevel;
+import org.andengine.util.system.SystemUtils;
+import org.andengine.util.system.SystemUtils.SystemUtilsException;
+
+
+
+/**
+ * (c) 2012 Zynga Inc.
+ *
+ * @author Nicolas Gramlich
+ * @since 14:50:15 - 14.05.2012
+ */
+public class MemoryLogger implements IUpdateHandler {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ private static final float AVERAGE_DURATION_DEFAULT = 5;
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ private final float mAverageDuration;
+ private final DebugLevel mDebugLevel;
+
+ private float mSecondsElapsed;
+
+ private boolean mLogSystemMemory;
+ private long mPreviousSystemMemorySize;
+ private long mPreviousSystemMemoryFreeSize;
+
+ private boolean mLogDalvikHeap;
+ private long mPreviousDalvikHeapSize;
+ private long mPreviousDalvikHeapFreeSize;
+ private long mPreviousDalvikHeapAllocatedSize;
+
+ private boolean mLogDalvikMemoryInfo;
+ private long mPreviousDalvikProportionalSetSize;
+ private long mPreviousDalvikPrivateDirtyPages;
+ private long mPreviousDalvikSharedDirtyPages;
+
+ private boolean mLogNativeHeap;
+ private long mPreviousNativeHeapSize;
+ private long mPreviousNativeHeapFreeSize;
+ private long mPreviousNativeHeapAllocatedSize;
+
+ private boolean mLogNativeMemoryInfo;
+ private long mPreviousNativeProportionalSetSize;
+ private long mPreviousNativePrivateDirtyPages;
+ private long mPreviousNativeSharedDirtyPages;
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ public MemoryLogger() {
+ this(DebugLevel.DEBUG);
+ }
+
+ public MemoryLogger(final DebugLevel pDebugLevel) {
+ this(MemoryLogger.AVERAGE_DURATION_DEFAULT, pDebugLevel);
+ }
+
+ public MemoryLogger(final float pAverageDuration) {
+ this(pAverageDuration, DebugLevel.DEBUG);
+ }
+
+ public MemoryLogger(final float pAverageDuration, final DebugLevel pDebugLevel) {
+ this(pAverageDuration, pDebugLevel, true, true, false, true, false);
+ }
+
+ public MemoryLogger(final float pAverageDuration, final DebugLevel pDebugLevel, final boolean pLogSystemMemory, final boolean pLogDalvikHeap, final boolean pLogDalvikMemoryInfo, final boolean pLogNativeHeap, final boolean pLogNativeMemoryInfo) {
+ this.mAverageDuration = pAverageDuration;
+ this.mDebugLevel = pDebugLevel;
+
+ this.mLogSystemMemory = pLogSystemMemory;
+ this.mLogDalvikHeap = pLogDalvikHeap;
+ this.mLogDalvikMemoryInfo = pLogDalvikMemoryInfo;
+ this.mLogNativeHeap = pLogNativeHeap;
+ this.mLogNativeMemoryInfo = pLogNativeMemoryInfo;
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ @Override
+ public void onUpdate(final float pSecondsElapsed) {
+ this.mSecondsElapsed += pSecondsElapsed;
+
+ if (this.mSecondsElapsed > this.mAverageDuration) {
+ this.onHandleLogDurationElapsed();
+
+ this.mSecondsElapsed -= this.mAverageDuration;
+ }
+ }
+
+ @Override
+ public void reset() {
+ this.mSecondsElapsed = 0;
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ protected void onHandleLogDurationElapsed() {
+ if (BuildConfig.DEBUG) {
+ /* Execute GC. */
+ System.gc();
+ try {
+ final StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append("+------------------------------+---------------+-----------------+\n");
+ stringBuilder.append("| Memory Stat | Current | Change |\n");
+ stringBuilder.append("+------------------------------+---------------+-----------------+\n");
+
+ if (this.mLogSystemMemory) {
+ final long systemMemorySize = SystemUtils.getSystemMemorySize();
+ final long systemMemoryFreeSize = SystemUtils.getSystemMemoryFreeSize();
+
+ final long systemMemorySizeDiff = systemMemorySize - this.mPreviousSystemMemorySize;
+ final long systemMemoryFreeSizeDiff = systemMemoryFreeSize - this.mPreviousSystemMemoryFreeSize;
+
+ this.mPreviousSystemMemorySize = systemMemorySize;
+ this.mPreviousSystemMemoryFreeSize = systemMemoryFreeSize;
+
+ stringBuilder.append("| System memory size | " + MemoryLogger.formatRight(systemMemorySize, ' ', 10) + " kB | (" + MemoryLogger.formatRight(systemMemorySizeDiff, ' ', 10, true) + " kB) |\n");
+ stringBuilder.append("| System memory free size | " + MemoryLogger.formatRight(systemMemoryFreeSize, ' ', 10) + " kB | (" + MemoryLogger.formatRight(systemMemoryFreeSizeDiff, ' ', 10, true) + " kB) |\n");
+ stringBuilder.append("+------------------------------+---------------+-----------------+\n");
+ }
+
+ if (this.mLogDalvikHeap) {
+ final long dalvikHeapSize = SystemUtils.getDalvikHeapSize();
+ final long dalvikHeapFreeSize = SystemUtils.getDalvikHeapFreeSize();
+ final long dalvikHeapAllocatedSize = SystemUtils.getDalvikHeapAllocatedSize();
+
+ final long dalvikHeapSizeDiff = dalvikHeapSize - this.mPreviousDalvikHeapSize;
+ final long dalvikHeapFreeSizeDiff = dalvikHeapFreeSize - this.mPreviousDalvikHeapFreeSize;
+ final long dalvikHeapAllocatedSizeDiff = dalvikHeapAllocatedSize - this.mPreviousDalvikHeapAllocatedSize;
+
+ stringBuilder.append("| Dalvik memory size | " + MemoryLogger.formatRight(dalvikHeapSize, ' ', 10) + " kB | (" + MemoryLogger.formatRight(dalvikHeapSizeDiff, ' ', 10, true) + " kB) |\n");
+ stringBuilder.append("| Dalvik memory free size | " + MemoryLogger.formatRight(dalvikHeapFreeSize, ' ', 10) + " kB | (" + MemoryLogger.formatRight(dalvikHeapFreeSizeDiff, ' ', 10, true) + " kB) |\n");
+ stringBuilder.append("| Dalvik memory allocated size | " + MemoryLogger.formatRight(dalvikHeapAllocatedSize, ' ', 10) + " kB | (" + MemoryLogger.formatRight(dalvikHeapAllocatedSizeDiff, ' ', 10, true) + " kB) |\n");
+ stringBuilder.append("+------------------------------+---------------+-----------------+\n");
+
+ this.mPreviousDalvikHeapSize = dalvikHeapSize;
+ this.mPreviousDalvikHeapFreeSize = dalvikHeapFreeSize;
+ this.mPreviousDalvikHeapAllocatedSize = dalvikHeapAllocatedSize;
+ }
+
+ if (this.mLogDalvikMemoryInfo) {
+ final long dalvikProportionalSetSize = SystemUtils.getDalvikProportionalSetSize();
+ final long dalvikPrivateDirtyPages = SystemUtils.getDalvikPrivateDirtyPages();
+ final long dalvikSharedDirtyPages = SystemUtils.getDalvikSharedDirtyPages();
+
+ final long dalvikProportionalSetSizeDiff = dalvikProportionalSetSize - this.mPreviousDalvikProportionalSetSize;
+ final long dalvikPrivateDirtyPagesDiff = dalvikPrivateDirtyPages - this.mPreviousDalvikPrivateDirtyPages;
+ final long dalvikSharedDirtyPagesDiff = dalvikSharedDirtyPages - this.mPreviousDalvikSharedDirtyPages;
+
+ stringBuilder.append("| Dalvik proportional set size | " + MemoryLogger.formatRight(dalvikProportionalSetSize, ' ', 10) + " | (" + MemoryLogger.formatRight(dalvikProportionalSetSizeDiff, ' ', 10, true) + " ) |\n");
+ stringBuilder.append("| Dalvik private dirty pages | " + MemoryLogger.formatRight(dalvikPrivateDirtyPages, ' ', 10) + " | (" + MemoryLogger.formatRight(dalvikPrivateDirtyPagesDiff, ' ', 10, true) + " ) |\n");
+ stringBuilder.append("| Dalvik shared dirty pages | " + MemoryLogger.formatRight(dalvikSharedDirtyPages, ' ', 10) + " | (" + MemoryLogger.formatRight(dalvikSharedDirtyPagesDiff, ' ', 10, true) + " ) |\n");
+ stringBuilder.append("+------------------------------+---------------+-----------------+\n");
+
+ this.mPreviousDalvikProportionalSetSize = dalvikProportionalSetSize;
+ this.mPreviousDalvikPrivateDirtyPages = dalvikPrivateDirtyPages;
+ this.mPreviousDalvikSharedDirtyPages = dalvikSharedDirtyPages;
+ }
+
+ if (this.mLogNativeHeap) {
+ final long nativeHeapSize = SystemUtils.getNativeHeapSize();
+ final long nativeHeapFreeSize = SystemUtils.getNativeHeapFreeSize();
+ final long nativeHeapAllocatedSize = SystemUtils.getNativeHeapAllocatedSize();
+
+ final long nativeHeapSizeDiff = nativeHeapSize - this.mPreviousNativeHeapSize;
+ final long nativeHeapFreeSizeDiff = nativeHeapFreeSize - this.mPreviousNativeHeapFreeSize;
+ final long nativeHeapAllocatedSizeDiff = nativeHeapAllocatedSize - this.mPreviousNativeHeapAllocatedSize;
+
+ stringBuilder.append("| Native memory size | " + MemoryLogger.formatRight(nativeHeapSize, ' ', 10) + " kB | (" + MemoryLogger.formatRight(nativeHeapSizeDiff, ' ', 10, true) + " kB) |\n");
+ stringBuilder.append("| Native memory free size | " + MemoryLogger.formatRight(nativeHeapFreeSize, ' ', 10) + " kB | (" + MemoryLogger.formatRight(nativeHeapFreeSizeDiff, ' ', 10, true) + " kB) |\n");
+ stringBuilder.append("| Native memory allocated size | " + MemoryLogger.formatRight(nativeHeapAllocatedSize, ' ', 10) + " kB | (" + MemoryLogger.formatRight(nativeHeapAllocatedSizeDiff, ' ', 10, true) + " kB) |\n");
+ stringBuilder.append("+------------------------------+---------------+-----------------+\n");
+
+ this.mPreviousNativeHeapSize = nativeHeapSize;
+ this.mPreviousNativeHeapFreeSize = nativeHeapFreeSize;
+ this.mPreviousNativeHeapAllocatedSize = nativeHeapAllocatedSize;
+ }
+
+ if (this.mLogNativeMemoryInfo) {
+ final long nativeProportionalSetSize = SystemUtils.getNativeProportionalSetSize();
+ final long nativePrivateDirtyPages = SystemUtils.getNativePrivateDirtyPages();
+ final long nativeSharedDirtyPages = SystemUtils.getNativeSharedDirtyPages();
+
+ final long nativeProportionalSetSizeDiff = nativeProportionalSetSize - this.mPreviousNativeProportionalSetSize;
+ final long nativePrivateDirtyPagesDiff = nativePrivateDirtyPages - this.mPreviousNativePrivateDirtyPages;
+ final long nativeSharedDirtyPagesDiff = nativeSharedDirtyPages - this.mPreviousNativeSharedDirtyPages;
+
+ stringBuilder.append("| Native proportional set size | " + MemoryLogger.formatRight(nativeProportionalSetSize, ' ', 10) + " | (" + MemoryLogger.formatRight(nativeProportionalSetSizeDiff, ' ', 10, true) + " ) |\n");
+ stringBuilder.append("| Native private dirty pages | " + MemoryLogger.formatRight(nativePrivateDirtyPages, ' ', 10) + " | (" + MemoryLogger.formatRight(nativePrivateDirtyPagesDiff, ' ', 10, true) + " ) |\n");
+ stringBuilder.append("| Native shared dirty pages | " + MemoryLogger.formatRight(nativeSharedDirtyPages, ' ', 10) + " | (" + MemoryLogger.formatRight(nativeSharedDirtyPagesDiff, ' ', 10, true) + " ) |\n");
+ stringBuilder.append("+------------------------------+---------------+-----------------+\n");
+
+ this.mPreviousNativeProportionalSetSize = nativeProportionalSetSize;
+ this.mPreviousNativePrivateDirtyPages = nativePrivateDirtyPages;
+ this.mPreviousNativeSharedDirtyPages = nativeSharedDirtyPages;
+ }
+
+ Debug.log(this.mDebugLevel, stringBuilder.toString());
+ } catch (final SystemUtilsException e) {
+ Debug.e(e);
+ }
+ System.gc();
+ }
+ }
+
+ public static final CharSequence formatRight(final long pLong, final char pPadChar, final int pLength) {
+ return MemoryLogger.formatRight(pLong, pPadChar, pLength, false);
+ }
+
+ public static final CharSequence formatRight(final long pLong, final char pPadChar, final int pLength, final boolean pAddPositiveSign) {
+ if ((pLong > 0) && pAddPositiveSign) {
+ return TextUtils.padFront("+" + String.valueOf(pLong), pPadChar, pLength);
+ } else {
+ return TextUtils.padFront(String.valueOf(pLong), pPadChar, pLength);
+ }
+ }
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
diff --git a/src/org/andengine/entity/util/ScreenCapture.java b/src/org/andengine/entity/util/ScreenCapture.java
index 4e69edd37..53b78579d 100644
--- a/src/org/andengine/entity/util/ScreenCapture.java
+++ b/src/org/andengine/entity/util/ScreenCapture.java
@@ -14,9 +14,9 @@
import android.graphics.Bitmap.CompressFormat;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:11:50 - 15.03.2010
*/
@@ -25,6 +25,8 @@ public class ScreenCapture extends Entity implements IScreenGrabberCallback {
// Constants
// ===========================================================
+ private static final int PNG_QUALITY_MAXIMUM = 100;
+
// ===========================================================
// Fields
// ===========================================================
@@ -95,9 +97,9 @@ private static void saveCapture(final Bitmap pBitmap, final String pFilePath) th
FileOutputStream out = null;
try {
out = new FileOutputStream(pFilePath);
- pBitmap.compress(CompressFormat.PNG, 100, out);
+ pBitmap.compress(CompressFormat.PNG, PNG_QUALITY_MAXIMUM, out);
} catch (final FileNotFoundException e) {
- StreamUtils.flushCloseStream(out);
+ StreamUtils.flushAndCloseStream(out);
Debug.e("Error saving file to: " + pFilePath, e);
throw e;
}
diff --git a/src/org/andengine/entity/util/ScreenGrabber.java b/src/org/andengine/entity/util/ScreenGrabber.java
index dfc70557b..371e76464 100644
--- a/src/org/andengine/entity/util/ScreenGrabber.java
+++ b/src/org/andengine/entity/util/ScreenGrabber.java
@@ -4,6 +4,7 @@
import org.andengine.engine.camera.Camera;
import org.andengine.entity.Entity;
+import org.andengine.opengl.util.GLHelper;
import org.andengine.opengl.util.GLState;
import android.graphics.Bitmap;
@@ -11,9 +12,9 @@
import android.opengl.GLES20;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:27:22 - 10.01.2011
*/
@@ -31,7 +32,7 @@ public class ScreenGrabber extends Entity {
private int mGrabWidth;
private int mGrabHeight;
- private boolean mScreenGrabPending = false;
+ private boolean mScreenGrabPending;
private IScreenGrabberCallback mScreenGrabCallback;
// ===========================================================
@@ -48,7 +49,7 @@ public class ScreenGrabber extends Entity {
@Override
protected void onManagedDraw(final GLState pGLState, final Camera pCamera) {
- if(this.mScreenGrabPending) {
+ if (this.mScreenGrabPending) {
try {
final Bitmap screenGrab = ScreenGrabber.grab(this.mGrabX, this.mGrabY, this.mGrabWidth, this.mGrabHeight);
@@ -90,31 +91,16 @@ public void grab(final int pGrabX, final int pGrabY, final int pGrabWidth, final
}
private static Bitmap grab(final int pGrabX, final int pGrabY, final int pGrabWidth, final int pGrabHeight) {
- final int[] source = new int[pGrabWidth * (pGrabY + pGrabHeight)];
- final IntBuffer sourceBuffer = IntBuffer.wrap(source);
- sourceBuffer.position(0);
+ final int[] pixelsRGBA_8888 = new int[pGrabWidth * pGrabHeight];
+ final IntBuffer pixelsRGBA_8888_Buffer = IntBuffer.wrap(pixelsRGBA_8888);
// TODO Check availability of OpenGL and GLES20.GL_RGBA combinations that require less conversion operations.
- // Note: There is (said to be) a bug with glReadPixels when 'y != 0', so we simply read starting from 'y == 0'.
- // TODO Does that bug still exist?
- GLES20.glReadPixels(pGrabX, 0, pGrabWidth, pGrabY + pGrabHeight, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, sourceBuffer);
-
- final int[] pixels = new int[pGrabWidth * pGrabHeight];
-
- // Convert from RGBA_8888 (Which is actually ABGR as the whole buffer seems to be inverted) --> ARGB_8888
- for (int y = 0; y < pGrabHeight; y++) {
- for (int x = 0; x < pGrabWidth; x++) {
- final int pixel = source[x + ((pGrabY + y) * pGrabWidth)];
-
- final int blue = (pixel & 0x00FF0000) >> 16;
- final int red = (pixel & 0x000000FF) << 16;
- final int greenAlpha = pixel & 0xFF00FF00;
-
- pixels[x + ((pGrabHeight - y - 1) * pGrabWidth)] = greenAlpha | red | blue;
- }
- }
+ GLES20.glReadPixels(pGrabX, pGrabY, pGrabWidth, pGrabHeight, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelsRGBA_8888_Buffer);
+
+ /* Convert from RGBA_8888 (Which is actually ABGR as the whole buffer seems to be inverted) --> ARGB_8888. */
+ final int[] pixelsARGB_8888 = GLHelper.convertRGBA_8888toARGB_8888(pixelsRGBA_8888);
- return Bitmap.createBitmap(pixels, pGrabWidth, pGrabHeight, Config.ARGB_8888);
+ return Bitmap.createBitmap(pixelsARGB_8888, pGrabWidth, pGrabHeight, Config.ARGB_8888);
}
// ===========================================================
diff --git a/src/org/andengine/entity/util/TextureMemoryLogger.java b/src/org/andengine/entity/util/TextureMemoryLogger.java
new file mode 100644
index 000000000..36a60acf7
--- /dev/null
+++ b/src/org/andengine/entity/util/TextureMemoryLogger.java
@@ -0,0 +1,102 @@
+package org.andengine.entity.util;
+
+import org.andengine.BuildConfig;
+import org.andengine.engine.handler.IUpdateHandler;
+import org.andengine.opengl.texture.TextureManager;
+import org.andengine.util.debug.Debug;
+import org.andengine.util.debug.Debug.DebugLevel;
+
+/**
+ * (c) 2013 Nicolas Gramlich
+ *
+ * @author Arturo GutiƩrrez
+ * @author Nicolas Gramlich
+ * @since 22:07:46 - 03.03.2013
+ */
+public class TextureMemoryLogger implements IUpdateHandler {
+ // ===========================================================
+ // Constants
+ // ===========================================================
+
+ private static final float AVERAGE_DURATION_DEFAULT = 5;
+
+ // ===========================================================
+ // Fields
+ // ===========================================================
+
+ private final TextureManager mTextureManager;
+
+ private final float mAverageDuration;
+ private float mSecondsElapsed;
+
+ private int mTextureMemoryUsedMax;
+ private int mTexturesLoadedCountMax;
+
+ private final DebugLevel mDebugLevel;
+
+ // ===========================================================
+ // Constructors
+ // ===========================================================
+
+ public TextureMemoryLogger(final TextureManager pTextureManager) {
+ this(pTextureManager, DebugLevel.DEBUG);
+ }
+
+ public TextureMemoryLogger(final TextureManager pTextureManager, final DebugLevel pDebugLevel) {
+ this(pTextureManager, TextureMemoryLogger.AVERAGE_DURATION_DEFAULT);
+ }
+
+ public TextureMemoryLogger(final TextureManager pTextureManager, final float pAverageDuration) {
+ this(pTextureManager, pAverageDuration, DebugLevel.DEBUG);
+ }
+
+ public TextureMemoryLogger(final TextureManager pTextureManager, final float pAverageDuration, final DebugLevel pDebugLevel) {
+ this.mTextureManager = pTextureManager;
+ this.mAverageDuration = pAverageDuration;
+ this.mDebugLevel = pDebugLevel;
+ }
+
+ // ===========================================================
+ // Getter & Setter
+ // ===========================================================
+
+ // ===========================================================
+ // Methods for/from SuperClass/Interfaces
+ // ===========================================================
+
+ @Override
+ public void onUpdate(final float pSecondsElapsed) {
+ this.mSecondsElapsed += pSecondsElapsed;
+
+ if (this.mSecondsElapsed > this.mAverageDuration) {
+ this.onHandleAverageDurationElapsed();
+
+ this.mSecondsElapsed -= this.mAverageDuration;
+ }
+ }
+
+ @Override
+ public void reset() {
+ this.mSecondsElapsed = 0;
+ }
+
+ // ===========================================================
+ // Methods
+ // ===========================================================
+
+ private void onHandleAverageDurationElapsed() {
+ if (BuildConfig.DEBUG) {
+ final int texturesLoadedCount = this.mTextureManager.getTexturesLoadedCount();
+ final int textureMemoryUsed = this.mTextureManager.getTextureMemoryUsed();
+
+ this.mTexturesLoadedCountMax = Math.max(texturesLoadedCount, this.mTexturesLoadedCountMax);
+ this.mTextureMemoryUsedMax = Math.max(textureMemoryUsed, this.mTextureMemoryUsedMax);
+
+ Debug.log(this.mDebugLevel, String.format("MEM: %d kB in %d textures (MAX: %d kB in %d textures)", textureMemoryUsed, texturesLoadedCount, this.mTextureMemoryUsedMax, this.mTexturesLoadedCountMax));
+ }
+ }
+
+ // ===========================================================
+ // Inner and Anonymous Classes
+ // ===========================================================
+}
\ No newline at end of file
diff --git a/src/org/andengine/input/sensor/BaseSensorData.java b/src/org/andengine/input/sensor/BaseSensorData.java
index 5af5c2489..4633f9d5c 100644
--- a/src/org/andengine/input/sensor/BaseSensorData.java
+++ b/src/org/andengine/input/sensor/BaseSensorData.java
@@ -3,9 +3,9 @@
import java.util.Arrays;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 16:50:44 - 10.03.2010
*/
@@ -26,10 +26,8 @@ public class BaseSensorData {
// Constructors
// ===========================================================
- public BaseSensorData(final int pValueCount, int pDisplayRotation) {
+ public BaseSensorData(final int pValueCount) {
this.mValues = new float[pValueCount];
-
- this.mDisplayRotation = pDisplayRotation;
}
// ===========================================================
@@ -44,12 +42,20 @@ public void setValues(final float[] pValues) {
System.arraycopy(pValues, 0, this.mValues, 0, pValues.length);
}
+ public int getAccuracy() {
+ return this.mAccuracy;
+ }
+
public void setAccuracy(final int pAccuracy) {
this.mAccuracy = pAccuracy;
}
- public int getAccuracy() {
- return this.mAccuracy;
+ public int getDisplayRotation() {
+ return this.mDisplayRotation;
+ }
+
+ public void setDisplayRotation(final int pDisplayRotation) {
+ this.mDisplayRotation = pDisplayRotation;
}
// ===========================================================
diff --git a/src/org/andengine/input/sensor/SensorDelay.java b/src/org/andengine/input/sensor/SensorDelay.java
index ef8cf082c..99ae2d9f8 100644
--- a/src/org/andengine/input/sensor/SensorDelay.java
+++ b/src/org/andengine/input/sensor/SensorDelay.java
@@ -4,9 +4,9 @@
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 11:14:38 - 31.10.2010
*/
diff --git a/src/org/andengine/input/sensor/acceleration/AccelerationData.java b/src/org/andengine/input/sensor/acceleration/AccelerationData.java
index 61392a73b..47fc7e784 100644
--- a/src/org/andengine/input/sensor/acceleration/AccelerationData.java
+++ b/src/org/andengine/input/sensor/acceleration/AccelerationData.java
@@ -8,9 +8,9 @@
import android.view.Surface;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 16:50:44 - 10.03.2010
*/
@@ -26,7 +26,7 @@ public class AccelerationData extends BaseSensorData {
@Override
public void swapAxis(final float[] pValues) {
final float x = -pValues[SensorManager.DATA_X];
- final float y = pValues[SensorManager.DATA_Y];
+ final float y = -pValues[SensorManager.DATA_Y];
pValues[SensorManager.DATA_X] = x;
pValues[SensorManager.DATA_Y] = y;
}
@@ -36,7 +36,7 @@ public void swapAxis(final float[] pValues) {
@Override
public void swapAxis(final float[] pValues) {
final float x = pValues[SensorManager.DATA_Y];
- final float y = pValues[SensorManager.DATA_X];
+ final float y = -pValues[SensorManager.DATA_X];
pValues[SensorManager.DATA_X] = x;
pValues[SensorManager.DATA_Y] = y;
}
@@ -46,7 +46,7 @@ public void swapAxis(final float[] pValues) {
@Override
public void swapAxis(final float[] pValues) {
final float x = pValues[SensorManager.DATA_X];
- final float y = -pValues[SensorManager.DATA_Y];
+ final float y = pValues[SensorManager.DATA_Y];
pValues[SensorManager.DATA_X] = x;
pValues[SensorManager.DATA_Y] = y;
}
@@ -56,7 +56,7 @@ public void swapAxis(final float[] pValues) {
@Override
public void swapAxis(final float[] pValues) {
final float x = -pValues[SensorManager.DATA_Y];
- final float y = -pValues[SensorManager.DATA_X];
+ final float y = pValues[SensorManager.DATA_X];
pValues[SensorManager.DATA_X] = x;
pValues[SensorManager.DATA_Y] = y;
}
@@ -71,8 +71,8 @@ public void swapAxis(final float[] pValues) {
// Constructors
// ===========================================================
- public AccelerationData(final int pDisplayOrientation) {
- super(3, pDisplayOrientation);
+ public AccelerationData() {
+ super(3);
}
// ===========================================================
@@ -100,7 +100,7 @@ public void setY(final float pY) {
}
public void setZ(final float pZ) {
- this.mValues[SensorManager.DATA_Z] = pZ;
+ this.mValues[SensorManager.DATA_Z] = pZ;
}
@Override
diff --git a/src/org/andengine/input/sensor/acceleration/AccelerationSensorOptions.java b/src/org/andengine/input/sensor/acceleration/AccelerationSensorOptions.java
index 675b76bbf..b68bf6b68 100644
--- a/src/org/andengine/input/sensor/acceleration/AccelerationSensorOptions.java
+++ b/src/org/andengine/input/sensor/acceleration/AccelerationSensorOptions.java
@@ -3,9 +3,9 @@
import org.andengine.input.sensor.SensorDelay;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 11:10:34 - 31.10.2010
*/
diff --git a/src/org/andengine/input/sensor/acceleration/IAccelerationListener.java b/src/org/andengine/input/sensor/acceleration/IAccelerationListener.java
index e37893a68..0bf394a1a 100644
--- a/src/org/andengine/input/sensor/acceleration/IAccelerationListener.java
+++ b/src/org/andengine/input/sensor/acceleration/IAccelerationListener.java
@@ -1,9 +1,9 @@
package org.andengine.input.sensor.acceleration;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 16:58:38 - 10.03.2010
*/
diff --git a/src/org/andengine/input/sensor/location/ILocationListener.java b/src/org/andengine/input/sensor/location/ILocationListener.java
index 117f31503..6eeb8c2b3 100644
--- a/src/org/andengine/input/sensor/location/ILocationListener.java
+++ b/src/org/andengine/input/sensor/location/ILocationListener.java
@@ -5,9 +5,9 @@
import android.os.Bundle;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 10:39:23 - 31.10.2010
*/
diff --git a/src/org/andengine/input/sensor/location/LocationProviderStatus.java b/src/org/andengine/input/sensor/location/LocationProviderStatus.java
index 0ef84e35c..ec003407e 100644
--- a/src/org/andengine/input/sensor/location/LocationProviderStatus.java
+++ b/src/org/andengine/input/sensor/location/LocationProviderStatus.java
@@ -1,9 +1,9 @@
package org.andengine.input.sensor.location;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 10:55:57 - 31.10.2010
*/
diff --git a/src/org/andengine/input/sensor/location/LocationSensorOptions.java b/src/org/andengine/input/sensor/location/LocationSensorOptions.java
index 8689b7667..74cdc3a60 100644
--- a/src/org/andengine/input/sensor/location/LocationSensorOptions.java
+++ b/src/org/andengine/input/sensor/location/LocationSensorOptions.java
@@ -5,9 +5,9 @@
import android.location.Criteria;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 11:02:12 - 31.10.2010
*/
@@ -33,15 +33,7 @@ public class LocationSensorOptions extends Criteria {
// ===========================================================
/**
- * @see {@link LocationSensorOptions#setAccuracy(int)},
- * {@link LocationSensorOptions#setAltitudeRequired(boolean)},
- * {@link LocationSensorOptions#setBearingRequired(boolean)},
- * {@link LocationSensorOptions#setCostAllowed(boolean)},
- * {@link LocationSensorOptions#setEnabledOnly(boolean)},
- * {@link LocationSensorOptions#setMinimumTriggerDistance(long)},
- * {@link LocationSensorOptions#setMinimumTriggerTime(long)},
- * {@link LocationSensorOptions#setPowerRequirement(int)},
- * {@link LocationSensorOptions#setSpeedRequired(boolean)}.
+ * @see {@link #setAccuracy(int)}, {@link #setAltitudeRequired(boolean)}, {@link #setBearingRequired(boolean)}, {@link #setCostAllowed(boolean)}, {@link #setEnabledOnly(boolean)}, {@link #setMinimumTriggerDistance(long)}, {@link #setMinimumTriggerTime(long)}, {@link #setPowerRequirement(int)}, {@link #setSpeedRequired(boolean)}.
*/
public LocationSensorOptions() {
diff --git a/src/org/andengine/input/sensor/orientation/IOrientationListener.java b/src/org/andengine/input/sensor/orientation/IOrientationListener.java
index 1964f509f..6cd1da4ed 100644
--- a/src/org/andengine/input/sensor/orientation/IOrientationListener.java
+++ b/src/org/andengine/input/sensor/orientation/IOrientationListener.java
@@ -1,9 +1,9 @@
package org.andengine.input.sensor.orientation;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 11:30:42 - 25.05.2010
*/
diff --git a/src/org/andengine/input/sensor/orientation/OrientationData.java b/src/org/andengine/input/sensor/orientation/OrientationData.java
index 3f503cc7b..7d56e1baf 100644
--- a/src/org/andengine/input/sensor/orientation/OrientationData.java
+++ b/src/org/andengine/input/sensor/orientation/OrientationData.java
@@ -9,9 +9,9 @@
import android.view.Surface;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 11:30:33 - 25.05.2010
*/
@@ -34,8 +34,8 @@ public class OrientationData extends BaseSensorData {
// Constructors
// ===========================================================
- public OrientationData(final int pDisplayRotation) {
- super(3, pDisplayRotation);
+ public OrientationData() {
+ super(3);
}
// ===========================================================
@@ -68,11 +68,13 @@ public void setAccuracy(final int pAccuracy) {
public void setAccelerationValues(final float[] pValues) {
System.arraycopy(pValues, 0, this.mAccelerationValues, 0, pValues.length);
+
this.updateOrientation();
}
public void setMagneticFieldValues(final float[] pValues) {
System.arraycopy(pValues, 0, this.mMagneticFieldValues, 0, pValues.length);
+
this.updateOrientation();
}
@@ -80,7 +82,7 @@ private void updateOrientation() {
SensorManager.getRotationMatrix(this.mRotationMatrix, null, this.mAccelerationValues, this.mMagneticFieldValues);
// TODO Use dont't use identical matrixes in remapCoordinateSystem, due to performance reasons.
- switch(this.mDisplayRotation) {
+ switch (this.mDisplayRotation) {
case Surface.ROTATION_0:
/* Nothing. */
break;
@@ -98,7 +100,7 @@ private void updateOrientation() {
final float[] values = this.mValues;
SensorManager.getOrientation(this.mRotationMatrix, values);
- for(int i = values.length - 1; i >= 0; i--) {
+ for (int i = values.length - 1; i >= 0; i--) {
values[i] = values[i] * MathConstants.RAD_TO_DEG;
}
}
diff --git a/src/org/andengine/input/sensor/orientation/OrientationSensorOptions.java b/src/org/andengine/input/sensor/orientation/OrientationSensorOptions.java
index 5945a010a..200440377 100644
--- a/src/org/andengine/input/sensor/orientation/OrientationSensorOptions.java
+++ b/src/org/andengine/input/sensor/orientation/OrientationSensorOptions.java
@@ -3,9 +3,9 @@
import org.andengine.input.sensor.SensorDelay;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 11:12:36 - 31.10.2010
*/
diff --git a/src/org/andengine/input/touch/TouchEvent.java b/src/org/andengine/input/touch/TouchEvent.java
index a56be937c..b58455349 100644
--- a/src/org/andengine/input/touch/TouchEvent.java
+++ b/src/org/andengine/input/touch/TouchEvent.java
@@ -5,9 +5,9 @@
import android.view.MotionEvent;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 10:17:42 - 13.07.2010
*/
@@ -77,6 +77,14 @@ public float getY() {
return this.mY;
}
+ public void setX(final float pX) {
+ this.mX = pX;
+ }
+
+ public void setY(final float pY) {
+ this.mY = pY;
+ }
+
public void set(final float pX, final float pY) {
this.mX = pX;
this.mY = pY;
diff --git a/src/org/andengine/input/touch/controller/BaseTouchController.java b/src/org/andengine/input/touch/controller/BaseTouchController.java
index 1afab377e..0fdbbf441 100644
--- a/src/org/andengine/input/touch/controller/BaseTouchController.java
+++ b/src/org/andengine/input/touch/controller/BaseTouchController.java
@@ -9,11 +9,11 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 21:06:40 - 13.07.2010
*/
-public abstract class BaseTouchController implements ITouchController {
+public abstract class BaseTouchController implements ITouchController {
// ===========================================================
// Constants
// ===========================================================
diff --git a/src/org/andengine/input/touch/controller/ITouchController.java b/src/org/andengine/input/touch/controller/ITouchController.java
index 06ffcf93c..888a41800 100644
--- a/src/org/andengine/input/touch/controller/ITouchController.java
+++ b/src/org/andengine/input/touch/controller/ITouchController.java
@@ -5,9 +5,9 @@
import android.view.MotionEvent;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 20:23:45 - 13.07.2010
*/
diff --git a/src/org/andengine/input/touch/controller/ITouchEventCallback.java b/src/org/andengine/input/touch/controller/ITouchEventCallback.java
index a79a2a46c..6e1003252 100644
--- a/src/org/andengine/input/touch/controller/ITouchEventCallback.java
+++ b/src/org/andengine/input/touch/controller/ITouchEventCallback.java
@@ -3,7 +3,7 @@
import org.andengine.input.touch.TouchEvent;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 16:44:26 - 04.04.2012
diff --git a/src/org/andengine/input/touch/controller/MultiTouch.java b/src/org/andengine/input/touch/controller/MultiTouch.java
index 067118a5d..e5c8a5b97 100644
--- a/src/org/andengine/input/touch/controller/MultiTouch.java
+++ b/src/org/andengine/input/touch/controller/MultiTouch.java
@@ -8,11 +8,11 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 16:00:38 - 14.07.2010
*/
-public class MultiTouch {
+public final class MultiTouch {
// ===========================================================
// Constants
// ===========================================================
@@ -21,13 +21,17 @@ public class MultiTouch {
// Fields
// ===========================================================
- private static Boolean SUPPORTED = null;
- private static Boolean SUPPORTED_DISTINCT = null;
+ private static Boolean sSupported;
+ private static Boolean sSupportedDistinct;
// ===========================================================
// Constructors
// ===========================================================
+ private MultiTouch() {
+
+ }
+
// ===========================================================
// Getter & Setter
// ===========================================================
@@ -41,19 +45,19 @@ public class MultiTouch {
// ===========================================================
public static boolean isSupported(final Context pContext) {
- if(MultiTouch.SUPPORTED == null) {
- MultiTouch.SUPPORTED = SystemUtils.hasSystemFeature(pContext, PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
+ if (MultiTouch.sSupported == null) {
+ MultiTouch.sSupported = SystemUtils.hasSystemFeature(pContext, PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH, false);
}
- return MultiTouch.SUPPORTED;
+ return MultiTouch.sSupported;
}
public static boolean isSupportedDistinct(final Context pContext) {
- if(MultiTouch.SUPPORTED_DISTINCT == null) {
- MultiTouch.SUPPORTED_DISTINCT = SystemUtils.hasSystemFeature(pContext, PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT);
+ if (MultiTouch.sSupportedDistinct == null) {
+ MultiTouch.sSupportedDistinct = SystemUtils.hasSystemFeature(pContext, PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT, false);
}
- return MultiTouch.SUPPORTED_DISTINCT;
+ return MultiTouch.sSupportedDistinct;
}
// ===========================================================
diff --git a/src/org/andengine/input/touch/controller/MultiTouchController.java b/src/org/andengine/input/touch/controller/MultiTouchController.java
index 747e1ecab..3bde441f4 100644
--- a/src/org/andengine/input/touch/controller/MultiTouchController.java
+++ b/src/org/andengine/input/touch/controller/MultiTouchController.java
@@ -5,7 +5,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 20:23:33 - 13.07.2010
*/
@@ -33,7 +33,7 @@ public class MultiTouchController extends BaseTouchController {
@Override
public void onHandleMotionEvent(final MotionEvent pMotionEvent) {
final int action = pMotionEvent.getAction() & MotionEvent.ACTION_MASK;
- switch(action) {
+ switch (action) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
this.onHandleTouchAction(MotionEvent.ACTION_DOWN, pMotionEvent);
@@ -59,7 +59,7 @@ public void onHandleMotionEvent(final MotionEvent pMotionEvent) {
// ===========================================================
private void onHandleTouchMove(final MotionEvent pMotionEvent) {
- for(int i = pMotionEvent.getPointerCount() - 1; i >= 0; i--) {
+ for (int i = pMotionEvent.getPointerCount() - 1; i >= 0; i--) {
final int pointerIndex = i;
final int pointerID = pMotionEvent.getPointerId(pointerIndex);
this.fireTouchEvent(pMotionEvent.getX(pointerIndex), pMotionEvent.getY(pointerIndex), MotionEvent.ACTION_MOVE, pointerID, pMotionEvent);
diff --git a/src/org/andengine/input/touch/controller/SingleTouchController.java b/src/org/andengine/input/touch/controller/SingleTouchController.java
index e0eeeefab..6e0a1d236 100644
--- a/src/org/andengine/input/touch/controller/SingleTouchController.java
+++ b/src/org/andengine/input/touch/controller/SingleTouchController.java
@@ -3,9 +3,9 @@
import android.view.MotionEvent;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 20:23:33 - 13.07.2010
*/
diff --git a/src/org/andengine/input/touch/detector/BaseDetector.java b/src/org/andengine/input/touch/detector/BaseDetector.java
index 8a66f27c7..a97e6d418 100644
--- a/src/org/andengine/input/touch/detector/BaseDetector.java
+++ b/src/org/andengine/input/touch/detector/BaseDetector.java
@@ -7,7 +7,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 15:59:00 - 05.11.2010
*/
@@ -52,7 +52,7 @@ public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouc
}
public final boolean onTouchEvent(final TouchEvent pSceneTouchEvent) {
- if(this.mEnabled) {
+ if (this.mEnabled) {
return this.onManagedTouchEvent(pSceneTouchEvent);
} else {
return false;
diff --git a/src/org/andengine/input/touch/detector/ClickDetector.java b/src/org/andengine/input/touch/detector/ClickDetector.java
index 1059a8dc4..4a5153ba1 100644
--- a/src/org/andengine/input/touch/detector/ClickDetector.java
+++ b/src/org/andengine/input/touch/detector/ClickDetector.java
@@ -5,7 +5,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @author Greg Haynes
* @since 14:29:59 - 16.08.2010
@@ -65,23 +65,34 @@ public void reset() {
@Override
public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
- switch(pSceneTouchEvent.getAction()) {
+ switch (pSceneTouchEvent.getAction()) {
case TouchEvent.ACTION_DOWN:
this.prepareClick(pSceneTouchEvent);
return true;
+ case TouchEvent.ACTION_MOVE:
+ if (this.mPointerID == pSceneTouchEvent.getPointerID()) {
+ final long moveTimeMilliseconds = pSceneTouchEvent.getMotionEvent().getEventTime();
+ if (moveTimeMilliseconds - this.mDownTimeMilliseconds <= this.mTriggerClickMaximumMilliseconds) {
+ return true;
+ }
+ }
+ return false;
case TouchEvent.ACTION_UP:
case TouchEvent.ACTION_CANCEL:
- if(this.mPointerID == pSceneTouchEvent.getPointerID()) {
- boolean handled = false;
+ if (this.mPointerID == pSceneTouchEvent.getPointerID()) {
final long upTimeMilliseconds = pSceneTouchEvent.getMotionEvent().getEventTime();
- if(upTimeMilliseconds - this.mDownTimeMilliseconds <= this.mTriggerClickMaximumMilliseconds) {
+ boolean handled;
+ if (upTimeMilliseconds - this.mDownTimeMilliseconds <= this.mTriggerClickMaximumMilliseconds) {
this.mDownTimeMilliseconds = Long.MIN_VALUE;
- this.mClickDetectorListener.onClick(this, pSceneTouchEvent.getPointerID(), pSceneTouchEvent.getX(), pSceneTouchEvent.getY());
+ this.mClickDetectorListener.onClick(this, this.mPointerID, pSceneTouchEvent.getX(), pSceneTouchEvent.getY());
handled = true;
+ } else {
+ handled = false;
}
this.mPointerID = TouchEvent.INVALID_POINTER_ID;
+
return handled;
} else {
return false;
@@ -94,7 +105,7 @@ public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
// ===========================================================
// Methods
// ===========================================================
-
+
private void prepareClick(final TouchEvent pSceneTouchEvent) {
this.mDownTimeMilliseconds = pSceneTouchEvent.getMotionEvent().getDownTime();
this.mPointerID = pSceneTouchEvent.getPointerID();
diff --git a/src/org/andengine/input/touch/detector/ContinuousHoldDetector.java b/src/org/andengine/input/touch/detector/ContinuousHoldDetector.java
index cfd2b8523..513c2bfbb 100644
--- a/src/org/andengine/input/touch/detector/ContinuousHoldDetector.java
+++ b/src/org/andengine/input/touch/detector/ContinuousHoldDetector.java
@@ -11,10 +11,10 @@
/**
* Note: Needs to be registered as an {@link IUpdateHandler} to the {@link Engine} or {@link Scene} to work properly.
- *
+ *
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @author Greg Haynes
* @since 20:49:25 - 23.08.2010
@@ -65,7 +65,7 @@ public void onUpdate(final float pSecondsElapsed) {
}
/**
- * When {@link ContinuousHoldDetector#isHolding()} this method will call through to {@link IHoldDetectorListener#onHoldFinished(HoldDetector, long, int, float, float)}.
+ * When {@link #isHolding()} this method will call through to {@link IHoldDetectorListener#onHoldFinished(HoldDetector, long, int, float, float)}.
*/
@Override
public void reset() {
@@ -77,9 +77,9 @@ public void reset() {
public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
final MotionEvent motionEvent = pSceneTouchEvent.getMotionEvent();
- switch(pSceneTouchEvent.getAction()) {
+ switch (pSceneTouchEvent.getAction()) {
case TouchEvent.ACTION_DOWN:
- if(this.mPointerID == TouchEvent.INVALID_POINTER_ID) {
+ if (this.mPointerID == TouchEvent.INVALID_POINTER_ID) {
this.prepareHold(pSceneTouchEvent);
return true;
} else {
@@ -87,7 +87,7 @@ public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
}
case TouchEvent.ACTION_MOVE:
{
- if(this.mPointerID == pSceneTouchEvent.getPointerID()) {
+ if (this.mPointerID == pSceneTouchEvent.getPointerID()) {
this.mHoldX = pSceneTouchEvent.getX();
this.mHoldY = pSceneTouchEvent.getY();
@@ -100,11 +100,11 @@ public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
case TouchEvent.ACTION_UP:
case TouchEvent.ACTION_CANCEL:
{
- if(this.mPointerID == pSceneTouchEvent.getPointerID()) {
+ if (this.mPointerID == pSceneTouchEvent.getPointerID()) {
this.mHoldX = pSceneTouchEvent.getX();
this.mHoldY = pSceneTouchEvent.getY();
- if(this.mTriggering) {
+ if (this.mTriggering) {
this.triggerOnHoldFinished(motionEvent.getEventTime() - this.mDownTimeMilliseconds);
}
@@ -130,12 +130,12 @@ protected void prepareHold(final TouchEvent pSceneTouchEvent) {
// ===========================================================
void fireListener() {
- if(this.mPointerID != TouchEvent.INVALID_POINTER_ID) {
+ if (this.mPointerID != TouchEvent.INVALID_POINTER_ID) {
final long holdTimeMilliseconds = System.currentTimeMillis() - this.mDownTimeMilliseconds;
- if(holdTimeMilliseconds >= this.mTriggerHoldMinimumMilliseconds) {
- if(this.mTriggering) {
+ if (holdTimeMilliseconds >= this.mTriggerHoldMinimumMilliseconds) {
+ if (this.mTriggering) {
this.triggerOnHold(holdTimeMilliseconds);
- } else if(!this.mMaximumDistanceExceeded) {
+ } else if (!this.mMaximumDistanceExceeded) {
this.triggerOnHoldStarted();
}
}
diff --git a/src/org/andengine/input/touch/detector/HoldDetector.java b/src/org/andengine/input/touch/detector/HoldDetector.java
index 63a6eeded..bb9bfcd8f 100644
--- a/src/org/andengine/input/touch/detector/HoldDetector.java
+++ b/src/org/andengine/input/touch/detector/HoldDetector.java
@@ -7,7 +7,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @author Greg Haynes
* @since 20:49:25 - 23.08.2010
@@ -65,7 +65,7 @@ public long getTriggerHoldMinimumMilliseconds() {
}
public void setTriggerHoldMinimumMilliseconds(final long pTriggerHoldMinimumMilliseconds) {
- if(pTriggerHoldMinimumMilliseconds < 0) {
+ if (pTriggerHoldMinimumMilliseconds < 0) {
throw new IllegalArgumentException("pTriggerHoldMinimumMilliseconds must not be < 0.");
}
this.mTriggerHoldMinimumMilliseconds = pTriggerHoldMinimumMilliseconds;
@@ -76,7 +76,7 @@ public float getTriggerHoldMaximumDistance() {
}
public void setTriggerHoldMaximumDistance(final float pTriggerHoldMaximumDistance) {
- if(pTriggerHoldMaximumDistance < 0) {
+ if (pTriggerHoldMaximumDistance < 0) {
throw new IllegalArgumentException("pTriggerHoldMaximumDistance must not be < 0.");
}
this.mTriggerHoldMaximumDistance = pTriggerHoldMaximumDistance;
@@ -91,11 +91,11 @@ public boolean isHolding() {
// ===========================================================
/**
- * When {@link HoldDetector#isHolding()} this method will call through to {@link IHoldDetectorListener#onHoldFinished(HoldDetector, long, int, float, float).
+ * When {@link #isHolding()} this method will call through to {@link IHoldDetectorListener#onHoldFinished(HoldDetector, long, int, float, float).
*/
@Override
public void reset() {
- if(this.mTriggering) {
+ if (this.mTriggering) {
this.triggerOnHoldFinished(System.currentTimeMillis() - this.mDownTimeMilliseconds);
}
@@ -109,9 +109,9 @@ public void reset() {
public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
final MotionEvent motionEvent = pSceneTouchEvent.getMotionEvent();
- switch(pSceneTouchEvent.getAction()) {
+ switch (pSceneTouchEvent.getAction()) {
case TouchEvent.ACTION_DOWN:
- if(this.mPointerID == TouchEvent.INVALID_POINTER_ID) {
+ if (this.mPointerID == TouchEvent.INVALID_POINTER_ID) {
this.prepareHold(pSceneTouchEvent);
return true;
} else {
@@ -119,20 +119,20 @@ public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
}
case TouchEvent.ACTION_MOVE:
{
- if(this.mPointerID == pSceneTouchEvent.getPointerID()) {
+ if (this.mPointerID == pSceneTouchEvent.getPointerID()) {
this.mHoldX = pSceneTouchEvent.getX();
this.mHoldY = pSceneTouchEvent.getY();
final long holdTimeMilliseconds = System.currentTimeMillis() - this.mDownTimeMilliseconds;
- if(holdTimeMilliseconds >= this.mTriggerHoldMinimumMilliseconds) {
- if(this.mTriggering) {
+ if (holdTimeMilliseconds >= this.mTriggerHoldMinimumMilliseconds) {
+ if (this.mTriggering) {
this.triggerOnHold(holdTimeMilliseconds);
} else {
final float triggerHoldMaximumDistance = this.mTriggerHoldMaximumDistance;
- this.mMaximumDistanceExceeded = this.mMaximumDistanceExceeded || Math.abs(this.mDownX - motionEvent.getX()) > triggerHoldMaximumDistance || Math.abs(this.mDownY - motionEvent.getY()) > triggerHoldMaximumDistance;
+ this.mMaximumDistanceExceeded = this.mMaximumDistanceExceeded || Math.abs(this.mDownX - motionEvent.getX()) > triggerHoldMaximumDistance || Math.abs(this.mDownY - motionEvent.getY()) > triggerHoldMaximumDistance;
- if(!this.mMaximumDistanceExceeded) {
- if(!this.mTriggering) {
+ if (!this.mMaximumDistanceExceeded) {
+ if (!this.mTriggering) {
this.triggerOnHoldStarted();
} else {
this.triggerOnHold(holdTimeMilliseconds);
@@ -148,19 +148,19 @@ public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
case TouchEvent.ACTION_UP:
case TouchEvent.ACTION_CANCEL:
{
- if(this.mPointerID == pSceneTouchEvent.getPointerID()) {
+ if (this.mPointerID == pSceneTouchEvent.getPointerID()) {
this.mHoldX = pSceneTouchEvent.getX();
this.mHoldY = pSceneTouchEvent.getY();
final long holdTimeMilliseconds = System.currentTimeMillis() - this.mDownTimeMilliseconds;
- if(holdTimeMilliseconds >= this.mTriggerHoldMinimumMilliseconds) {
- if(this.mTriggering) {
+ if (holdTimeMilliseconds >= this.mTriggerHoldMinimumMilliseconds) {
+ if (this.mTriggering) {
this.triggerOnHoldFinished(holdTimeMilliseconds);
} else {
final float triggerHoldMaximumDistance = this.mTriggerHoldMaximumDistance;
- this.mMaximumDistanceExceeded = this.mMaximumDistanceExceeded || Math.abs(this.mDownX - motionEvent.getX()) > triggerHoldMaximumDistance || Math.abs(this.mDownY - motionEvent.getY()) > triggerHoldMaximumDistance;
+ this.mMaximumDistanceExceeded = this.mMaximumDistanceExceeded || Math.abs(this.mDownX - motionEvent.getX()) > triggerHoldMaximumDistance || Math.abs(this.mDownY - motionEvent.getY()) > triggerHoldMaximumDistance;
- if(!this.mMaximumDistanceExceeded) {
+ if (!this.mMaximumDistanceExceeded) {
this.triggerOnHoldFinished(holdTimeMilliseconds);
}
}
@@ -191,7 +191,7 @@ protected void prepareHold(final TouchEvent pSceneTouchEvent) {
this.mHoldX = pSceneTouchEvent.getX();
this.mHoldY = pSceneTouchEvent.getY();
- if(this.mTriggerHoldMinimumMilliseconds == 0) {
+ if (this.mTriggerHoldMinimumMilliseconds == 0) {
this.triggerOnHoldStarted();
}
}
@@ -199,13 +199,13 @@ protected void prepareHold(final TouchEvent pSceneTouchEvent) {
protected void triggerOnHoldStarted() {
this.mTriggering = true;
- if(this.mPointerID != TouchEvent.INVALID_POINTER_ID) {
+ if (this.mPointerID != TouchEvent.INVALID_POINTER_ID) {
this.mHoldDetectorListener.onHoldStarted(this, this.mPointerID, this.mHoldX, this.mHoldY);
}
}
protected void triggerOnHold(final long pHoldTimeMilliseconds) {
- if(this.mPointerID != TouchEvent.INVALID_POINTER_ID) {
+ if (this.mPointerID != TouchEvent.INVALID_POINTER_ID) {
this.mHoldDetectorListener.onHold(this, pHoldTimeMilliseconds, this.mPointerID, this.mHoldX, this.mHoldY);
}
}
@@ -213,7 +213,7 @@ protected void triggerOnHold(final long pHoldTimeMilliseconds) {
protected void triggerOnHoldFinished(final long pHoldTimeMilliseconds) {
this.mTriggering = false;
- if(this.mPointerID != TouchEvent.INVALID_POINTER_ID) {
+ if (this.mPointerID != TouchEvent.INVALID_POINTER_ID) {
this.mHoldDetectorListener.onHoldFinished(this, pHoldTimeMilliseconds, this.mPointerID, this.mHoldX, this.mHoldY);
}
}
diff --git a/src/org/andengine/input/touch/detector/PinchZoomDetector.java b/src/org/andengine/input/touch/detector/PinchZoomDetector.java
index cf0275183..69852a38a 100644
--- a/src/org/andengine/input/touch/detector/PinchZoomDetector.java
+++ b/src/org/andengine/input/touch/detector/PinchZoomDetector.java
@@ -8,7 +8,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 19:16:19 - 04.11.2010
*/
@@ -51,11 +51,11 @@ public boolean isZooming() {
// ===========================================================
/**
- * When {@link PinchZoomDetector#isZooming()} this method will call through to {@link IPinchZoomDetectorListener#onPinchZoomFinished(PinchZoomDetector, TouchEvent, float)}.
+ * When {@link #isZooming()} this method will call through to {@link IPinchZoomDetectorListener#onPinchZoomFinished(PinchZoomDetector, TouchEvent, float)}.
*/
@Override
public void reset() {
- if(this.mPinchZooming) {
+ if (this.mPinchZooming) {
this.mPinchZoomDetectorListener.onPinchZoomFinished(this, null, this.getZoomFactor());
}
@@ -70,12 +70,12 @@ public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
final int action = motionEvent.getAction() & MotionEvent.ACTION_MASK;
- switch(action) {
+ switch (action) {
case MotionEvent.ACTION_POINTER_DOWN:
- if(!this.mPinchZooming && this.hasTwoOrMorePointers(motionEvent)) {
+ if (!this.mPinchZooming && PinchZoomDetector.hasTwoOrMorePointers(motionEvent)) {
this.mInitialDistance = PinchZoomDetector.calculatePointerDistance(motionEvent);
this.mCurrentDistance = this.mInitialDistance;
- if(this.mInitialDistance > PinchZoomDetector.TRIGGER_PINCHZOOM_MINIMUM_DISTANCE_DEFAULT) {
+ if (this.mInitialDistance > PinchZoomDetector.TRIGGER_PINCHZOOM_MINIMUM_DISTANCE_DEFAULT) {
this.mPinchZooming = true;
this.mPinchZoomDetectorListener.onPinchZoomStarted(this, pSceneTouchEvent);
}
@@ -84,16 +84,16 @@ public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
- if(this.mPinchZooming) {
+ if (this.mPinchZooming) {
this.mPinchZooming = false;
this.mPinchZoomDetectorListener.onPinchZoomFinished(this, pSceneTouchEvent, this.getZoomFactor());
}
break;
case MotionEvent.ACTION_MOVE:
- if(this.mPinchZooming) {
- if (this.hasTwoOrMorePointers(motionEvent)) {
+ if (this.mPinchZooming) {
+ if (PinchZoomDetector.hasTwoOrMorePointers(motionEvent)) {
this.mCurrentDistance = PinchZoomDetector.calculatePointerDistance(motionEvent);
- if(this.mCurrentDistance > PinchZoomDetector.TRIGGER_PINCHZOOM_MINIMUM_DISTANCE_DEFAULT) {
+ if (this.mCurrentDistance > PinchZoomDetector.TRIGGER_PINCHZOOM_MINIMUM_DISTANCE_DEFAULT) {
this.mPinchZoomDetectorListener.onPinchZoom(this, pSceneTouchEvent, this.getZoomFactor());
}
} else {
@@ -121,7 +121,7 @@ private static float calculatePointerDistance(final MotionEvent pMotionEvent) {
return MathUtils.distance(pMotionEvent.getX(0), pMotionEvent.getY(0), pMotionEvent.getX(1), pMotionEvent.getY(1));
}
- private boolean hasTwoOrMorePointers(final MotionEvent pMotionEvent) {
+ private static boolean hasTwoOrMorePointers(final MotionEvent pMotionEvent) {
return pMotionEvent.getPointerCount() >= 2;
}
diff --git a/src/org/andengine/input/touch/detector/ScrollDetector.java b/src/org/andengine/input/touch/detector/ScrollDetector.java
index dca6f9fb2..69bffb01e 100644
--- a/src/org/andengine/input/touch/detector/ScrollDetector.java
+++ b/src/org/andengine/input/touch/detector/ScrollDetector.java
@@ -5,7 +5,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 14:29:59 - 16.08.2010
*/
@@ -22,7 +22,7 @@ public class ScrollDetector extends BaseDetector {
private float mTriggerScrollMinimumDistance;
private final IScrollDetectorListener mScrollDetectorListener;
-
+
private int mPointerID = TouchEvent.INVALID_POINTER_ID;
private boolean mTriggering;
@@ -61,7 +61,7 @@ public void setTriggerScrollMinimumDistance(final float pTriggerScrollMinimumDis
@Override
public void reset() {
- if(this.mTriggering) {
+ if (this.mTriggering) {
this.mScrollDetectorListener.onScrollFinished(this, this.mPointerID, 0, 0);
}
@@ -76,26 +76,26 @@ public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
final float touchX = this.getX(pSceneTouchEvent);
final float touchY = this.getY(pSceneTouchEvent);
- switch(pSceneTouchEvent.getAction()) {
+ switch (pSceneTouchEvent.getAction()) {
case TouchEvent.ACTION_DOWN:
this.prepareScroll(pSceneTouchEvent.getPointerID(), touchX, touchY);
return true;
case TouchEvent.ACTION_MOVE:
- if(this.mPointerID == TouchEvent.INVALID_POINTER_ID) {
+ if (this.mPointerID == TouchEvent.INVALID_POINTER_ID) {
this.prepareScroll(pSceneTouchEvent.getPointerID(), touchX, touchY);
return true;
- } else if(this.mPointerID == pSceneTouchEvent.getPointerID()) {
+ } else if (this.mPointerID == pSceneTouchEvent.getPointerID()) {
final float distanceX = touchX - this.mLastX;
final float distanceY = touchY - this.mLastY;
final float triggerScrollMinimumDistance = this.mTriggerScrollMinimumDistance;
- if(this.mTriggering || Math.abs(distanceX) > triggerScrollMinimumDistance || Math.abs(distanceY) > triggerScrollMinimumDistance) {
- if(!this.mTriggering) {
+ if (this.mTriggering || Math.abs(distanceX) > triggerScrollMinimumDistance || Math.abs(distanceY) > triggerScrollMinimumDistance) {
+ if (!this.mTriggering) {
this.triggerOnScrollStarted(distanceX, distanceY);
} else {
this.triggerOnScroll(distanceX, distanceY);
}
-
+
this.mLastX = touchX;
this.mLastY = touchY;
this.mTriggering = true;
@@ -106,11 +106,11 @@ public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
}
case TouchEvent.ACTION_UP:
case TouchEvent.ACTION_CANCEL:
- if(this.mPointerID == pSceneTouchEvent.getPointerID()) {
+ if (this.mPointerID == pSceneTouchEvent.getPointerID()) {
final float distanceX = touchX - this.mLastX;
final float distanceY = touchY - this.mLastY;
- if(this.mTriggering) {
+ if (this.mTriggering) {
this.triggerOnScrollFinished(distanceX, distanceY);
}
@@ -125,30 +125,30 @@ public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
// ===========================================================
// Methods
// ===========================================================
-
+
private void prepareScroll(final int pPointerID, final float pTouchX, final float pTouchY) {
this.mLastX = pTouchX;
this.mLastY = pTouchY;
this.mTriggering = false;
this.mPointerID = pPointerID;
}
-
+
private void triggerOnScrollStarted(final float pDistanceX, final float pDistanceY) {
- if(this.mPointerID != TouchEvent.INVALID_POINTER_ID) {
+ if (this.mPointerID != TouchEvent.INVALID_POINTER_ID) {
this.mScrollDetectorListener.onScrollStarted(this, this.mPointerID, pDistanceX, pDistanceY);
}
}
-
+
private void triggerOnScroll(final float pDistanceX, final float pDistanceY) {
- if(this.mPointerID != TouchEvent.INVALID_POINTER_ID) {
+ if (this.mPointerID != TouchEvent.INVALID_POINTER_ID) {
this.mScrollDetectorListener.onScroll(this, this.mPointerID, pDistanceX, pDistanceY);
}
}
-
+
private void triggerOnScrollFinished(final float pDistanceX, final float pDistanceY) {
this.mTriggering = false;
-
- if(this.mPointerID != TouchEvent.INVALID_POINTER_ID) {
+
+ if (this.mPointerID != TouchEvent.INVALID_POINTER_ID) {
this.mScrollDetectorListener.onScrollFinished(this, this.mPointerID, pDistanceX, pDistanceY);
}
}
diff --git a/src/org/andengine/input/touch/detector/SurfaceGestureDetector.java b/src/org/andengine/input/touch/detector/SurfaceGestureDetector.java
index cc556347b..21ce4b58b 100644
--- a/src/org/andengine/input/touch/detector/SurfaceGestureDetector.java
+++ b/src/org/andengine/input/touch/detector/SurfaceGestureDetector.java
@@ -11,7 +11,7 @@
* @author rkpost
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 11:36:26 - 11.10.2010
*/
@@ -116,16 +116,16 @@ public boolean onFling(final MotionEvent pMotionEventStart, final MotionEvent pM
final boolean isHorizontalFling = Math.abs(pVelocityX) > Math.abs(pVelocityY);
- if(isHorizontalFling) {
- if(pMotionEventStart.getX() - pMotionEventEnd.getX() > swipeMinDistance) {
+ if (isHorizontalFling) {
+ if (pMotionEventStart.getX() - pMotionEventEnd.getX() > swipeMinDistance) {
return SurfaceGestureDetector.this.onSwipeLeft();
- } else if(pMotionEventEnd.getX() - pMotionEventStart.getX() > swipeMinDistance) {
+ } else if (pMotionEventEnd.getX() - pMotionEventStart.getX() > swipeMinDistance) {
return SurfaceGestureDetector.this.onSwipeRight();
}
} else {
- if(pMotionEventStart.getY() - pMotionEventEnd.getY() > swipeMinDistance) {
+ if (pMotionEventStart.getY() - pMotionEventEnd.getY() > swipeMinDistance) {
return SurfaceGestureDetector.this.onSwipeUp();
- } else if(pMotionEventEnd.getY() - pMotionEventStart.getY() > swipeMinDistance) {
+ } else if (pMotionEventEnd.getY() - pMotionEventStart.getY() > swipeMinDistance) {
return SurfaceGestureDetector.this.onSwipeDown();
}
}
diff --git a/src/org/andengine/input/touch/detector/SurfaceGestureDetectorAdapter.java b/src/org/andengine/input/touch/detector/SurfaceGestureDetectorAdapter.java
index 3c5cc03d1..f27fbf1f7 100644
--- a/src/org/andengine/input/touch/detector/SurfaceGestureDetectorAdapter.java
+++ b/src/org/andengine/input/touch/detector/SurfaceGestureDetectorAdapter.java
@@ -3,7 +3,7 @@
import android.content.Context;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 16:53:40 - 04.04.2012
@@ -23,7 +23,7 @@ public class SurfaceGestureDetectorAdapter extends SurfaceGestureDetector {
public SurfaceGestureDetectorAdapter(final Context pContext) {
super(pContext);
- }
+ }
public SurfaceGestureDetectorAdapter(final Context pContext, final float pSwipeMinDistance) {
super(pContext, pSwipeMinDistance);
diff --git a/src/org/andengine/input/touch/detector/SurfaceScrollDetector.java b/src/org/andengine/input/touch/detector/SurfaceScrollDetector.java
index 5ffb86b9c..1d4ae44e6 100644
--- a/src/org/andengine/input/touch/detector/SurfaceScrollDetector.java
+++ b/src/org/andengine/input/touch/detector/SurfaceScrollDetector.java
@@ -5,7 +5,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 16:12:29 - 16.08.2010
*/
diff --git a/src/org/andengine/opengl/GLES20Fix.java b/src/org/andengine/opengl/GLES20Fix.java
index 349b9b7d9..6f4a14c42 100644
--- a/src/org/andengine/opengl/GLES20Fix.java
+++ b/src/org/andengine/opengl/GLES20Fix.java
@@ -3,21 +3,23 @@
import org.andengine.util.exception.AndEngineRuntimeException;
import org.andengine.util.system.SystemUtils;
+import android.annotation.TargetApi;
import android.opengl.GLES20;
import android.os.Build;
/**
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 17:44:43 - 04.09.2011
*/
+@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public class GLES20Fix {
// ===========================================================
// Constants
// ===========================================================
- private static boolean NATIVE_LIB_LOADED;
+ private static final boolean NATIVE_LIB_LOADED;
/** Android issue 8931. */
private static final boolean WORKAROUND_MISSING_GLES20_METHODS;
@@ -32,8 +34,8 @@ public class GLES20Fix {
}
NATIVE_LIB_LOADED = loadLibrarySuccess;
- if(SystemUtils.isAndroidVersionOrLower(Build.VERSION_CODES.FROYO)) {
- if(loadLibrarySuccess) {
+ if (SystemUtils.isAndroidVersionOrLower(Build.VERSION_CODES.FROYO)) {
+ if (loadLibrarySuccess) {
WORKAROUND_MISSING_GLES20_METHODS = true;
} else {
throw new AndEngineRuntimeException("Inherently incompatible device detected.");
@@ -71,7 +73,7 @@ private GLES20Fix() {
public static native void glDrawElements(final int pMode, final int pCount, final int pType, final int pOffset);
public static void glVertexAttribPointerFix(final int pIndex, final int pSize, final int pType, final boolean pNormalized, final int pStride, final int pOffset) {
- if(GLES20Fix.WORKAROUND_MISSING_GLES20_METHODS) {
+ if (GLES20Fix.WORKAROUND_MISSING_GLES20_METHODS) {
GLES20Fix.glVertexAttribPointerFix(pIndex, pSize, pType, pNormalized, pStride, pOffset);
} else {
GLES20.glVertexAttribPointer(pIndex, pSize, pType, pNormalized, pStride, pOffset);
@@ -79,7 +81,7 @@ public static void glVertexAttribPointerFix(final int pIndex, final int pSize, f
}
public static void glDrawElementsFix(final int pMode, final int pCount, final int pType, final int pOffset) {
- if(GLES20Fix.WORKAROUND_MISSING_GLES20_METHODS) {
+ if (GLES20Fix.WORKAROUND_MISSING_GLES20_METHODS) {
GLES20Fix.glDrawElements(pMode, pCount, pType, pOffset);
} else {
GLES20.glDrawElements(pMode, pCount, pType, pOffset);
diff --git a/src/org/andengine/opengl/exception/GLException.java b/src/org/andengine/opengl/exception/GLException.java
index 7beaddd07..9d38587a9 100644
--- a/src/org/andengine/opengl/exception/GLException.java
+++ b/src/org/andengine/opengl/exception/GLException.java
@@ -3,7 +3,7 @@
import android.opengl.GLU;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 10:44:27 - 13.02.2012
@@ -53,7 +53,7 @@ public int getError() {
private static String getErrorString(final int pError) {
String errorString = GLU.gluErrorString(pError);
- if(errorString == null) {
+ if (errorString == null) {
errorString = "Unknown error '0x" + Integer.toHexString(pError) + "'.";
}
return errorString;
diff --git a/src/org/andengine/opengl/exception/GLFrameBufferException.java b/src/org/andengine/opengl/exception/GLFrameBufferException.java
index fc050dac6..71133b4ef 100644
--- a/src/org/andengine/opengl/exception/GLFrameBufferException.java
+++ b/src/org/andengine/opengl/exception/GLFrameBufferException.java
@@ -2,7 +2,7 @@
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 10:47:22 - 13.02.2012
diff --git a/src/org/andengine/opengl/exception/RenderTextureInitializationException.java b/src/org/andengine/opengl/exception/RenderTextureInitializationException.java
index d3339d9cf..a6bbd8f05 100644
--- a/src/org/andengine/opengl/exception/RenderTextureInitializationException.java
+++ b/src/org/andengine/opengl/exception/RenderTextureInitializationException.java
@@ -3,7 +3,7 @@
import org.andengine.util.exception.AndEngineRuntimeException;
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 11:59:45 AM - Feb 13, 2012
diff --git a/src/org/andengine/opengl/font/BitmapFont.java b/src/org/andengine/opengl/font/BitmapFont.java
index 027804b7f..4c56735d9 100644
--- a/src/org/andengine/opengl/font/BitmapFont.java
+++ b/src/org/andengine/opengl/font/BitmapFont.java
@@ -33,7 +33,7 @@
* http://www.angelcode.com/products/bmfont/ (Free, Windows only)
*
*
- * (c) Zynga 2011
+ * (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 17:54:59 - 01.11.2011
@@ -200,7 +200,7 @@ public BitmapFont(final TextureManager pTextureManager, final AssetManager pAsse
final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in), StreamUtils.IO_BUFFER_SIZE);
final String assetBasePath;
- if(pAssetPath.indexOf('/') == -1) {
+ if (pAssetPath.indexOf('/') == -1) {
assetBasePath = "";
} else {
assetBasePath = pAssetPath.substring(0, pAssetPath.lastIndexOf('/') + 1);
@@ -214,12 +214,12 @@ public BitmapFont(final TextureManager pTextureManager, final AssetManager pAsse
/* Common. */
{
final String common = bufferedReader.readLine();
- if((common != null) && common.startsWith(BitmapFont.TAG_COMMON)) {
+ if ((common != null) && common.startsWith(BitmapFont.TAG_COMMON)) {
final String[] commonAttributes = TextUtils.SPLITPATTERN_SPACE.split(common, BitmapFont.TAG_COMMON_ATTRIBUTECOUNT + 1);
- if((commonAttributes.length - 1) != BitmapFont.TAG_COMMON_ATTRIBUTECOUNT) {
+ if ((commonAttributes.length - 1) != BitmapFont.TAG_COMMON_ATTRIBUTECOUNT) {
throw new FontException("Expected: '" + BitmapFont.TAG_COMMON_ATTRIBUTECOUNT + "' " + BitmapFont.TAG_COMMON + " attributes, found: '" + (commonAttributes.length - 1) + "'.");
}
- if(!commonAttributes[0].equals(BitmapFont.TAG_COMMON)) {
+ if (!commonAttributes[0].equals(BitmapFont.TAG_COMMON)) {
throw new FontException("Expected: '" + BitmapFont.TAG_COMMON + "' attributes.");
}
this.mLineHeight = BitmapFont.getIntAttribute(commonAttributes, BitmapFont.TAG_COMMON_ATTRIBUTE_LINEHEIGHT_INDEX, BitmapFont.TAG_COMMON_ATTRIBUTE_LINEHEIGHT);
@@ -229,12 +229,12 @@ public BitmapFont(final TextureManager pTextureManager, final AssetManager pAsse
this.mBitmapFontPageCount = BitmapFont.getIntAttribute(commonAttributes, BitmapFont.TAG_COMMON_ATTRIBUTE_PAGES_INDEX, BitmapFont.TAG_COMMON_ATTRIBUTE_PAGES);
this.mPacked = BitmapFont.getBooleanAttribute(commonAttributes, BitmapFont.TAG_COMMON_ATTRIBUTE_PACKED_INDEX, BitmapFont.TAG_COMMON_ATTRIBUTE_PACKED);
- if(this.mBitmapFontPageCount != 1) {
+ if (this.mBitmapFontPageCount != 1) {
throw new FontException("Only a single page is supported.");
}
this.mBitmapFontPages = new BitmapFontPage[this.mBitmapFontPageCount];
- if(this.mPacked) {
+ if (this.mPacked) {
throw new FontException("Packed is not supported.");
}
} else {
@@ -243,19 +243,19 @@ public BitmapFont(final TextureManager pTextureManager, final AssetManager pAsse
}
/* Pages. */
- for(int i = 0; i < this.mBitmapFontPageCount; i++) {
+ for (int i = 0; i < this.mBitmapFontPageCount; i++) {
this.mBitmapFontPages[i] = new BitmapFontPage(pAssetManager, assetBasePath, bufferedReader.readLine());
}
/* Chars. */
{
final String chars = bufferedReader.readLine();
- if((chars != null) && chars.startsWith(BitmapFont.TAG_CHARS)) {
+ if ((chars != null) && chars.startsWith(BitmapFont.TAG_CHARS)) {
final String[] charsAttributes = TextUtils.SPLITPATTERN_SPACE.split(chars, BitmapFont.TAG_CHARS_ATTRIBUTECOUNT + 1);
- if((charsAttributes.length - 1) != BitmapFont.TAG_CHARS_ATTRIBUTECOUNT) {
+ if ((charsAttributes.length - 1) != BitmapFont.TAG_CHARS_ATTRIBUTECOUNT) {
throw new FontException("Expected: '" + BitmapFont.TAG_CHARS_ATTRIBUTECOUNT + "' " + BitmapFont.TAG_CHARS + " attributes, found: '" + (charsAttributes.length - 1) + "'.");
}
- if(!charsAttributes[0].equals(BitmapFont.TAG_CHARS)) {
+ if (!charsAttributes[0].equals(BitmapFont.TAG_CHARS)) {
throw new FontException("Expected: '" + BitmapFont.TAG_CHARS + "' attributes.");
}
@@ -270,12 +270,12 @@ public BitmapFont(final TextureManager pTextureManager, final AssetManager pAsse
/* Kernings. */
{
final String kernings = bufferedReader.readLine();
- if((kernings != null) && kernings.startsWith(BitmapFont.TAG_KERNINGS)) {
+ if ((kernings != null) && kernings.startsWith(BitmapFont.TAG_KERNINGS)) {
final String[] kerningsAttributes = TextUtils.SPLITPATTERN_SPACE.split(kernings, BitmapFont.TAG_KERNINGS_ATTRIBUTECOUNT + 1);
- if((kerningsAttributes.length - 1) != BitmapFont.TAG_KERNINGS_ATTRIBUTECOUNT) {
+ if ((kerningsAttributes.length - 1) != BitmapFont.TAG_KERNINGS_ATTRIBUTECOUNT) {
throw new FontException("Expected: '" + BitmapFont.TAG_KERNINGS_ATTRIBUTECOUNT + "' " + BitmapFont.TAG_KERNINGS + " attributes, found: '" + (kerningsAttributes.length - 1) + "'.");
}
- if(!kerningsAttributes[0].equals(BitmapFont.TAG_KERNINGS)) {
+ if (!kerningsAttributes[0].equals(BitmapFont.TAG_KERNINGS)) {
throw new FontException("Expected: '" + BitmapFont.TAG_KERNINGS + "' attributes.");
}
@@ -346,6 +346,11 @@ public void unload() {
this.unloadTextures();
}
+ @Override
+ public float getAscent() {
+ return 0;
+ }
+
@Override
public float getLineHeight() {
return this.mLineHeight;
@@ -354,7 +359,7 @@ public float getLineHeight() {
@Override
public Letter getLetter(final char pChar) throws LetterNotFoundException {
final Letter letter = this.mCharacterToLetterMap.get(pChar);
- if(letter == null) {
+ if (letter == null) {
throw new LetterNotFoundException("Letter '" + pChar + "' not found.");
}
return letter;
@@ -367,7 +372,7 @@ public Letter getLetter(final char pChar) throws LetterNotFoundException {
public void loadTextures() {
final BitmapFontPage[] bitmapFontPages = this.mBitmapFontPages;
final int bitmapFontPageCount = bitmapFontPages.length;
- for(int i = 0; i < bitmapFontPageCount; i++) {
+ for (int i = 0; i < bitmapFontPageCount; i++) {
bitmapFontPages[i].getTexture().load();
}
}
@@ -375,19 +380,19 @@ public void loadTextures() {
public void unloadTextures() {
final BitmapFontPage[] bitmapFontPages = this.mBitmapFontPages;
final int bitmapFontPageCount = bitmapFontPages.length;
- for(int i = 0; i < bitmapFontPageCount; i++) {
+ for (int i = 0; i < bitmapFontPageCount; i++) {
bitmapFontPages[i].getTexture().unload();
}
}
private void parseCharacters(final int pCharacterCount, final BufferedReader pBufferedReader) throws IOException {
- for(int i = pCharacterCount - 1; i >= 0; i--) {
+ for (int i = pCharacterCount - 1; i >= 0; i--) {
final String character = pBufferedReader.readLine();
final String[] charAttributes = TextUtils.SPLITPATTERN_SPACES.split(character, BitmapFont.TAG_CHAR_ATTRIBUTECOUNT + 1);
- if((charAttributes.length - 1) != BitmapFont.TAG_CHAR_ATTRIBUTECOUNT) {
+ if ((charAttributes.length - 1) != BitmapFont.TAG_CHAR_ATTRIBUTECOUNT) {
throw new FontException("Expected: '" + BitmapFont.TAG_CHAR_ATTRIBUTECOUNT + "' " + BitmapFont.TAG_CHAR + " attributes, found: '" + (charAttributes.length - 1) + "'.");
}
- if(!charAttributes[0].equals(BitmapFont.TAG_CHAR)) {
+ if (!charAttributes[0].equals(BitmapFont.TAG_CHAR)) {
throw new FontException("Expected: '" + BitmapFont.TAG_CHAR + "' attributes.");
}
@@ -411,18 +416,18 @@ private void parseCharacters(final int pCharacterCount, final BufferedReader pBu
final float u2 = (x + width) / textureWidth;
final float v2 = (y + height) / textureHeight;
- this.mCharacterToLetterMap.put(id, new Letter((char)id, x, y, width, height, xOffset, yOffset, xAdvance, u, v, u2, v2));
+ this.mCharacterToLetterMap.put(id, new Letter((char) id, x, y, width, height, xOffset, yOffset, xAdvance, u, v, u2, v2));
}
}
private void parseKernings(final int pKerningsCount, final BufferedReader pBufferedReader) throws IOException {
- for(int i = pKerningsCount - 1; i >= 0; i--) {
+ for (int i = pKerningsCount - 1; i >= 0; i--) {
final String kerning = pBufferedReader.readLine();
final String[] charAttributes = TextUtils.SPLITPATTERN_SPACES.split(kerning, BitmapFont.TAG_KERNING_ATTRIBUTECOUNT + 1);
- if((charAttributes.length - 1) != BitmapFont.TAG_KERNING_ATTRIBUTECOUNT) {
+ if ((charAttributes.length - 1) != BitmapFont.TAG_KERNING_ATTRIBUTECOUNT) {
throw new FontException("Expected: '" + BitmapFont.TAG_KERNING_ATTRIBUTECOUNT + "' " + BitmapFont.TAG_KERNING + " attributes, found: '" + (charAttributes.length - 1) + "'.");
}
- if(!charAttributes[0].equals(BitmapFont.TAG_KERNING)) {
+ if (!charAttributes[0].equals(BitmapFont.TAG_KERNING)) {
throw new FontException("Expected: '" + BitmapFont.TAG_KERNING + "' attributes.");
}
@@ -438,13 +443,13 @@ private static boolean getBooleanAttribute(final String[] pData, final int pPosi
final String data = pData[pPosition];
final int attributeLength = pAttribute.length();
- if(!data.startsWith(pAttribute) || (data.charAt(attributeLength) != '=')) {
+ if (!data.startsWith(pAttribute) || (data.charAt(attributeLength) != '=')) {
throw new FontException("Expected '" + pAttribute + "' at position '" + pPosition + "', but found: '" + data + "'.");
}
return Integer.parseInt(data.substring(attributeLength + 1)) != 0;
}
-
+
private static char getCharAttribute(final String[] pData, final int pPosition, final String pAttribute) {
return (char) BitmapFont.getIntAttribute(pData, pPosition, pAttribute);
}
@@ -453,7 +458,7 @@ private static int getIntAttribute(final String[] pData, final int pPosition, fi
final String data = pData[pPosition];
final int attributeLength = pAttribute.length();
- if(!data.startsWith(pAttribute) || (data.charAt(attributeLength) != '=')) {
+ if (!data.startsWith(pAttribute) || (data.charAt(attributeLength) != '=')) {
throw new FontException("Expected '" + pAttribute + "' at position '" + pPosition + "', but found: '" + data + "'.");
}
@@ -464,7 +469,7 @@ private static String getStringAttribute(final String[] pData, final int pPositi
final String data = pData[pPosition];
final int attributeLength = pAttribute.length();
- if(!data.startsWith(pAttribute) || (data.charAt(attributeLength) != '=')) {
+ if (!data.startsWith(pAttribute) || (data.charAt(attributeLength) != '=')) {
throw new FontException("Expected '" + pAttribute + "' at position '" + pPosition + "', but found: '" + data + "'.");
}
@@ -475,7 +480,7 @@ private static String getAttribute(final String[] pData, final int pPosition, fi
final String data = pData[pPosition];
final int attributeLength = pAttribute.length();
- if(!data.startsWith(pAttribute)) {
+ if (!data.startsWith(pAttribute)) {
throw new FontException("Expected '" + pAttribute + "' at position '" + pPosition + "', but found: '" + data + "'.");
}
@@ -574,16 +579,16 @@ public class BitmapFontInfo {
// ===========================================================
public BitmapFontInfo(final String pData) throws FontException {
- if(pData == null) {
+ if (pData == null) {
throw new FontException("pData must not be null.");
}
final String[] infoAttributes = TextUtils.SPLITPATTERN_SPACE.split(pData, BitmapFont.TAG_INFO_ATTRIBUTECOUNT + 1);
- if((infoAttributes.length - 1) != BitmapFont.TAG_INFO_ATTRIBUTECOUNT) {
+ if ((infoAttributes.length - 1) != BitmapFont.TAG_INFO_ATTRIBUTECOUNT) {
throw new FontException("Expected: '" + BitmapFont.TAG_INFO_ATTRIBUTECOUNT + "' " + BitmapFont.TAG_INFO + " attributes, found: '" + (infoAttributes.length - 1) + "'.");
}
- if(!infoAttributes[0].equals(BitmapFont.TAG_INFO)) {
+ if (!infoAttributes[0].equals(BitmapFont.TAG_INFO)) {
throw new FontException("Expected: '" + BitmapFont.TAG_INFO + "' attributes.");
}
@@ -706,10 +711,10 @@ public class BitmapFontPage {
public BitmapFontPage(final AssetManager pAssetManager, final String pAssetBasePath, final String pData) throws IOException {
final String[] pageAttributes = TextUtils.SPLITPATTERN_SPACE.split(pData, BitmapFont.TAG_PAGE_ATTRIBUTECOUNT + 1);
- if((pageAttributes.length - 1) != BitmapFont.TAG_PAGE_ATTRIBUTECOUNT) {
+ if ((pageAttributes.length - 1) != BitmapFont.TAG_PAGE_ATTRIBUTECOUNT) {
throw new FontException("Expected: '" + BitmapFont.TAG_PAGE_ATTRIBUTECOUNT + "' " + BitmapFont.TAG_PAGE + " attributes, found: '" + (pageAttributes.length - 1) + "'.");
}
- if(!pageAttributes[0].equals(BitmapFont.TAG_PAGE)) {
+ if (!pageAttributes[0].equals(BitmapFont.TAG_PAGE)) {
throw new FontException("Expected: '" + BitmapFont.TAG_PAGE + "' attributes.");
}
diff --git a/src/org/andengine/opengl/font/Font.java b/src/org/andengine/opengl/font/Font.java
index 14d788fc9..d9e29d962 100644
--- a/src/org/andengine/opengl/font/Font.java
+++ b/src/org/andengine/opengl/font/Font.java
@@ -6,8 +6,8 @@
import org.andengine.opengl.texture.ITexture;
import org.andengine.opengl.texture.PixelFormat;
import org.andengine.opengl.util.GLState;
+import org.andengine.util.adt.color.Color;
import org.andengine.util.adt.map.SparseArrayUtils;
-import org.andengine.util.color.Color;
import org.andengine.util.math.MathUtils;
import android.graphics.Bitmap;
@@ -25,7 +25,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 10:39:33 - 03.04.2010
*/
@@ -142,7 +142,7 @@ public float getLineHeight() {
@Override
public synchronized Letter getLetter(final char pCharacter) throws FontException {
Letter letter = this.mManagedCharacterToLetterMap.get(pCharacter);
- if(letter == null) {
+ if (letter == null) {
letter = this.createLetter(pCharacter);
this.mLettersPendingToBeDrawnToTexture.add(letter);
@@ -160,7 +160,7 @@ public synchronized void invalidateLetters() {
final SparseArray managedCharacterToLetterMap = this.mManagedCharacterToLetterMap;
/* Make all letters redraw to the texture. */
- for(int i = managedCharacterToLetterMap.size() - 1; i >= 0; i--) {
+ for (int i = managedCharacterToLetterMap.size() - 1; i >= 0; i--) {
lettersPendingToBeDrawnToTexture.add(managedCharacterToLetterMap.valueAt(i));
}
}
@@ -185,7 +185,7 @@ protected Bitmap getLetterBitmap(final Letter pLetter) throws FontException {
/* Actually draw the character. */
final float drawLetterLeft = -pLetter.mOffsetX;
- final float drawLetterTop = -(pLetter.mOffsetY + this.getAscent());
+ final float drawLetterTop = -pLetter.mOffsetY;
this.drawLetter(characterAsString, drawLetterLeft, drawLetterTop);
@@ -197,7 +197,7 @@ protected void drawLetter(final String pCharacterAsString, final float pLeft, fi
}
public void prepareLetters(final char... pCharacters) throws FontException {
- for(final char character : pCharacters) {
+ for (final char character : pCharacters) {
this.getLetter(character);
}
}
@@ -219,16 +219,16 @@ private Letter createLetter(final char pCharacter) throws FontException {
final float advance = this.getLetterAdvance(characterAsString);
final boolean whitespace = Character.isWhitespace(pCharacter) || (letterWidth == 0) || (letterHeight == 0);
- if(whitespace) {
+ if (whitespace) {
letter = new Letter(pCharacter, advance);
} else {
- if((this.mCurrentTextureX + Font.LETTER_TEXTURE_PADDING + letterWidth) >= textureWidth) {
+ if ((this.mCurrentTextureX + Font.LETTER_TEXTURE_PADDING + letterWidth) >= textureWidth) {
this.mCurrentTextureX = 0;
this.mCurrentTextureY += this.mCurrentTextureYHeightMax + (2 * Font.LETTER_TEXTURE_PADDING);
this.mCurrentTextureYHeightMax = 0;
}
- if((this.mCurrentTextureY + letterHeight) >= textureHeight) {
+ if ((this.mCurrentTextureY + letterHeight) >= textureHeight) {
throw new FontException("Not enough space for " + Letter.class.getSimpleName() + ": '" + pCharacter + "' on the " + this.mTexture.getClass().getSimpleName() + ". Existing Letters: " + SparseArrayUtils.toString(this.mManagedCharacterToLetterMap));
}
@@ -241,7 +241,7 @@ private Letter createLetter(final char pCharacter) throws FontException {
final float u2 = (this.mCurrentTextureX + letterWidth) / textureWidth;
final float v2 = (this.mCurrentTextureY + letterHeight) / textureHeight;
- letter = new Letter(pCharacter, this.mCurrentTextureX - Font.LETTER_TEXTURE_PADDING, this.mCurrentTextureY - Font.LETTER_TEXTURE_PADDING, letterWidth, letterHeight, letterLeft, letterTop - this.getAscent(), advance, u, v, u2, v2);
+ letter = new Letter(pCharacter, this.mCurrentTextureX - Font.LETTER_TEXTURE_PADDING, this.mCurrentTextureY - Font.LETTER_TEXTURE_PADDING, letterWidth, letterHeight, letterLeft, letterTop, advance, u, v, u2, v2);
this.mCurrentTextureX += letterWidth + Font.LETTER_TEXTURE_PADDING;
}
@@ -253,31 +253,31 @@ protected void updateTextBounds(final String pCharacterAsString) {
}
public synchronized void update(final GLState pGLState) {
- if(this.mTexture.isLoadedToHardware()) {
+ if (this.mTexture.isLoadedToHardware()) {
final ArrayList lettersPendingToBeDrawnToTexture = this.mLettersPendingToBeDrawnToTexture;
- if(lettersPendingToBeDrawnToTexture.size() > 0) {
+ if (lettersPendingToBeDrawnToTexture.size() > 0) {
this.mTexture.bind(pGLState);
final PixelFormat pixelFormat = this.mTexture.getPixelFormat();
final boolean preMultipyAlpha = this.mTexture.getTextureOptions().mPreMultiplyAlpha;
- for(int i = lettersPendingToBeDrawnToTexture.size() - 1; i >= 0; i--) {
+ for (int i = lettersPendingToBeDrawnToTexture.size() - 1; i >= 0; i--) {
final Letter letter = lettersPendingToBeDrawnToTexture.get(i);
- if(!letter.isWhitespace()) {
+ if (!letter.isWhitespace()) {
final Bitmap bitmap = this.getLetterBitmap(letter);
final boolean useDefaultAlignment = MathUtils.isPowerOfTwo(bitmap.getWidth()) && MathUtils.isPowerOfTwo(bitmap.getHeight()) && (pixelFormat == PixelFormat.RGBA_8888);
- if(!useDefaultAlignment) {
+ if (!useDefaultAlignment) {
/* Adjust unpack alignment. */
GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
}
- if(preMultipyAlpha) {
+ if (preMultipyAlpha) {
GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, letter.mTextureX, letter.mTextureY, bitmap);
} else {
pGLState.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, letter.mTextureX, letter.mTextureY, bitmap, pixelFormat);
}
- if(!useDefaultAlignment) {
+ if (!useDefaultAlignment) {
/* Restore default unpack alignment. */
GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, GLState.GL_UNPACK_ALIGNMENT_DEFAULT);
}
diff --git a/src/org/andengine/opengl/font/FontFactory.java b/src/org/andengine/opengl/font/FontFactory.java
index 9ece71bac..2f3e9bafd 100644
--- a/src/org/andengine/opengl/font/FontFactory.java
+++ b/src/org/andengine/opengl/font/FontFactory.java
@@ -1,11 +1,11 @@
package org.andengine.opengl.font;
+import org.andengine.opengl.texture.EmptyTexture;
import org.andengine.opengl.texture.ITexture;
+import org.andengine.opengl.texture.PixelFormat;
import org.andengine.opengl.texture.TextureManager;
import org.andengine.opengl.texture.TextureOptions;
-import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
-import org.andengine.opengl.texture.bitmap.BitmapTextureFormat;
-import org.andengine.util.color.Color;
+import org.andengine.util.adt.color.Color;
import android.content.res.AssetManager;
import android.graphics.Typeface;
@@ -13,11 +13,11 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 17:17:28 - 16.06.2010
*/
-public class FontFactory {
+public final class FontFactory {
// ===========================================================
// Constants
// ===========================================================
@@ -35,6 +35,10 @@ public class FontFactory {
// Constructors
// ===========================================================
+ private FontFactory() {
+
+ }
+
// ===========================================================
// Getter & Setter
// ===========================================================
@@ -43,13 +47,17 @@ public class FontFactory {
* @param pAssetBasePath must end with '/' or have .length() == 0.
*/
public static void setAssetBasePath(final String pAssetBasePath) {
- if(pAssetBasePath.endsWith("/") || pAssetBasePath.length() == 0) {
+ if (pAssetBasePath.endsWith("/") || pAssetBasePath.length() == 0) {
FontFactory.sAssetBasePath = pAssetBasePath;
} else {
- throw new IllegalStateException("pAssetBasePath must end with '/' or be lenght zero.");
+ throw new IllegalStateException("pAssetBasePath must end with '/' or be length zero.");
}
}
+ public static String getAssetBasePath() {
+ return FontFactory.sAssetBasePath;
+ }
+
public static void onCreate() {
FontFactory.setAssetBasePath("");
}
@@ -115,23 +123,23 @@ public static Font create(final FontManager pFontManager, final TextureManager p
}
public static Font create(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final TextureOptions pTextureOptions, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final int pColor) {
- return FontFactory.create(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, BitmapTextureFormat.RGBA_8888, pTextureOptions, pTypeface, pSize, pAntiAlias, pColor);
+ return FontFactory.create(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, PixelFormat.RGBA_8888, pTextureOptions, pTypeface, pSize, pAntiAlias, pColor);
}
- public static Font create(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final BitmapTextureFormat pBitmapTextureFormat, final TextureOptions pTextureOptions, final Typeface pTypeface, final float pSize) {
- return FontFactory.create(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, pBitmapTextureFormat, pTextureOptions, pTypeface, pSize, FontFactory.ANTIALIAS_DEFAULT, FontFactory.COLOR_DEFAULT);
+ public static Font create(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final PixelFormat pPixelFormat, final TextureOptions pTextureOptions, final Typeface pTypeface, final float pSize) {
+ return FontFactory.create(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, pPixelFormat, pTextureOptions, pTypeface, pSize, FontFactory.ANTIALIAS_DEFAULT, FontFactory.COLOR_DEFAULT);
}
- public static Font create(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final BitmapTextureFormat pBitmapTextureFormat, final TextureOptions pTextureOptions, final Typeface pTypeface, final float pSize, final boolean pAntiAlias) {
- return FontFactory.create(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, pBitmapTextureFormat, pTextureOptions, pTypeface, pSize, pAntiAlias, FontFactory.COLOR_DEFAULT);
+ public static Font create(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final PixelFormat pPixelFormat, final TextureOptions pTextureOptions, final Typeface pTypeface, final float pSize, final boolean pAntiAlias) {
+ return FontFactory.create(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, pPixelFormat, pTextureOptions, pTypeface, pSize, pAntiAlias, FontFactory.COLOR_DEFAULT);
}
- public static Font create(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final BitmapTextureFormat pBitmapTextureFormat, final TextureOptions pTextureOptions, final Typeface pTypeface, final float pSize, final int pColor) {
- return FontFactory.create(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, pBitmapTextureFormat, pTextureOptions, pTypeface, pSize, FontFactory.ANTIALIAS_DEFAULT, pColor);
+ public static Font create(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final PixelFormat pPixelFormat, final TextureOptions pTextureOptions, final Typeface pTypeface, final float pSize, final int pColor) {
+ return FontFactory.create(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, pPixelFormat, pTextureOptions, pTypeface, pSize, FontFactory.ANTIALIAS_DEFAULT, pColor);
}
- public static Font create(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final BitmapTextureFormat pBitmapTextureFormat, final TextureOptions pTextureOptions, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final int pColor) {
- return FontFactory.create(pFontManager, new BitmapTextureAtlas(pTextureManager, pTextureWidth, pTextureHeight, pBitmapTextureFormat, pTextureOptions), pTypeface, pSize, pAntiAlias, pColor);
+ public static Font create(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final PixelFormat pPixelFormat, final TextureOptions pTextureOptions, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final int pColor) {
+ return FontFactory.create(pFontManager, new EmptyTexture(pTextureManager, pTextureWidth, pTextureHeight, pPixelFormat, pTextureOptions), pTypeface, pSize, pAntiAlias, pColor);
}
public static Font create(final FontManager pFontManager, final ITexture pTexture, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final int pColor) {
@@ -148,28 +156,105 @@ public static Font createFromAsset(final FontManager pFontManager, final Texture
}
public static Font createFromAsset(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final TextureOptions pTextureOptions, final AssetManager pAssetManager, final String pAssetPath, final float pSize, final boolean pAntiAlias, final int pColor) {
- return FontFactory.createFromAsset(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, BitmapTextureFormat.RGBA_8888, pTextureOptions, pAssetManager, pAssetPath, pSize, pAntiAlias, pColor);
+ return FontFactory.createFromAsset(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, PixelFormat.RGBA_8888, pTextureOptions, pAssetManager, pAssetPath, pSize, pAntiAlias, pColor);
+ }
+
+ public static Font createFromAsset(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final PixelFormat pPixelFormat, final TextureOptions pTextureOptions, final AssetManager pAssetManager, final String pAssetPath, final float pSize, final boolean pAntiAlias, final int pColor) {
+ return new Font(pFontManager, new EmptyTexture(pTextureManager, pTextureWidth, pTextureHeight, pPixelFormat, pTextureOptions), Typeface.createFromAsset(pAssetManager, FontFactory.sAssetBasePath + pAssetPath), pSize, pAntiAlias, pColor);
+ }
+
+
+ public static StrokeFont createStroke(final FontManager pFontManager, final ITexture pTexture, final float pSize, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStroke(pFontManager, pTexture, pSize, FontFactory.ANTIALIAS_DEFAULT, FontFactory.COLOR_DEFAULT, pStrokeWidth, pStrokeColor);
+ }
+
+ public static StrokeFont createStroke(final FontManager pFontManager, final ITexture pTexture, final float pSize, final boolean pAntiAlias, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStroke(pFontManager, pTexture, pSize, pAntiAlias, FontFactory.COLOR_DEFAULT, pStrokeWidth, pStrokeColor);
+ }
+
+ public static StrokeFont createStroke(final FontManager pFontManager, final ITexture pTexture, final float pSize, final int pColor, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStroke(pFontManager, pTexture, pSize, FontFactory.ANTIALIAS_DEFAULT, pColor, pStrokeWidth, pStrokeColor);
+ }
+
+ public static StrokeFont createStroke(final FontManager pFontManager, final ITexture pTexture, final float pSize, final boolean pAntiAlias, final int pColor, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStroke(pFontManager, pTexture, Typeface.create(Typeface.DEFAULT, Typeface.NORMAL), pSize, pAntiAlias, pColor, pStrokeWidth, pStrokeColor);
+ }
+
+ public static StrokeFont createStroke(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final float pSize, final boolean pAntiAlias, final int pColor, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStroke(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, TextureOptions.DEFAULT, pSize, pAntiAlias, pColor, pStrokeWidth, pStrokeColor);
+ }
+
+ public static StrokeFont createStroke(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final TextureOptions pTextureOptions, final float pSize, final boolean pAntiAlias, final int pColor, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStroke(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, pTextureOptions, Typeface.create(Typeface.DEFAULT, Typeface.NORMAL), pSize, pAntiAlias, pColor, pStrokeWidth, pStrokeColor);
+ }
+
+ public static StrokeFont createStroke(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final Typeface pTypeface, final float pSize, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStroke(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, TextureOptions.DEFAULT, pTypeface, pSize, FontFactory.ANTIALIAS_DEFAULT, FontFactory.COLOR_DEFAULT, pStrokeWidth, pStrokeColor);
+ }
+
+ public static StrokeFont createStroke(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStroke(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, TextureOptions.DEFAULT, pTypeface, pSize, pAntiAlias, FontFactory.COLOR_DEFAULT, pStrokeWidth, pStrokeColor);
+ }
+
+ public static StrokeFont createStroke(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final Typeface pTypeface, final float pSize, final int pColor, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStroke(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, TextureOptions.DEFAULT, pTypeface, pSize, FontFactory.ANTIALIAS_DEFAULT, pColor, pStrokeWidth, pStrokeColor);
+ }
+
+ public static StrokeFont createStroke(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final int pColor, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStroke(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, TextureOptions.DEFAULT, pTypeface, pSize, pAntiAlias, pColor, pStrokeWidth, pStrokeColor);
+ }
+
+ public static StrokeFont createStroke(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final TextureOptions pTextureOptions, final Typeface pTypeface, final float pSize, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStroke(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, pTextureOptions, pTypeface, pSize, FontFactory.ANTIALIAS_DEFAULT, FontFactory.COLOR_DEFAULT, pStrokeWidth, pStrokeColor);
+ }
+
+ public static StrokeFont createStroke(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final TextureOptions pTextureOptions, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStroke(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, pTextureOptions, pTypeface, pSize, pAntiAlias, FontFactory.COLOR_DEFAULT, pStrokeWidth, pStrokeColor);
}
- public static Font createFromAsset(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final BitmapTextureFormat pBitmapTextureFormat, final TextureOptions pTextureOptions, final AssetManager pAssetManager, final String pAssetPath, final float pSize, final boolean pAntiAlias, final int pColor) {
- return new Font(pFontManager, new BitmapTextureAtlas(pTextureManager, pTextureWidth, pTextureHeight, pBitmapTextureFormat, pTextureOptions), Typeface.createFromAsset(pAssetManager, FontFactory.sAssetBasePath + pAssetPath), pSize, pAntiAlias, pColor);
+ public static StrokeFont createStroke(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final TextureOptions pTextureOptions, final Typeface pTypeface, final float pSize, final int pColor, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStroke(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, pTextureOptions, pTypeface, pSize, FontFactory.ANTIALIAS_DEFAULT, pColor, pStrokeWidth, pStrokeColor);
}
+ public static StrokeFont createStroke(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final TextureOptions pTextureOptions, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final int pColor, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStroke(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, PixelFormat.RGBA_8888, pTextureOptions, pTypeface, pSize, pAntiAlias, pColor, pStrokeWidth, pStrokeColor);
+ }
+
+ public static StrokeFont createStroke(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final PixelFormat pPixelFormat, final TextureOptions pTextureOptions, final Typeface pTypeface, final float pSize, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStroke(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, pPixelFormat, pTextureOptions, pTypeface, pSize, FontFactory.ANTIALIAS_DEFAULT, FontFactory.COLOR_DEFAULT, pStrokeWidth, pStrokeColor);
+ }
+
+ public static StrokeFont createStroke(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final PixelFormat pPixelFormat, final TextureOptions pTextureOptions, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStroke(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, pPixelFormat, pTextureOptions, pTypeface, pSize, pAntiAlias, FontFactory.COLOR_DEFAULT, pStrokeWidth, pStrokeColor);
+ }
+
+ public static StrokeFont createStroke(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final PixelFormat pPixelFormat, final TextureOptions pTextureOptions, final Typeface pTypeface, final float pSize, final int pColor, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStroke(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, pPixelFormat, pTextureOptions, pTypeface, pSize, FontFactory.ANTIALIAS_DEFAULT, pColor, pStrokeWidth, pStrokeColor);
+ }
+
+ public static StrokeFont createStroke(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final PixelFormat pPixelFormat, final TextureOptions pTextureOptions, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final int pColor, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStroke(pFontManager, new EmptyTexture(pTextureManager, pTextureWidth, pTextureHeight, pPixelFormat, pTextureOptions), pTypeface, pSize, pAntiAlias, pColor, pStrokeWidth, pStrokeColor);
+ }
public static StrokeFont createStroke(final FontManager pFontManager, final ITexture pTexture, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final int pColor, final float pStrokeWidth, final int pStrokeColor) {
return new StrokeFont(pFontManager, pTexture, pTypeface, pSize, pAntiAlias, pColor, pStrokeWidth, pStrokeColor);
}
- public static StrokeFont createStroke(final FontManager pFontManager, final ITexture pTexture, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final int pColor, final float pStrokeWidth, final int pStrokeColor, final boolean pStrokeOnly) {
- return new StrokeFont(pFontManager, pTexture, pTypeface, pSize, pAntiAlias, pColor, pStrokeWidth, pStrokeColor, pStrokeOnly);
- }
public static StrokeFont createStrokeFromAsset(final FontManager pFontManager, final ITexture pTexture, final AssetManager pAssetManager, final String pAssetPath, final float pSize, final boolean pAntiAlias, final int pColor, final float pStrokeWidth, final int pStrokeColor) {
return new StrokeFont(pFontManager, pTexture, Typeface.createFromAsset(pAssetManager, FontFactory.sAssetBasePath + pAssetPath), pSize, pAntiAlias, pColor, pStrokeWidth, pStrokeColor);
}
- public static StrokeFont createStrokeFromAsset(final FontManager pFontManager, final ITexture pTexture, final AssetManager pAssetManager, final String pAssetPath, final float pSize, final boolean pAntiAlias, final int pColor, final float pStrokeWidth, final int pStrokeColor, final boolean pStrokeOnly) {
- return new StrokeFont(pFontManager, pTexture, Typeface.createFromAsset(pAssetManager, FontFactory.sAssetBasePath + pAssetPath), pSize, pAntiAlias, pColor, pStrokeWidth, pStrokeColor, pStrokeOnly);
+ public static StrokeFont createStrokeFromAsset(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final AssetManager pAssetManager, final String pAssetPath, final float pSize, final boolean pAntiAlias, final int pColor, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStrokeFromAsset(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, TextureOptions.DEFAULT, pAssetManager, pAssetPath, pSize, pAntiAlias, pColor, pStrokeWidth, pStrokeColor);
+ }
+
+ public static StrokeFont createStrokeFromAsset(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final TextureOptions pTextureOptions, final AssetManager pAssetManager, final String pAssetPath, final float pSize, final boolean pAntiAlias, final int pColor, final float pStrokeWidth, final int pStrokeColor) {
+ return FontFactory.createStrokeFromAsset(pFontManager, pTextureManager, pTextureWidth, pTextureHeight, PixelFormat.RGBA_8888, pTextureOptions, pAssetManager, pAssetPath, pSize, pAntiAlias, pColor, pStrokeWidth, pStrokeColor);
+ }
+
+ public static StrokeFont createStrokeFromAsset(final FontManager pFontManager, final TextureManager pTextureManager, final int pTextureWidth, final int pTextureHeight, final PixelFormat pPixelFormat, final TextureOptions pTextureOptions, final AssetManager pAssetManager, final String pAssetPath, final float pSize, final boolean pAntiAlias, final int pColor, final float pStrokeWidth, final int pStrokeColor) {
+ return new StrokeFont(pFontManager, new EmptyTexture(pTextureManager, pTextureWidth, pTextureHeight, pPixelFormat, pTextureOptions), Typeface.createFromAsset(pAssetManager, FontFactory.sAssetBasePath + pAssetPath), pSize, pAntiAlias, pColor, pStrokeWidth, pStrokeColor);
}
// ===========================================================
diff --git a/src/org/andengine/opengl/font/FontLibrary.java b/src/org/andengine/opengl/font/FontLibrary.java
index df09435b4..c107c7b53 100644
--- a/src/org/andengine/opengl/font/FontLibrary.java
+++ b/src/org/andengine/opengl/font/FontLibrary.java
@@ -5,9 +5,9 @@
import android.util.SparseArray;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 11:52:26 - 20.08.2010
*/
@@ -46,9 +46,9 @@ public FontLibrary(final int pInitialCapacity) {
public void loadFonts(final FontManager pFontManager) {
final SparseArray items = this.mItems;
- for(int i = items.size() - 1; i >= 0; i--) {
+ for (int i = items.size() - 1; i >= 0; i--) {
final Font font = items.valueAt(i);
- if(font != null) {
+ if (font != null) {
pFontManager.loadFont(font);
}
}
diff --git a/src/org/andengine/opengl/font/FontManager.java b/src/org/andengine/opengl/font/FontManager.java
index 9032f45e0..40dce056a 100644
--- a/src/org/andengine/opengl/font/FontManager.java
+++ b/src/org/andengine/opengl/font/FontManager.java
@@ -1,6 +1,7 @@
package org.andengine.opengl.font;
import java.util.ArrayList;
+import java.util.HashMap;
import org.andengine.opengl.util.GLState;
@@ -8,7 +9,7 @@
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
- *
+ *
* @author Nicolas Gramlich
* @since 17:48:46 - 08.03.2010
*/
@@ -22,6 +23,8 @@ public class FontManager {
// ===========================================================
private final ArrayList mFontsManaged = new ArrayList();
+ private final ArrayList mBitmapFontsManaged = new ArrayList();
+ private final HashMap mFontsMapped = new HashMap();
// ===========================================================
// Constructors
@@ -45,44 +48,104 @@ public void onCreate() {
public synchronized void onDestroy() {
final ArrayList managedFonts = this.mFontsManaged;
- for(int i = managedFonts.size() - 1; i >= 0; i--) {
+ for (int i = managedFonts.size() - 1; i >= 0; i--) {
managedFonts.get(i).invalidateLetters();
}
this.mFontsManaged.clear();
+ this.mBitmapFontsManaged.clear();
+ this.mFontsMapped.clear();
+ }
+
+ public synchronized boolean hasMappedFont(final String pID) {
+ if (pID == null) {
+ throw new IllegalArgumentException("pID must not be null!");
+ }
+ return this.mFontsMapped.containsKey(pID);
+ }
+
+ public synchronized IFont getMappedFont(final String pID) {
+ if (pID == null) {
+ throw new IllegalArgumentException("pID must not be null!");
+ }
+ return this.mFontsMapped.get(pID);
+ }
+
+ public synchronized void addMappedFont(final String pID, final IFont pFont) throws IllegalArgumentException {
+ if (pID == null) {
+ throw new IllegalArgumentException("pID must not be null!");
+ } else if (pFont == null) {
+ throw new IllegalArgumentException("pFont must not be null!");
+ } else if (this.mFontsMapped.containsKey(pID)) {
+ throw new IllegalArgumentException("Collision for pID: '" + pID + "'.");
+ }
+ this.mFontsMapped.put(pID, pFont);
+ }
+
+ public synchronized IFont removedMappedFont(final String pID) {
+ if (pID == null) {
+ throw new IllegalArgumentException("pID must not be null!");
+ }
+ return this.mFontsMapped.remove(pID);
}
public synchronized void loadFont(final Font pFont) {
- if(pFont == null) {
+ if (pFont == null) {
throw new IllegalArgumentException("pFont must not be null!");
}
this.mFontsManaged.add(pFont);
}
- public synchronized void loadFonts(final Font ...pFonts) {
- for(int i = 0; i < pFonts.length; i++) {
+ public synchronized void loadFont(final BitmapFont pBitmapFont) {
+ if (pBitmapFont == null) {
+ throw new IllegalArgumentException("pBitmapFont must not be null!");
+ }
+ this.mBitmapFontsManaged.add(pBitmapFont);
+ }
+
+ public synchronized void loadFonts(final Font ... pFonts) {
+ for (int i = 0; i < pFonts.length; i++) {
this.loadFont(pFonts[i]);
}
}
+ public synchronized void loadFonts(final BitmapFont ... pBitmapFonts) {
+ for (int i = 0; i < pBitmapFonts.length; i++) {
+ this.loadFont(pBitmapFonts[i]);
+ }
+ }
+
public synchronized void unloadFont(final Font pFont) {
- if(pFont == null) {
+ if (pFont == null) {
throw new IllegalArgumentException("pFont must not be null!");
}
this.mFontsManaged.remove(pFont);
}
- public synchronized void unloadFonts(final Font ...pFonts) {
- for(int i = 0; i < pFonts.length; i++) {
+ public synchronized void unloadFont(final BitmapFont pBitmapFont) {
+ if (pBitmapFont == null) {
+ throw new IllegalArgumentException("pBitmapFont must not be null!");
+ }
+ this.mBitmapFontsManaged.remove(pBitmapFont);
+ }
+
+ public synchronized void unloadFonts(final Font ... pFonts) {
+ for (int i = 0; i < pFonts.length; i++) {
this.unloadFont(pFonts[i]);
}
}
+ public synchronized void unloadFonts(final BitmapFont ... pBitmapFonts) {
+ for (int i = 0; i < pBitmapFonts.length; i++) {
+ this.unloadFont(pBitmapFonts[i]);
+ }
+ }
+
public synchronized void updateFonts(final GLState pGLState) {
final ArrayList fonts = this.mFontsManaged;
final int fontCount = fonts.size();
- if(fontCount > 0){
- for(int i = fontCount - 1; i >= 0; i--){
+ if (fontCount > 0) {
+ for (int i = fontCount - 1; i >= 0; i--) {
fonts.get(i).update(pGLState);
}
}
@@ -90,7 +153,7 @@ public synchronized void updateFonts(final GLState pGLState) {
public synchronized void onReload() {
final ArrayList managedFonts = this.mFontsManaged;
- for(int i = managedFonts.size() - 1; i >= 0; i--) {
+ for (int i = managedFonts.size() - 1; i >= 0; i--) {
managedFonts.get(i).invalidateLetters();
}
}
diff --git a/src/org/andengine/opengl/font/FontUtils.java b/src/org/andengine/opengl/font/FontUtils.java
index d84153c3a..fe68e12ae 100644
--- a/src/org/andengine/opengl/font/FontUtils.java
+++ b/src/org/andengine/opengl/font/FontUtils.java
@@ -8,7 +8,7 @@
/**
- * (c) Zynga 2012
+ * (c) 2012 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 15:06:32 - 25.01.2012
@@ -83,29 +83,29 @@ public static float measureText(final IFont pFont, final CharSequence pText, fin
public static float measureText(final IFont pFont, final CharSequence pText, final int pStart, final int pEnd, final float[] pWidths) {
final int textLength = pEnd - pStart;
/* Early exits. */
- if(pStart == pEnd) {
+ if (pStart == pEnd) {
return 0;
- } else if(textLength == 1) {
+ } else if (textLength == 1) {
return pFont.getLetter(pText.charAt(pStart)).mWidth;
}
Letter previousLetter = null;
float width = 0;
- for(int pos = pStart, i = 0; pos < pEnd; pos++, i++) {
+ for (int pos = pStart, i = 0; pos < pEnd; pos++, i++) {
final Letter letter = pFont.getLetter(pText.charAt(pos));
- if(previousLetter != null) {
+ if (previousLetter != null) {
width += previousLetter.getKerning(letter.mCharacter);
}
previousLetter = letter;
/* Check if this is the last character. */
- if(pos == (pEnd - 1)) {
+ if (pos == (pEnd - 1)) {
width += letter.mOffsetX + letter.mWidth;
} else {
width += letter.mAdvance;
}
- if(pWidths != null) {
+ if (pWidths != null) {
pWidths[i] = width;
}
}
@@ -132,7 +132,7 @@ public static > L splitLines(final CharSequence pTe
/**
* Does not respect linebreaks!
- *
+ *
* @param pFont
* @param pText
* @param pResult
@@ -141,9 +141,9 @@ public static > L splitLines(final CharSequence pTe
*/
public static > L splitLines(final IFont pFont, final CharSequence pText, final L pResult, final AutoWrap pAutoWrap, final float pAutoWrapWidth) {
/**
- * TODO In order to respect already existing linebreaks, {@link FontUtils#split(CharSequence, List)} could be leveraged and than the following methods could be called for each line.
+ * TODO In order to respect already existing linebreaks, {@link #split(CharSequence, List)} could be leveraged and than the following methods could be called for each line.
*/
- switch(pAutoWrap) {
+ switch (pAutoWrap) {
case LETTERS:
return FontUtils.splitLinesByLetters(pFont, pText, pResult, pAutoWrapWidth);
case WORDS:
@@ -164,10 +164,10 @@ private static > L splitLinesByLetters(final IFont
int lastNonWhitespace = 0;
boolean charsAvailable = false;
- for(int i = 0; i < textLength; i++) {
+ for (int i = 0; i < textLength; i++) {
final char character = pText.charAt(i);
- if(character != ' ') {
- if(charsAvailable) {
+ if (character != ' ') {
+ if (charsAvailable) {
lastNonWhitespace = i + 1;
} else {
charsAvailable = true;
@@ -177,7 +177,7 @@ private static > L splitLinesByLetters(final IFont
}
}
- if(charsAvailable) {
+ if (charsAvailable) {
// /* Just for debugging. */
// final CharSequence line = pText.subSequence(lineStart, lineEnd);
// final float lineWidth = FontUtils.measureText(pFont, pText, lineStart, lineEnd);
@@ -186,19 +186,19 @@ private static > L splitLinesByLetters(final IFont
final float lookaheadLineWidth = FontUtils.measureText(pFont, pText, lineStart, lastNonWhitespace);
final boolean isEndReached = (i == (textLength - 1));
- if(isEndReached) {
+ if (isEndReached) {
/* When the end of the string is reached, add remainder to result. */
- if(lookaheadLineWidth <= pAutoWrapWidth) {
+ if (lookaheadLineWidth <= pAutoWrapWidth) {
pResult.add(pText.subSequence(lineStart, lastNonWhitespace));
} else {
pResult.add(pText.subSequence(lineStart, lineEnd));
/* Avoid special case where last line is added twice. */
- if(lineStart != i) {
+ if (lineStart != i) {
pResult.add(pText.subSequence(i, lastNonWhitespace));
}
}
} else {
- if(lookaheadLineWidth <= pAutoWrapWidth) {
+ if (lookaheadLineWidth <= pAutoWrapWidth) {
lineEnd = lastNonWhitespace;
} else {
pResult.add(pText.subSequence(lineStart, lineEnd));
@@ -215,7 +215,7 @@ private static > L splitLinesByLetters(final IFont
private static > L splitLinesByWords(final IFont pFont, final CharSequence pText, final L pResult, final float pAutoWrapWidth) {
final int textLength = pText.length();
- if(textLength == 0) {
+ if (textLength == 0) {
return pResult;
}
@@ -228,11 +228,11 @@ private static > L splitLinesByWords(final IFont pF
float lineWidthRemaining = pAutoWrapWidth;
boolean firstWordInLine = true;
int i = 0;
- while(i < textLength) {
+ while (i < textLength) {
int spacesSkipped = 0;
/* Find next word. */
{ /* Skip whitespaces. */
- while((i < textLength) && (pText.charAt(i) == ' ')) {
+ while ((i < textLength) && (pText.charAt(i) == ' ')) {
i++;
spacesSkipped++;
}
@@ -240,20 +240,20 @@ private static > L splitLinesByWords(final IFont pF
final int wordStart = i;
/* Mark beginning of a new line. */
- if(lineStart == FontUtils.UNSPECIFIED) {
+ if (lineStart == FontUtils.UNSPECIFIED) {
lineStart = wordStart;
}
{ /* Skip non-whitespaces. */
- while((i < textLength) && (pText.charAt(i) != ' ')) {
+ while ((i < textLength) && (pText.charAt(i) != ' ')) {
i++;
}
}
final int wordEnd = i;
/* Nothing more could be read. */
- if(wordStart == wordEnd) {
- if(!firstWordInLine) {
+ if (wordStart == wordEnd) {
+ if (!firstWordInLine) {
pResult.add(pText.subSequence(lineStart, lineEnd));
}
break;
@@ -266,7 +266,7 @@ private static > L splitLinesByWords(final IFont pF
/* Determine the width actually needed for the current word. */
final float widthNeeded;
- if(firstWordInLine) {
+ if (firstWordInLine) {
widthNeeded = wordWidth;
} else {
widthNeeded = (spacesSkipped * spaceWidth) + wordWidth;
@@ -274,7 +274,7 @@ private static