[Solved]Can’t resume from Sleep on Nexus S with Libgdx

When I test my game on my Nexus S, strange things happened. I pressed power button in my game, the phone fall asleep and my game paused. After touched the power button again, the screen is black and nothing showed up.

After check the forum of Libgdx, I found the method to solve this problem.

by mzechner » Mon Feb 21, 2011 8:05 pm

Ay. Could you do me a favor and add

<activity android:configChanges=”orientation|keyboard|keyboardHidden” … >

to your activity tag?

I’ll try to reproduce this locally with the phones i got.

After add the android:configChanges parameter in my AndroidManifest.xml, everything is OK.

ClassCastException when use TexturePacker of Libgdx

The weekly report of Android Game Untitled is paused, the game is still in  progress.

TexturePacker is useful extension class of Libgdx, it packed all images in one folder to one image with power of 2 width and height and create a pack file record the coordinate info of each sub image. With TextureAtlas you can  load subimage from the assembled one easily. Why we use this not directly use several images. That’s because

1.The width and height of Texture should be pow of 2, that’s not convenient when you want use other width and length.

2.Loading several images is slower than loading one.

When I use the TexturePacker I get an exception

Exception in thread “main” java.lang.ClassCastException: [B cannot be cast to [S
at sun.awt.image.ShortInterleavedRaster.getDataElements(ShortInterleavedRaster.java:245)
at com.matrix.libgdx.util.TexturePacker.squeeze(TexturePacker.java:362)
at com.matrix.libgdx.util.TexturePacker.addImage(TexturePacker.java:98)
at com.matrix.libgdx.util.TexturePacker.<init>(TexturePacker.java:78)
at com.matrix.libgdx.util.TexturePacker.process(TexturePacker.java:748)
at com.matrix.libgdx.util.TexturePacker.process(TexturePacker.java:837)
at com.matrix.libgdx.util.MyPacker.main(TexPacker.java:12)

Because I don’t find any others who confronted the same problem, I think it’s maybe my fault. After digging a while, using debug I found the reason, Every time when squeeze a special file the source.getAlphaRaster() return a ShortInterleavedRaster and that lead to the exception.

I have no idea of this png file, it’s same as others to me. And the only difference between them maybe the special one made by Photoshop and others by GIMP. It seems like the alpha raster of image made by Photoshop is short not byte. It’s just my guess, not sure about that. After removed it, everything is OK. :lol:

Android Game Untitled Week Six

Alpha 1 released, hurrah!

The whole game is nasty right now, I should add real graphic stuff, animation, sound, music, better UI and more funny gameplay. Although there is a lot of things to do and at the same time I learned a lot of things.

The art style in this game is cartoon like, I found a great vector design tool Inkscape. It’s easy to use and have a lot of tutorial, and it’s free and open source, great tool for indie game group with limited budget like us.

In this game, I want some sprites always on the top. However, libgdx can not create multi-layer or set the z-order directly with the Stage class. Update: Different from AndEngine, the multi-layer is implement with groups in libgdx(thx the heroes  behind libgdx, I’ll think twice before post :-) ). All actor in stage drew in the order of adding in stage. Later added actor on the top of before ones. There’s a easier way to implement multi-layer in stage. Create some Groups, each group behalf of one layer, the later added group has bigger z-order, the last group is always on the top. Then just add actors to the  group  instead of adding them to the stage directly. The basic multi-layer function has done.

In this week, I’ll concentrate on the graphic and gameplay.

Android Game Untitled Week Five

Gameplay is the most important thing in the game. I have played lots of games, from physic to mental, from paper to video. Finally, I will create my own game, so exciting. And then, so frustrating.

Designing a game is not as easy as playing it, I know that before, but it’s more difficult than I imagined. I spent some time to learn basic concepts about game design like game, play. I thought I had some ideas of game design.

Game is an interactive system, and also is a complicated system like the reality. The distinction between boring reality and funny game is game has clear rules and targets and always give feedback to player. A good game in my mind should be neat, don’t have too many factors lead to complexity nor few factors lead to boring.

Because my target platform is mobile phone with touch screen, the control system is also my focus.

Free DiskGenius

This is not a post about pirate software, just relax. DiskGenius is a great disk recovery software on Windows made by Chinese programmer Dahai Li. The English edition is not cheap, it would cost you $69.95. Of course it worth the money, data is priceless. However, there’s a free edition for Chinese customer, mainly because Chinese are not used to buy digital stuff. If you know Chinese, maybe you can try the Chinese edition to save your purse.

WARNING : IF YOU HAVE NO IDEA OF CHINESE, YOU SHOULD BOUGHT THE ENGLISH EDITION, OR YOUR VALUABLE DATA MAY LOST BY MISOPERATION.

Android Game Untitled Week Four

How fast the time is. Actually this week I only spend 2 or 3 days on the project.

I simplified the role creation module. Before that I should wrote a create method for every role class. These classes all inherited from a abstract class, they have different name, and I should call corresponding constructor. The classes I would constructed is saved in a XML file with their names. So I use reflection to construct them with their class name in runtime. Although it would affect the efficiency, considered the mess I wrote for the classes, I can sacrifice some efficiency.

Another work I did was making the main game loop, now we can call it a game not a prototype. Karen made some draft of graphic assets, seems like she is already on the way.

Some Background of Dream Home

Dream Home is a movie directed by Ho-Cheung Pang. This cult film told us a story of a normal woman did some crazy things for the apartment she dreamed of.

Actually the reality is crazier than the film. Since 1994, the system of dividing taxes lead most tax to the central government of China. Local government have more responsibilities but less money to spend. Some provinces found that they can lend the land to land agent for big profit. Because land in China belongs to Chinese people, so the government can not sell it but lend it. There are people live on the land would be lent. If some family don’t want to move to other place, it’s easy to solve it, as you can see in the movie. The officers and agents hire mobs to force the people move. Self-burning cases happened sometimes.

The Chinese housing price is very high. How high it is? For example, Google spent $1.9 billion bought new office in New York, it’s $6600 per square. And the housing price near second ring of Beijing is almost the same. The average annual salary of Beijing citizen is about $7000 and I think the number of New York is more than that.

There’s circle in Chinese society, government lent the people’s land to business men, business men built apartment and sold them to the people. People spent all the money their family have, from grandparents to parents, and also lent big money they should repay with their whole life from bank. The master of the land became the slave of it, the humble servant of the country stole everything of it. That’s the real story of the Chinese dream home.

Not Everyone Want To Make Big Money

This is not another story about a saint gave up fortune and did some meaning things, like helping children in developing country or save some wild life close to extinction. I want to talk about greedy.

I met many people, they complain of everything. Their job, family, girlfriend and social status are not what they want, they always said if big money can help them to do something they can’t do right now. At first, I take their complaint to the symbol of ambitious,  I thought they want do something big to change. And I found I was wrong, they love spending big money instead of making it, that means they want reap without sowing.

Making big money always accompanied with some risk. Only brave man dare to take the challenge. Most people said they want want to make big money just means they want to enjoy the experience of spending money. They just want the result not the process, so they deserved to complain.

Android Game Untitled Week Three

This weekly report is a little late, my weekends are busier than weekdays, can you belivie that?

Last week I refactored many classes, most of them are related to Scene and Role, now I have factory class to build them. There’s some sprite in my game can change their size, not scale themselves but looks like openging a scroll. I implement this feature with changing the region size I applied to the texture. Although it doesn’t support circle, it’s good for me right now.

I also add real contact handler and a boundary. I found a JVM crash after colliding many times, I’m not sure whether my fault or something wrong else where. I will put it to debug period to handle.