TiledMapTileLayer wont cast from TileLayer - libgdx

I'm trying to get cells from a tile layer in libgdx (for a tiled map). A lot of examples I see say to cast a layer to TiledMapTileLayer, but this doesn't work.
TiledMap tiledMap = new TmxMapLoader().load("start.tmx");
TiledMapTileLayer obsLayer = (TileMapTileLayer) tiledMap.getLayers().get("obs");
I get this exception:
Exception in thread "LWJGL Application" java.lang.ClassCastException: com.badlogic.gdx.maps.MapLayer cannot be cast to com.badlogic.gdx.maps.tiled.TiledMapTileLayer
at net.myname.mygame.Game.create(Game.java:66)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:149)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:126)
My guess is the library was updated to work differently, but I don't see any examples doing things in a new way. Anyone know what to do?
I'm using libgdx 1.9.9

Oh wait, I guess my map got reverted accidentally. Was using a object layer before but changed it to a tile layer. Changing to a tile layer instead of an object layer makes it work.

Related

Why do I get ArrayIndexOutOfBoundsException when I build an imageView with JavaFX?

I have various places in my JavaFx app where I insert images(png/gif). It usually works with one exception. What I do:
I put the images in a specific directory under resources.
I load them like this:
ImageView openView = new ImageView("/pics/logo.png");
An alternative that also works is:
InputStream resourceAsStream = classParameter.getResourceAsStream("/pics/logo.png");
Image image = new Image(resourceAsStream);
ImageView openView = new ImageView(image);
The problem:
There is one gif that has a white background. When I insert it in the app it works, but if I insert the same gif after it is transformed (to add transparency for background) I get :
ObjectProperty [bean: javafx.scene.image.Image#2ac5919d, name: exception, value: java.lang.ArrayIndexOutOfBoundsException: 4096]
If I open it for view, the transformed gif is displayed as expected.
Any ideas on why is this exception thrown?
Stack trace:
java.lang.ArrayIndexOutOfBoundsException: 4096
at com.sun.javafx.iio.gif.GIFImageLoader2$LZWDecoder.readString(GIFImageLoader2.java:388)
at com.sun.javafx.iio.gif.GIFImageLoader2.decodeImage(GIFImageLoader2.java:148)
at com.sun.javafx.iio.gif.GIFImageLoader2.load(GIFImageLoader2.java:209)
at com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:368)
at com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:328)
at com.sun.javafx.tk.quantum.PrismImageLoader2.loadAll(PrismImageLoader2.java:119)
at com.sun.javafx.tk.quantum.PrismImageLoader2.<init>(PrismImageLoader2.java:70)
at com.sun.javafx.tk.quantum.QuantumToolkit.loadImage(QuantumToolkit.java:648)
at javafx.scene.image.Image.loadImage(Image.java:1036)
at javafx.scene.image.Image.initialize(Image.java:785)
at javafx.scene.image.Image.<init>(Image.java:599)
at javafx.scene.image.ImageView.<init>(ImageView.java:167)
at helpers.Helpers.setImageView(Helpers.java:173)
I managed to make it work by using another gif editing tool. So the problem was the conversion. Even if the initial gif seemed fine, under the hood it made JavaFx crash. (Won't share here the name of the tools that work and that didn't work, since it may be against stackoverflow policy).

How to change bitmapdata in AS3

