Embedding loads of images - arrays

I got 42 images that I want to embed and then put on an array.
I tried to do it within a for loop, but it doesn't seem to work.
How exactly can I avoid to have 42 embed lines + a very long line for the array ?

The only way to embed multiple images without an embed line for each one is to use a Sprite Sheet (sometimes called a 'Texture Atlas', or simply a 'Sprite'). This will take a folder of images, and generate one large image. And also give you a data file (use XML or JSON) of all images in your folder and where they're positioned inside the Sprite Sheet.
You can then embed the Sprite Sheet once.
For this you need 2 things:
1/ Software to create your sprite sheet... There are many tools available, the one I use for example is Texture Packer: http://www.codeandweb.com/texturepacker
2/ An actionscript class or framework, designed to handle referencing images from your sprite sheet... This is a native feature of Starling, but if you're not ready to support Flash Player 11 then you can find some publicly available frameworks for this:
For example: Spriter: http://abeltoy.com/projects/spriterAS3/usage.html has a class called BitmapSpriter to handle sprite sheets natively in AS3.

You could use a for each loop.
var items:Array = ["hi", "there", "bob"];
for (var index in items) {
trace(index+" => "+items[index]); // traces "0 => hi", "1 => there" and "2 => bob"
}

Related

How to compress game data in one file

I'm trying to make game like "Duke Nukem 3D". I will have many maps in my game and each map will have it's own (and no more!) data files such as textures, sounds and so on, that's why I need to compress all these data files to one "map" file.
So, let's image that I want to test my maps one by one, and after compiling my code I want to test my first map with her textures and sounds, And when I type in my command line something like this: ./game_name "mymap.rce" or ./game_name "mymap.zip" my game must start with map what I typed and this map must have textures and sounds which I compressed with her.
You can download demo here.
To run demo you can type this for example: ./rce demo1.rce
So, I just made my archiver(without compress). If you need it, you can find it here.

scn file all items rotated

I have a curtain I want to render in my ARKit app. I added all parts of my curtain (exported as COLLADA) and added them in my .scn file and placed them so that they line up properly and form a correct curtain.
Now I have added the file to the ARKit testing app and it seems like all individual objects rotated around the X-axis of their own coordinate system.
Why is this? Does it have something to do with Y vs Z being up?
Blender's coordinate system uses Z-up, but SceneKit uses Y-up. I believe that's where your issue is stemming from.
SCNScene has an initializer with loading options, try using the convertToYUp option. This could be done at runtime or before with a custom command line tool.
Here's an example of how to load a Collada file with the convert Y-up option, then exported to the url destination of your choice.
let scene = try? SCNScene(url: daeURL, options: [.convertToYUp: true])
scene.write(to: scnURL, options: nil, delegate: nil, progressHandler: nil)
I've been very happy with the results. SceneKit is able to convert not just single objects but multiple objects in complex scenes.
Just remember to apply rotation in Blender before exporting to get good results. I believe the hotkey to apply rotation is Ctrl+A, then R.

Libgdx texture atlas vs files

So in my game i have more than 32000 images (size: 32x32). How to store this amount of images? What could better: loading these images as separate files or as one big texture atlas?
When you load a texture (image) in your game by doing you load a texture in GPU.
So let's say you have 3200 images and you load them separately that means 3200 textures loaded on the GPU. That's harsh and will eat loads of memory.
Now let me explain what is TextureRegion
TextureRegion, takes an area from the Texture according to the dimension you provide, the advantage of having it is that you don't have to load textures again and again and the bigger advantage is you don't have to load each and every texture on GPU as you can do it directly by loading one big texture and extracting sub regions(TextureRegions) from it.
Now because you want to use TextureRegions, it will be hard to know the dimensions of each and every sub image to load them from Texture Sheet. So what we do is we pack the Textures into a bigger Texture using TexturePacker(an application) which then creates a .pack file. It will pack every texture into one image AND create a .pack file. Now when you load the .pack file, it is loaded using TextureAtlas class
For example imagine a pokemon pack file which has all the pokemons into it.
TextureAtlas pokemonFrontAtlas = new TextureAtlas(Gdx.files.internal("pokemon//pokemon.pack"));
Now you packed 3200 files using Texture Packer and you want to load a image(Texture) which has file name as "SomePokemon".
Now to get a particular TextureRegion from it, you do
pokemonFrontAtlas.findRegion("SomePokemon")
findRegion(String name) returns you the textureRegion from the TextureAtlas.
A TextureAtlas class contains a collection of AtlasRegion class which extends TextureRegion class.
See Javadocs for more details
TextureAtlas

Load an Image in Multiple movie clips using as3

