The first part of this tutorial can be found here: http://www.b4x.com/forum/basic4andr...-gameview-create-2d-android-games-part-i.html
GameView features were described in the first part. GameView handles only the drawings. The logic and sprite management are done in Basic4android code.
The attached project includes several classes that you can use in your game to help with common tasks:
SpriteAnimator - Every sprite should have a SpriteAnimator... SpriteAnimator is responsible for moving the sprite and changing the current frame.
CollisionDetector - A class that is added to a sprite that needs to detect collisions with other sprites. For example in the asteroids game the ship and missile classes each use a CollisionDetector object to detect collisions with the asteroids.
Both SpriteAnimator and CollisionDetector have a Tick method which you should call on each tick.
GamePad - A multitouch game pad implementation made of two joysticks. This is an improved version of a previous GamePad implementation. It works with GameView and provides better performance.
GameUtils - This is a code module with currently two features: scale calculation and a method to load sprite sheets.
These classes should be a good base for further customizations as needed.
The asteroids game example demonstrates the usage of these classes.
The game is quite simple. You move the ship with the left joystick and shoot the asteroids with the right joystick. Hitting an asteroid will crash the ship.
This project depends on three libraries: Audio, GameView and Gestures.
It should scale correctly on all devices.
As it is based on GameView is works on Android 3.0 or above. It can work on lower versions without hardware acceleration. The minimum target version in the manifest editor was set to Android 3.0.
Please feel free to ask any question about the code.
Credits
Asteroids sprites - XNA Development: Game Development for the masses
Sounds - Crash Sounds | Free Sound Effects | Crash Sound Clips | Sound Bites
GameView features were described in the first part. GameView handles only the drawings. The logic and sprite management are done in Basic4android code.
The attached project includes several classes that you can use in your game to help with common tasks:
SpriteAnimator - Every sprite should have a SpriteAnimator... SpriteAnimator is responsible for moving the sprite and changing the current frame.
CollisionDetector - A class that is added to a sprite that needs to detect collisions with other sprites. For example in the asteroids game the ship and missile classes each use a CollisionDetector object to detect collisions with the asteroids.
Both SpriteAnimator and CollisionDetector have a Tick method which you should call on each tick.
GamePad - A multitouch game pad implementation made of two joysticks. This is an improved version of a previous GamePad implementation. It works with GameView and provides better performance.
GameUtils - This is a code module with currently two features: scale calculation and a method to load sprite sheets.
These classes should be a good base for further customizations as needed.
The asteroids game example demonstrates the usage of these classes.
The game is quite simple. You move the ship with the left joystick and shoot the asteroids with the right joystick. Hitting an asteroid will crash the ship.
This project depends on three libraries: Audio, GameView and Gestures.
It should scale correctly on all devices.
As it is based on GameView is works on Android 3.0 or above. It can work on lower versions without hardware acceleration. The minimum target version in the manifest editor was set to Android 3.0.
Please feel free to ask any question about the code.
Credits
Asteroids sprites - XNA Development: Game Development for the masses
Sounds - Crash Sounds | Free Sound Effects | Crash Sound Clips | Sound Bites
Attachments
Last edited: