Tutorial:AddingImages

From FANG

Jump to: navigation, search

These instructions assume you already know how to make a basic game using the FANG Engine.

These instructions are currently available for two different IDEs (Integrated Development Environment):

The instructions below correspond to the JavaWIDE instructions. If you would like the instructions for any of the above IDEs, click on the link above.

Contents

0. Look at a Simple Example

Take a look at this simple example that shows an image.

If you are using the new version of the FANG Engine, Take a look at this simple example that uses the new version of the FANG Engine.

1. Upload an Image

The first step to adding an image to your game is to upload an image file to the JavaWIDE site. Both the Sandbox and the Playground allow you to upload files up to 100K. Under the Toolbox on the left menu, click on Upload file. Select the image you would like to show in your game. Most common formats are supported including jpg, png, gif and animated gif.

Be sure to remember the exact name of the file you are uploading and be aware that JavaWIDE typically capitalizes the names of all files. You will need to be able to type in the exact name of the file in the following step.

2. Declare and Initialize an ImageSprite

In your class, put in the following line of code:

private ImageSprite sprite;

and you'll also need the following line to initialize your sprite. You usually put this in your makeSprites or startGame method

sprite=new ImageSprite("YourImage.gif");

where you replace YourImage.gif with the exact name of the file you uploaded in step 1. Now you can use sprite just like any other Sprite.

3. (Optional) Transform the ImageSprite

Once you create the sprite, there are various ways to manipulate it:

sprite.flipAlongHorizontalAxis(); reflects the sprite along its original x axis
sprite.flipAlongVerticalAxis(); reflects the sprite along its original y axis
sprite.setLooping(true) if the image is an animated gif it makes it loop indefinitely
sprite.setLooping(false) if the image is an animated gif it makes it play through once only
sprite.startAnimationNow(); starts the animated gif animation at this time. Animated gifs are not guaranteed to start looping at any particular frame unless you call this method explicitly.
sprite.setImageIndex(2) sets the frame of the animated gif to display at this time. This stops all animation and looping.




Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter

Games
Games