Android Tutorial GameView - Create 2D Android games - Part II

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.

SS-2012-07-31_16.12.12.png


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

  • Asteroids.zip
    253.3 KB · Views: 4,013
Last edited:

tsund

Member
Licensed User
Longtime User
New levels

Hi Erel, Im adding to this asteroids game and disecting the code to learn it. Could you help me with making new levels. After you beat it I want to keep going instead of just reseting and Id also like to add a score in the future.
 

manicmonkey

Member
Licensed User
Longtime User
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.

SS-2012-07-31_16.12.12.png


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


The Asteroids.zip seems corrupted when I download it. The other sample games qre fine but this zip seems corrupt. COuld youplease post it again as I would really like to try it.

Thanks
Lawrence
 

Rob_Wood

Member
Licensed User
Longtime User
The gestures library is not in the library list. How does one get the gestures library?
 
Top