Can Someone Give Me A Simple COcos2d-X Particle Example? - cocos2d-x

I just want to make a CCParticleExplsion using Cocos2d-x and C++, but can't seem to find it after searching all over.
ObjC example:
CCParticleSystem *firework = [[CCParticleExplosion alloc] initWithTotalParticles:200];
[self addChild:firework];
[firework setTexture:[[CCTextureCache sharedTextureCache] addImage:#"star.png"]];

In most cases, the ParticleTexture comes with the plist file, and the whole plist file is from the particle designer. Usually, we use
CCParticleSystemQuad* p = CCParticleSystemQuad::create("whatever_particle.plist");
this->addChild(p);
but if you wanna use the particles comes with cocos2d-x, you can check how to use them in the Test Cases that comes with the cocos2d-x framework. the file name is ParticleTest.cpp

CCParticleExplosion is declared in cocos2dx/particle_nodes/CCParticleExamples.h.
Here's the C++ equivalent of your Objective C code:
CCTexture2D* texture = CCTextureCache::sharedTextureCache()->textureForKey("star.png");
CCParticleExplosion* firework = CCParticleExplosion::create();
firework->setTexture(texture);

see the tests folder in the cocos2d-x root folder.

Related

Managing Bitmap Font assets in LibGdx

I can load a Bitmap Font just fine with the following code:
BitmapFont font= new BitmapFont(
Gdx.files.internal( "Fonts/MyFont.fnt" ),
Gdx.files.internal( "Fonts/MyFont.png" ),
false );
but I'm trying to implement the AssetManager instead. So I recoded that snippet with the following code:
AssetManager assetManager = new AssetManager();
assetManager.load( "Fonts/MyFont.fnt", BitmapFont.class );
assetManager.load( "Fonts/MyFont.png", Texture.class );
assetManager.finishLoading();
BitmapFont font = assetManager.get( "Fonts/MyFont.fnt" );
If failed of course. The the call to the finishLoading() method returned a message indicating:
Couldn't load dependencies of asset: "Fonts/MyFont.fnt"
Ok. that makes sense, because I didn't do anything with the texture. So how do I pass the texture file as dependency? github.com/libgdx/libgdx/wiki/Managing-your-assets says:
BitmapFontLoader is a good example of an asynchronous loader that also
has dependencies that need to be loaded before the actual asset can be
loaded (in that case it's the texture storing the glyphs). Again, you
can do pretty much anything with this.
Well Duh! I guess they assume, "... if you only knew how!" But, their example doesn't show how - as a matter of fact their example shows pretty much what I've written. So, I'm stumped. All Google seems to be able to find are examples of what to do with TTF fonts, but nothing for regular old Bitmap Fonts.
Does anyone have an example of the solution to this error. Thanks a million!
When you use the AssetManager to load a BitmapFont is uses the BitmapFontLoader class. In the Libgdx api docs is says (api)
AssetLoader for BitmapFont instances. Loads the font description file (.fnt) asynchronously, loads the Texture containing the glyphs as a dependency.
The glyphs texture is automatically loaded as a dependency of the font. However, to know which file to load as the texture it checks in the .fnt file for the location of the texture.
I suspect that the reason that the font loaded successfully without using the AssetManager was because you manually added the Texture of the font as a parameter.
BitmapFont font= new BitmapFont(
Gdx.files.internal( "Fonts/MyFont.fnt" ),
Gdx.files.internal( "Fonts/MyFont.png" ), // This lets it know what texture to use
false );
When you used the AssetManager on the other hand it could not find/load the texture dependency. To fix this, open the .fnt file and make sure that the file="something.png" points to your fonts texture glyphs. (It must be the same as the name of the png. In your case file="MyFont.png")
That hopefully will solve your problem.
My tried and tested code:
AssetManager manager = new AssetManager();
manager.load("fonts/MyFont.fnt", BitmapFont.class);
manager.finishLoading();
font = manager.get("fonts/MyFont.fnt", BitmapFont.class);
An extract of the MyFont.fnt file:
info face=font size=54 bold=0 italic=0 charset= unicode= stretchH=100 smooth=1
aa=1 padding=2,2,2,2 spacing=0,0 outline=0 common lineHeight=50 base=43 scaleW=243
scaleH=511 pages=1 packed=0
page id=0 file="MyFont.png" <-- The important part
Hopefully that will solve your problem!
Also please note, as I was testing out the AssetManager I noticed that it only loaded when the .fnt was in basic text. When I tried use a .fnt file which used tags (like html) the texture failed to load. I used littera to generate the bitmap font I used for my test.

cocos2d-x tiledMap create return null?

I am currently following Ray's tutorial on cocos2d-x tile map and my very simple code is not working at all.
So here is my code,
_tileMap = TMXTiledMap::create("TileMap.tmx");
this->addChild(_tileMap);
and according to the debugger, _tileMap is null, which causes a crash on the addChild method.
Do anyone have any idea why this is happening?
p.s _tileMap is declared as a TMXTiledMap* in header, TileMap.tmx is totally filled with stuff and TileMap.tmx along with other things are imported into the resource folder using creating folder reference.
Have you try "Tile layer format" with "Base64(uncompressed) ?
I have same symptom as like you, but I get out from stock by change tile layer format from cvs to Base64(uncompressed).
enter image description here

TmxMapLoader to use packed tileset

In the old libgdx map api, they used to have
map = TiledLoader.createMap(Gdx.files.internal("maps/testmap.tmx"));
atlas = new TileAtlas(map, Gdx.files.internal("maps"));
tileMapRenderer = new TileMapRenderer(map, atlas, 8, 8);
However in the new libgdx the rule changes, to load a tilemap there is no longer needed to use map packer first. You can directly use the .tmx file with the tileset png. Something like following will work, and then call render.
TiledMap map = new TmxMapLoader().load("maps/testmap.tmx");
My question is the original tileselt.png that used to generate the .tmx file, it's size is not power of two. So I still have to either use Texture packer or a map packer to pack it for using.
I could not successfully associate the packed file with the .tmx;
Is there anyway to approach this issue?
Thanks
If you target GLES 1.0, you will need power-of-two tilesets. Some devices might allow non-power-of-two with GLES 1.0, but that isn't guaranteed. With GLES 2.0 this restriction is lifted, but you still might get better performance out of power-of-two.
You can still use the TiledMapPacker-produced maps, you will just need to load the map with AtlasTmxMapLoader instead of TmxMapLoader.
They do not need to be power of two. If you have Problems with it like you get the power of two error set Texture.setEnforcePotImages(false); inside of your MainClass.
You do not need the packer anymore so i think you cant associate the packer to the tmx file.
If you use the TmxMapLoader the tilesets need to be inside of the same folder of the .tmxfile.
If they are inside of an different directory you need to configure the source path inside of the .tmx file. here is an Example:
<tileset firstgid="257" name="mountain" tilewidth="32" tileheight="32">
<image source="mountain.png" width="512" height="512"/>
</tileset>
is the regular output of Tiled. If the Tileset is inside of for example config it you need to change it like this:
<tileset firstgid="257" name="mountain" tilewidth="32" tileheight="32">
<image source="config/mountain.png" width="512" height="512"/>
</tileset>
But it still need to be a subfolder of the path where the tmx file is.
Regards hope that may helps.

Anyone know a list of flash.includes? (as3)

I'm looking for a list of flash.include.whatever.whatever for as3.
If no one knows a list then can someone tell me the flash.include to use for drawing rectangle with the startFill and endFill things? Thanks for any help.
I didn't find anything on either of these googling, and the place I got the code for drawing a rectangle of course didn't have the flash.includes included in the example code... is their a reason so many people do that? Any way I can get around it?
Do you mean you want a list of the packages and classes that come with AS3? That is typically called the documentation and can be found here:
Adobe ActionScript® 3 API Reference
For drawing a Rectangle, you can start at flash.display.Shape. It has a graphics object with the methods .beginFill() and .endFill().
you can using a Graphics.
The Graphics class contains a set of methods that you can use to
create a vector shape. Display objects that support drawing include
Sprite and Shape objects. Each of these classes includes a graphics
property that is a Graphics object. The following are among those
helper functions provided for ease of use: drawRect(),
drawRoundRect(), drawCircle(), and drawEllipse(). You cannot create a
Graphics object directly from ActionScript code. If you call new
Graphics(), an exception is thrown.
The Graphics class is final; it cannot be subclassed.
here is a sample
import flash.display.*;
this.graphics.beginFill(0xff0000);
this.graphics.drawRect(0,0,100,100);
here is a Adobe Tutorial
AS3 all display class list here
You do not necessarily need to default AS3 include. fine compile. But include only the code you can see the hint. perhaps, CS4 after that if you use a specific class will automatically include. or ctrl+space is autocompletion.
As follows by default when you install the flash is because of the SWC path.
As per I know, there is not such a thing like Flash.include. May be you're trying to ask something else or may be i am still unknown about this feature.
If you found any positive thing about this, please let me know, i want to know that new thing.

LibGdx Texture loading in game and using it for various listeners

hi i am developing a game using libgdx. I want to make the texture object available to entire application. I have a requirement like, initialize the texture in one application listener and i want to use it in another application listener. Can anyone help me on this.
There are two ways I think you can do this. First, you could read the data into a static variable. For an example of this, take a look at the Art class in metagun demo: Art.java. The second way, which I have not tried yet, is to use the new AssetManager class. There is example use in the AssetManager test. These should help you access your textures more easily.
You don't need to have 2 or more Application listeners. Actually that only makes things harder.
Use Screens instead (extending Game in your core class instead of directly implementing ApplicationListener).
Either way, you should be able to just send the textures as arguments. For example I have a class Assets that contains all the textures and I sent it to each screen. You can make them static as Doran suggested too.