Input Controls

In this section we will modify the GameEngineView to handle input controls. We do this by calling setFocusable(true); on the constructor of the view. All that is left is to override the onKeyDown and onKeyUp events.

In this snippet the “st” object is an Instance of the player object which will be discussed shortly. Note that on key down animate player, on key up we return him to the idle state.

Player

The player class houses the characteristics that a player consists of. We will use the Sprite Tile as the base object, this will take care of the visual part of our player. We will add function and attributes for animation

Game Loop

Game Loop is the main part of a game engine, it cycles threw at given intervals updating the game. The Game loop in this section will be fairly simple, it will be a thread that fires off every millisecond.

A couple things to notice. We pause the thread until the screen has finished drawing, the reason this is done is that the thread will continue to fire off and the onDraw() function will never be called. Also Since we are using a generic thread and not a UI-Thread we call postInvalidate() function to let android know that our view has to be re drawn.

The Current Game loop is really simple it will call draw on the items that implement the Drawable Interface.

Sprite Tile Class

The Sprite Tile class will be an object that extends the Drawable interface in the android api. Our Sprite will be composed of two files, a bitmap file (image of format type jpg, png, gif or bmp) and an xml file that describes its behavior.

The xml description file contains the information needed to animation the sprite sheet. All of the Elements and there Attributes will have respective fields in our sprite class. Note that the frame rectangle is not equally uniform, this allows to compose an animation where the tile thats being drawn doesn’t have to be the same size. It also tells us how much time each frame will last on the screen, along with a rectangle for collision for that specific animation.

Sprite Class:
The following class will load, draw and animate the tilesheet.

The class also implements a couple useful functions for checking the animations current state. Also note that the constructor take Resource-ID’s and not file paths. This is so that the developer has the choice of passing in images that have been compressed by the android api or raw images.

One of the biggest problems facing mobile web developers is making sites share the same level of user experience across all platforms. The approach i recomend is to make your application scalable enough to adapt to different screen resolution and features. This means you must know alot about the phone before hand, the response to this usualy “we can possibly collect all that information”. Yes I agree but, we already have people doing this work and donating it as open source.

These resource files gives us great control over what type of content can be served out to the device requesting information. This means that your mobile site has to intelligently make decision on the information that you are now provided, because now you know screen resolutions, if a the mobile device can handle video. Use this information wisely dont not try to make a use case for everyphone. Group phones based on ability and screen size.

Group devices into categories for example the nextGen Group can be composed of iphone, android, and other touch phones.

Short answer yes, why not? The key is to come up with what you expect your user to get put off it; and then from the point of view of the user, and what they expects out of it. The intersection of the two sets gives you the minimum required to successfully go mobile.

Going mobile can mean different things and because of that implementation may vary. In most cases it means a mobile version of the current offering via a mobile browser. Now I chose my previous words carefully because mobile could mean two things; a mobile application or a mobile website.

Mobile Web Site

This is a mobile version of the standard website. It may or may not contain all the information the main website has. Mobile sites currently are stripped down with plain html and css, currently only next gen phones such as the iPhone, android and windows mobile 8 phone support more complex CSS and javaScript. Even though this is quite a limitation it those not mean that you cannot have a usefull and compelling mobile site that runs on even a cheap prepaid phone. The key is to simplify and keep it clean.

Mobile Applications

Mobile applications fall under two buckets:

Mobile Web Application: This is a mobile website that is not just informative but provides some functionality to the user.