I'm building a spritesheet class. Hopefully this will be low hanging fruit to someone, but I'm stumped.
I have a spritesheet (.png) that I've loaded at runtime and placed a section of it on the stage using this code from within the Spritesheet class .as file ouside of the constructor method:
private function onLoad(e:Event):void
{
var loaderBmp:Bitmap = Bitmap(_loader.content);
_bmpData.copyPixels(loaderBmp.bitmapData, new Rectangle(0,0,80,80),new Point(0,0));
}
That works fine. I get my slice of the .png file displaying nicely. In my case, the spritesheet is meant for animating a character, so I need to update the BitmapData and I'm not having any luck. Here is what I'm trying this within my Main class in a function I use to alter the frame of the animation depending on the state of the character:
c._thisSpriteSheet._loader.content.bitmapData.copyPixels(loaderBmp.bitmapData, new Rectangle(0,20,50,30),new Point(0,0));
loaderBmp is a variable who's value is var loaderBmp: Bitmap = Bitmap(_spriteSheet._loader.content);
c is a reference to the Runner object that is the character.
_spriteSheet is a property of the Runner class of type Spritesheet.
_loader is a property of the c._spriteSheet and is the Loader object used when the spritesheet was instantiated.
It doesn't throw an error, but it also doesn't replace the original bitmapData object with the new one. I thought maybe this meant that I need to create a new BitmapData object and use that in the copyPixels method, but that returned the same results (nothing). When I step through the code in debug mode, everything looks like it is working, but my display object does not update with the new bitmapData. What am I tripping on?
Thanks for looking!
Well, probably no one will read this since I'm answering it so quickly, but I literally spent 3 days trying to figure this out. Sometimes trying to ask the question in a concise way helps one answer their own question, and moments later, voila!
So in case anyone has a similar issue, what I was doing wrong was that I was trying to access the BitmapData object via the Loader that originally loaded it. Then it dawned on me that I could simply reference the BitmapData directly via that property of the SpriteSheet class I had made. I think this will be pretty confusing for someone else to follow. If a moderator sees this and thinks it's junk, I don't mind it getting erased, but thought I'd keep it up anyway. The new code looked like this:
c._thisSpriteSheet._bmpDSheet.copyPixels(loaderBmp.bitmapData, new Rectangle(0,20,50,30),new Point(0,0));
and _bmpDSheet is the bitmapdata property of the class.

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

AS3 Defining coords for a screenshot?

I've built a photo booth app for an installation and I need to take a screen shot of the bitmap data with it's frame... I foolishly nested my objects all wrong way too early in the game so taking a picture of just the display object is moot at this juncture, and I dont have time to re-organize everything.
I know the encoder can output stills of the stage, but can that be a defined set of coords? I have an 800x600 region that needs to output, ignoring the rest of the stage.
I am playing with other options as well, but if there is anything that seems obvious, i would greatly appreaciate it!
You can get the whole stage as a bitmap data and then use the copypixels method to copy the region you need.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#copyPixels%28%29
Or you can use the draw method of BitmapData class to draw a display object into that bitmap data.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#draw%28%29

TweenLite does not work with object

I got the following problem:
I have an object called tempScore for my game.
This object is blitted to the canvas by a renderer via the copyPixels method. The object is NOT a display object. It's a Score-object (self made). The Score-object extends an object called BasicBlitArrayObject. The BasicBlitArrayObject extends an EventDispatcher (therefore no display object).
I tried to apply several different TweenLite-plugins to my tempScore-object (i.e. TransformAroundCenter, colorMatrixFilter, etc.). But nothing happens. Absolutely nothing.
Sometimes I get error messages (when a plugin requires a display object and my object is NOT a display object). So far so good.
According to Greensock (maker of Tweenlite) his engine can tween ANY numeric property of ANY object. So when a plugin like TransformAroundCenter requires a display object for tweening I have to modify the plugin to get it working for my non-display object (tempScore). Currently I can't do that because it's way too hard for me.
My game rests upon this code:
http://www.8bitrocket.com/book/ch11_blastermines.zip
Try to apply TweenLite with an object called tempMine inside the game class BlasterMines. It won't work. Any help, please?
Greensock's claim is correct, in it's exactness. You can tween any numeric property of any object. This statement does not include the application of plugin features.
The reason that the TransformAroundCenter and ColorMatrixFilter plugins don't work for you is that they each utilise some property or method of DisplayObject. In the case of transformAroundCenter that's DisplayObject.localToGlobal() and for ColorMatrixFiler it's DisplayObject.filters.
I have to ask why you're applying these plugins to something that is not a display object? In blitting (as it applies to AS3), the basic idea is that you read an area from a sprite sheet to a BitmapData object, which in turn you write to a Bitmap object on the stage. Both BitmapData and Bitmap extend DisplayObject, which is what you need. For higher compatibility you should target the Bitmap object that is actually on the stage, TransformAroundCenter will not work correctly with an object that is not on the stage.
For a better answer you will have to post some code, and possibly a screenshot from a debugger like Monster Debugger 3 which shows your expanded display tree.