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:

CapReed

Member
Licensed User
Longtime User
Differents routes for differents sprites

Hi all,

I'm dissecting this example to learn how to manage the sprites. I would be very useful to have controlled each of the sprites that are "alive", for example, to give one of the asteroids and a distinct personality that moved in a continuous motion elliptical. Actually in this case would not make much sense, but it would be very useful for example to control small groups of soldiers shaped sprites or warehouses. Do you remember the Galaxian and as alien ships fell with a certain path?

I think that would be necessary for both. First have controlled what the sprite is going to have a given path, and second, to know how to tell the program the "equation" of the trajectory.

How could indicate different paths to each piece of asteroid? Could you put a small example that illustrates this?

Thank you!
 

CapReed

Member
Licensed User
Longtime User
Sorry to insist, but how could have identified each of the live objects? Could at all times know that spriteanimator sprite is being processed? It may be a silly question ... but do not see it.
 

TheJinJ

Active Member
Licensed User
Longtime User
From memory the asteroids in the demo are held in a list so you have asteroids 0-4. Each one is passed to the sprite animator that adjusts its position. You could pass another value to the animator and use that with a select to have different movement for objects.

Sent from my GT-I9300
 

CapReed

Member
Licensed User
Longtime User
Thank you both, with your advice I have made ​​progress in the game I'm programming.

Thank you!
 

CapReed

Member
Licensed User
Longtime User
TextLabel in GameView

Hello!

How could I put a small text beside each asteroid that could put, for example, the X and Y position in which he is, or anything else, for example the number of impacts that have received?

I think I have no trouble controlling both the X and the Y or the number of impacts, but do not know how to put a text in a specific position within a GameView and it can move freely.

Thank you.
 

Armoured

Member
Licensed User
Longtime User
Hi,
I have this error when I try to compile this example:

Compiling code. Error
Error parsing program.
Error description: Unknown type: gestures
Are you missing a library reference?
Occurred on line: 3
Private ges As Gestures

The Gesture library is correctly installed.
How I can fix this error?
 

Peter Simpson

Expert
Licensed User
Longtime User
Good stuff

I'm going to try and implement the Game View library into a game shortly. I just need to improve on my gfx making skills in Photoshop and away we go.

I promise to try and not ask too many questions.

Thanks for the library Erel, and to everyone for the support in advance...
 
Top