I am really curious of asking a particular question to everyone of you. I am creating an Application in flash that is lot similar to this Application Zazzle Case Cover
I am almost ready with what i was supposed to do and How i have to do. But, still i am ain't a very big Tech_geek to handle all these . I list out some of the things which i could`nt achieve. Kindly help me if possible.
I know that inorder to load unlimited number of images in a Movie Clip, we need Array. But to go with it, I am not sure of framing it properly.
I have Merged certain codings from internet and encoded it to act as the Application in that Site for a Single image in a Single view, but when i try to add child or make it display the same image in all other views i can't frame the coding. It is not behaving properly .
Last but not the Least, I am confused of displaying the Bitmap data in as3... I wanted to show the Uploaded Panel Image in the below thmbnail area but i am not so sure of it.
The Questionnaire format of the Above problems are
How to upload unlimited number of images in a Movie Clip using Array ?
Is it is possible to Display the same image in two Movie Clips simultaneously using addChild ?
I had lots of blah and blah but this area plays the 2nd Question and even Answer for it. But i am ain't sure revealing the Answer.
function onMovieClipLoaderComplete(event:Event):void
{
// Hide progress bar
progressBar.visible=false;
var loadedContent:DisplayObject=event.target.content;
var loader:Loader=event.target.loader as Loader;
loadedContent.x=-37.625;
loadedContent.y=-37.625;
loadedContent.width=75.25;
loadedContent.height=75.25;
trace("loadedContent.width="+loadedContent.x);
trace("loadedContent.height="+loadedContent.y);
mcOnStage=true;
con1.container.addChild(loader);
clears.addEventListener(MouseEvent.CLICK, removeMC);
function removeMC(MouseEvent):void {
trace("Its Removed");
if (mcOnStage )
{
con1.container.removeChild(loader);
con1.textcontainer.removeChild(txt);
mcOnStage=false;
}
}
}
"con1.container.addChild(loader);"
Can i add "con1.container2.addChild(loader);" for the same loaded image.
How to Clone a Movieclip's Bitmap data and Display it in another area or Movieclip ???
Guide me if possible...
I have included the SWF file along with this Question...
https://docs.google.com/file/d/0B5jnHM1zpP4MOHRCeWFqX05sSTA/edit?usp=sharing
Can Someone check the first Site and gimme little notes of how can i bring all those modules in this flash as3 based application.
Here's how you would display the same image twice, with reference to the code you included in your post:
//here's your code
var loadedContent:DisplayObject=event.target.content as DisplayObject;
//create bitmap data instance same size and as the loaded content
var transparent:Boolean = true;
var fillColor:uint = 0xFFFFFFFF;
var bitmapData:BitmapData = new BitmapData(loadedContent.width, loadedContent.height, transparent, fillColor);
//draw the loaded content into the bitmap data
bitmapData.draw( loadedContent );
//create new bitmap
var bitmap:Bitmap = new Bitmap( bitmapData);
//add the loaded content
con1.container.addChild(loader);
//add your 'cloned' content
con1.container2.addChild( bitmap );

How do load an image into a 2D array element?

I'm currently doing my A-Level Computing project for which I am making my own version of the classic game Space Invaders.
To create the wave of space invaders I want to use a 2D array of images, where the images are loaded from a disk and then displayed on the form but I am unsure of how load the images into the array and then display the array on a form.
The current arrays are:
ImagePaths:array [1..3] of string =('SpaceInvader1.jpg', 'SpaceInvader2.jpg', 'SpaceInvader3.jpg');
Wave:array[1..11, 1..5] of TImage; x,y:integer;
What I would like to know is: how would I load an image into an array element? eg how would I load 'SpaceInvader1.jpg' to array element [1,1]?
Any help would be greatly appreciated.
If you're going to be coding graphical animations, you probably won't want to do it directly on the form. Trying to move things around can be tricky, especially if you want to animate smoothly and not get a lot of flicker and graphical artifacts.
It would be better to use a rendering library. The workflow goes like this:
Create a rendering context on the form. This is a control that provides a surface for graphical animations to run on.
Load your three images into memory.
Create an array of objects to represent the game data associated with your monsters. (Position, movement direction and speed, etc.) It can be flat or 2D, whichever works better for you.
Set up a render loop that goes like this:
For each monster in the array, draw it at its position.
Draw the player's ship and all projectiles.
Check for collisions and handle appropriately.
Check for player input and handle appropriately.
You can find plenty of information on rendering libraries for Delphi in the forums at Pascal Game Development.
You have the following declarations:
ImagePaths:array [1..3] of string =(
'SpaceInvader1.jpg',
'SpaceInvader2.jpg',
'SpaceInvader3.jpg'
);
Wave: array[1..11, 1..5] of TImage;
You want to know how to populate the array of images. It is quite wasteful to create 55 images when 3 will suffice. So instead of that, use indirection. Store references to the images. And TImage is a visual component, and so not appropriate for a sprite.
I would hold the images in an array like this:
Sprites: array [1..3] of TBitmap;
And populate it
JPEGImage := TJPEGImage.Create;
try
for i := 1 to 3 do
begin
JPEGImage.LoadFromFile(ImagePaths[i]);
Sprites[i] := TBitmap.Create;
Sprites[i].Assign(JPEGImage);
end;
finally
JPEGImage.Free;
end;
Then populate your Wave array like this, for example:
Wave: array[1..11, 1..5] of TBitmap;
....
for i := 1 to 11 do
for j := 1 to 5 do
Wave[i,j] := Sprites[1];// or whichever sprite you want
Of course your sprites may be better with a real name rather than in an array.
Some other comments:
JPEG is a bad format for a game sprite. It is a lossy format. A plain Windows bitmap would be fine, as would a GIF or PNG.
I'd much rather see the images as embedded resources. Then your executable can stand alone.
I'd also far rather see your Waves array holding the state of each invader. And then you would create a function that would render that state onto a canvas.

Categories

Resources