Published on the 30th June 2015.
ISBN 139781785280122.
Paperback 388 pages.
- Animate your characters with sprite sheets, add multiple scrolling parallax backgrounds, and implement genuinely tough, playable levels in your games
- Implement basic and advanced collision detection mechanics
- Implement a multitude of other game features such as pickups, firing weapons, HUD’s, generating and playing sound FX, scenery, level transition, high scores, and more
The book is best suited for existing Android or Java programmers who want to adapt their skills to make exciting Android games. The book starts by using slightly beyond beginner level Java and steadily increases the difficulty. The book is also for determined readers who might have no Android, game programming or even Java experience, but a reasonable understanding of object oriented programming knowledge is assumed.
Learn to build exciting Android game projects. Build a simple flappy-bird like game to a multi-environment, tough, retro platformer then an OpenGL ES 2 Asteroids clone, running at hundreds of frames per second .
Available Now!
Build real games
This book will help you get up to speed with the essentials of game development with Android. The book begins by teaching you the setup of a game development environment on a fundamental level. Moving on, the book deals with concepts such as building a home screen UI, implementing game objects, and painting the scene at a fixed resolution. Gradually, it builds up to the implementation of a flexible and advanced game engine that uses OpenGL ES 2 for fast, smooth frame rates. This is achieved by starting with a simple game and gradually increasing the complexity of the three complete games built step by step. By the end of the book, you will have successfully built three exciting games over the course of three engrossing and insightful projects.
This looks awesome! Just finished the snake game and trying to improve it.
Really believe in your tutorial style.
Thanks very much Tom. Have fun with Snake. I would be interested to hear what improvements you decided to add. Perhaps on this article
http://gamecodeschool.com/blog/learning-java-by-building-android-games/
if you want to share.
Cant wait!!
Hi
I would like to play the game which you built. Is it uploaded in play store?
Please pass me the name.
Thanks
Jeson
Hi Jason,
They aren’t at the moment but I guess they should be so sorry. I will get round to it as soon as I can.
Thanks and sorry again.
John
Hi, I just wanted to thank you, I have “Learning Java” and it’s helping me a lot. I’m well on my way to making some great games. I look forward to reading your new book. Thanks again.
Hi Jesse,
Really nice to hear from you. I am very pleased you are finding it useful. Keep in touch.
John
Dear Mr. Horton,
first of all sorry for my bad english. Thank you very much for sharing ur programming experience with us. I love your books. I was totally new to java and android studio and now im capable of making simple android games. Thanks a lot
I have a problem with the TappyDefender Game, i followed all of your instrucitons in the book but sometimes the game crashes and i get a “java.util.ConcurrentModificationException”. How can i solve this? also in none of the games i can play the sound. I always get a sound not ready message in the logcat.
Greetings
Hi Niclas,
Many thanks for your message. I will try and help you solve the issues.
With regard to the concurrentmodificationexception, this is caused by two threads accesing the same data/object at the same time. This “shouldn’t” happen with the tappy defender code. Could you post the logcat output around the error and I will try and identify the precise cause.
The sound not ready error is almost always because the system can’t find the files at all. Just double check the names of the files correspond exactly, including upper/lower case. Also, did you add the files manually as described using your operating system to make the folder and add the files? Android studio allows you to add them through the project explorer but this isn’t the way to do it. Also the folder you add must also be the exact spelling and capitalization. If in doubt you can drag the entire assets folder from the download bundle into your folder hierachy.
Thanks again,
John
Hello John,
Thanks for your quick reply and for the help. As you mentioned the error with the sound was caused by putting the files in the wrong folder. Iput them in the res- instead of the mainfolder. Now i fixed it
Here is the logcat output for the crashing tappy defender:
12-27 10:45:38.456 14179-16209/com.packtub.c1tappydefender E/AndroidRuntime: FATAL EXCEPTION: Thread-43886
12-27 10:45:38.456 14179-16209/com.packtub.c1tappydefender E/AndroidRuntime: java.util.ConcurrentModificationException
Greetings
Niclas
Hi Niclas,
I have looked really closely and I can’t see how the tappy defender code would cause it. I am not saying it’s impossible but I can’t see it. Have any modifications been made to the code you are getting the error on? If so try running the unmodified code from the download bundle and see if you manage to get the same error.
Hello John
I made a new TappyDefenderGame and used exactly the same files from the bundle. Sometimes no error happens and sometimes after 5-10games the error occurs again.
I just manually added in the onCreate-Method:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
to make it fullscreen.
The error only occurs if i ended a game and tap to start a new game. While the game is running everything is flawless.
This time i got the error: FATAL EXCEPTION: Thread-144020
java.util.ConcurrentModificationException
I dont know if it makes any difference.
Greetings Niclas
Hi Niclas.
Here are a few things to try.
Try getActionBar.hide(); instaead of requestWindowFeature(Window.FEATURE_NO_TITLE);
Also make sure that all three lines of code are added before super.onCreate();
More specifically, the error you are getting is suggesting that a variable declared in one thread is be accessed/modified from outside that thread. Does that help you look for the error further.
John.
Thanks for the quick answer John
I think i found the error. The SpaceDust caused the game to crash. I read that the ArrayList could have the negative side effect to cause java.util.ConcurrentModificationExceptions. I tried to solve it by using an Iterator method instead, but im doing something wrong i guess. There is no SpaceDust showing up. Could u take a quick look at my code and help me? plz
I declared in my TDView Class:
ArrayList dustList = new ArrayList();
ListIterator it = dustList.listIterator();
on draw:
for (ListIterator it = dustList.listIterator();it.hasNext();) {
SpaceDust sd = it.next();
canvas.drawPoint(sd.getX(), sd.getY(), paint); }
on update:
for (ListIterator it = dustList.listIterator();it.hasNext();) {
SpaceDust sd =it.next();
sd.update(player.getSpeed()); }
Thanks
Niclas
Hi Niclas,
The solution to java.util.ConcurrentModificationExceptions problems with ArrayList is covered in the platform game project when we implement a machine gun for the player character. Take a look at it and you will probably be able to use the same techniques here.
Hi John,
Just started on this book and it is awesome, as was the first.
I do have one question about Tappy Defender. I’m already building it and have got up to the space dust class. I have no issues with the code but, when I run the app on the phone, the app is very jerky and stutters. I cannot find a sample app on the Play Store to compare so I am wondering if you could tell me the jerkiness and stuttering is right/to be expected. My belief is because the app is redrawing (through canvas) multiple times and many objects. It is therefore struggling and hence is slowing down. Is this right?
Thanks
Tom
Hi Tom,
Nice to hear from you. Using the amount of space dust suggested in the book shouldn’t cause jerkiness on any but the most basic of phones, or perhaps the emulator. Try reducing the amount of space dust, even as low as 5 or 10 and you still get a pleasant space-travel-like effect. Or if you have/can borrow another device try that. I am working on a Game Code School app which will have working versions of all the demo projects from the site and all the books too so you could see if it has the same problem but that will probably be a few more weeks before it is done.
All the best,
John
Hi John,
I realised it was that I had quite large bitmaps and this was slowing the canvas down. Thank you for getting back to me.
I have another question regarding Tappy Defender: I’m working from a Galaxy S6 and the text size from the canvas is tiny, no matter how much I change the setTextSize. Do you know why this is?
Thank you.
Tom
Hi Tom,
Galaxy s6 is a really high density (nice) screen. In a full game you would test for the screen resolution and vary the text size accordingly. Try changing the text size like this:
paint.setTextSize(48);
Vary the value up or down to suit your device.
Hope this helps.
Hi John,
I just finished “Learning Java by Building Android Games” and fortunatelly there is also a part 2 “Android Game Programming by Example”. I love your books and they are worth every penny! I had the idea to start an own Space Game and just wanted to ask if I could use your awesome Space Ships from the TappyDefenderGame.
Greetings
Ben
Hi Ben,
I have no problem with you using them. Just watch out if you use them commercially, I am not sure what the publisher thinks? They came with a book which you paid for so I guess you should be able to do anything reasonable with them. Possibly reselling is the only risky thing? I say go for it.
Thanks for your message,
John
Ran into some problems with the platformer game. I downloaded the code bundle and copy-pasted the code from the chapter 8 folder. It would be great if you could shed some light about these…
1) Regarding sounds, I created the assets folder by right-clicking ‘res’>’new’>’Android resource directory’ (and later just ‘directory’). For directory name>’assets’, resource type>’raw’ (later values).
During the first build, Android Studio was asking for the associated file type and offered options, but there was nothing for ‘sound’ so I unwisely chose ‘text’. This resulted in gibberish text in the editor and gradle failing with ‘Error: Content is not allowed in prolog’ and ‘Error:Execution failed for task ‘:app:mergeDebugResources’.
> C:\AndroidStudioProjects\C8PlatformGame\app\src\main\res\assets\coin_pickup.ogg:1:1: Error: Content is not allowed in prolog.’
2) I decided to remove the sounds for the meantime and ran into a minor problem of a missing ic_launcher which was solved by just placing a file with that name into the drawable folder.
3) So the build went smoothly and I connected a device and uploaded/ran the game. It showed up and played ok but later the lives went negative, i got like, up to -48 lives and the map started dancing left and right (background and Bob stayed fixed), I can move Bob but decided to reset the game. After that it occasionally danced left and right. Bob at times went behind the map.
Hi Pete, thanks for your questions.
Regarding the sound, use your operating system (windows explorer on windows) to create the folder and to copy the sound files into it. Creating it through Android Studio is awkward and error prone. As the Gradle build system might now be a bit messed up from what has happened, I would recommend starting a new project and pasting the code again.
The second problem should disappear when you create a new project.
Regarding the juddering/incorrect graphics, I am not sure what that could be. Try exporting a .apk file to get the smoothest results and running that on a device. If it still judders, to see if the device could be incompatible in some way, download the free Game Code School Android app and run the game from there. Do you get the same problem?
If you have time let me know how you get on and I will try and help.
All the best,
John
Got the sound working as per your advice but I still get the juddering and more so when lives go negative even with a standalone apk file. Will try your gamecode school app when I have the time.
Hi Mr. John Horton i have two error in chapter 2.
1. C:\Users\omar\Desktop\Im A Good Programmer\C1TappyDefender\app\build\intermediates\manifests\full\debug\AndroidManifest.xml
Error:(13, 23) No resource found that matches the given name (at ‘icon’ with value ‘@drawable/ic_launcher’).
2. Error:Execution failed for task ‘:app:processDebugResources’.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘C:\Users\omar\AppData\Local\Android\sdk\build-tools\23.0.2\aapt.exe” finished with non-zero exit value 1.
Hi Omar,
My best guess is that the latest version of Android Studio is now generating an app icon in the mipmap folder instead of the drawable folder.
Did you copy & paste the AndroidManifest.xml file from the download bundle?
If so, open the AndroidManifest.xml file and change this line:
android:icon="@drawable/ic_launcher"
to this:
android:icon="@mipmap/ic_launcher"
Then, from the main menu, select Tools | Android | Sync Project with Gradle files
And try playing the game again.
In future projects you can either keep changing drawable to mipmap or if you make the changes step by step from the book instructions and don’t copy & paste the AndroidManifest.xml file, then everything should work without this change.
Many thanks for letting me know about this issue.
I hope this helps.
All the best,
John
Mr. John Horton
I solve my problems
First problem was in MainAtctvity. I did not type the id in UI layout. button play
Second problem I did not drag the ship.png in explorer window.
Thank you Mr. John Horton. I really appreciate your quick respond.
Well done!
Hey John,
I really like this book. I like how the information is given a little at a time and then the code to go with it. I am currently on the second game 2DPlatformer. I just finished the collision detection section. I noticed that when I push bob into a stack of grass tiles (8 high or so) some times he glitches through. Do you know what would cause that?
Hi Ken,
Thanks very much for your comment. The collision detection is imperfect, however, it should be generally fit-for-purpose. Two things to check/try.
First, make sure that the player is placed as the first item on your text file that is your map layout. This sounds like it shouldn’t be connected but not doing so makes the player character ‘juddery’. Second, make sure to run on a real device, preferably not a low res one.
If you still can’t get a nice smooth action, download the app with the full working game. If it still goes through walls it is the imperfections of the simple system that is at fault. But when testing it seemed fairly sound on devices as low as 800 pixels wide(landscape).
The app is free from here: https://play.google.com/store/apps/details?id=com.gamecodeschool.gcs_app
Thanks again. I would be interested to know your outcome if you have the time.
John,
So I am testing on a physical device (Samsung galaxy 3) I changed the player “p” back to the first position on the text file in LevelCave. This fixed the juttery glitchy reaction but Bob still glitches through sometimes. I checked the app out and he does the same thing on the app. If you hold left into a wall he goes through sometimes. Maybe its my device but I just wanted to make sure it was not an issue with my code. I would like to reiterate again how much I am enjoying your book and how the information is presented. Thank you!
I was just going through your source code file and seen in the collision detection portion in Player class. There is two lines of code commented out under the left and right collision if statements. //setxVolicity(0); //setisPressingRight(false); I added these (unCommented)to my code and it seems to be working alot more consistent.
Thanks Ken,
I forgot all about that option. I will leave this published to help others.
Many thanks again!
Hi, John!
I bought your book. Your book is very informative and useful! But when I made example in your book, I discovered two problems with example opengl.
The first: variable program doesn’t exist in class GLManager. May be I need use next code… int program = buildProgram();???
The Second: variable fragmentShade doesn’t exist in class GLManager but two times vertexShader is defined.
Thanks for your comment. It sounds like the public static variables might be missing? Check all the import statements are there and the shader programs in the right directory. It has been a while since I wrote this code so if this doesn’t help, let me know and I will look in to it more deeply. Thanks for getting my book Nikolay.
Hi mr.Horton i’ve read “Android game programming by example” i successfully built Asteroids but i don’t understand this part of the code:
// And now we can test the rotated point from cp1 against the
// rotated points which form a side from cp2
if (((cp2.currentPoint.y > cp1.currentPoint.y) != (cp2.currentPoint2.y > cp1.currentPoint.y)) &&
(cp1.currentPoint.x < (cp2.currentPoint2.x – cp2.currentPoint2.x) *
(cp1.currentPoint.y – cp2.currentPoint.y) / (cp2.currentPoint2.y – cp2.currentPoint.y) + cp2.currentPoint.x))
numCrosses++;
This is at page 356. I don't understand this part in particular: (cp2.currentPoint2.x – cp2.currentPoint2.x). This make no sense to me because it is always 0.
HI Zhaku,
Toughest question I have had in a while. Unfortunately I don’t have an exact answer. It is nearly two years since I wrote the code/studied it. I think it is a case of converting the formula for intersection of a line, verbatim, and not optimizing the code to remove the parts that were not necessary in this specific scenario. I think you are right, it could be removed or replaced with zero.
Sorry to not give a precise and full answer but hopefully you can be reassured it is me that is the problem, not you.
Thanks,
John
Hi mr.Horton,
I’ve modified the code like this: (cp2.currentPoint.x – cp2.currentPoint2.x) and doing the math it seems to work.
Thanks for the update and pointing out the flaws. I will revisit this code when I update the book.
Hi, I really like your book and have been playing around with the code for the platformer quite a bit.
However, I was wanting to be able to let the user click on gameObjects but I’m having trouble translating from the touch coordinates to the world coordinates. Could you offer any advice on this?
Hi Duncan, this is an interesting problem. The key to the solution lies in the worldToScreen method. Study it and then write a screenToWorld method that does the opposite. You can then get all the screen coordinates of screen taps, convert them to world coordinates and then you can use rectangle intersection to decide if an object has been selected. Thanks for your interesting comment. I hope my answer helps.
I had been looking at doing something like that but hadn’t got it to work but knowing that was the right track and having the directions really helped – thanks!
Thanks Duncan.
Hey,
The book is excellent, and I’ve been recommending it to everyone I know who’s interested in learning android.
I’ve been toying with the TappyDefender game, and attempted to implement some animations for the player and enemies based on the classes used in the platform game. As they seem to use very different methods and classes such as GameObject, I’ve been having some difficulty.
Is it possible to animate the playerShip using the Animation class and implementing in TDView?
Thanks!
Hi AJ,
Thanks very much for your comment and for your recommendations, I really appreciate it. I would try and do things the other way around and integrate space ships, etc, in to the platform engine. The reason for this is that the animation class uses the delta time. I would strip down the platform engine to its bear essentials, including removing all the level classes and loader code. Then add a controlable space ship and add back the tappy defender functionality a bit at a time.
The key to success here is to strip out a bit at a time and then add functionality back a bit at a time, testing each step. Then if you break the code you will only have one step to retrace. This is a really good learning exercise and by the time you are done you will probably have worked out a way to start from scratch and do the whole thing better;-).
Good luck, John.
Hi John im reading the book i found everything really well explained, but i tried to test the game in my cell, the first time i tested it was with the layout and the highscore button , and the second time i tried it said unfortunately the app has stopped, the only error that i found in the android studio log was Error Installing APK, followed by an update of 800mb, but i dont get it because the first code that i tested to see the layout and the button working was ok, but when i entered the other code with the TDView gameactivity and the playership classes, everything look good(excepted for a warning of the catch exception e it says catch block) so im really confused, hope u can help me!! thanks john.
Hi Alberto,
Thanks very much for getting my book. I will try and help you get this working. The easiest way to get running is to paste all the code from the download bundle for the chapter you are currently on. This won’t spoil your personal progress as it only contains the working code up to the end of the chapter.
If you are determined to solve it yourself then this is the tough way but also the most satisfying when you finally solve it. Make sure you are running in debugging mode. Are you connected to your device via USB or are you running a exported APK independent of Android Studio? If the later try the former to get all the necessary error messages. Or, more quickly, run the game on an AVD. The game will run poorly but you will get all the error messages to work out what is going wrong. If the error messages don’t help then post them here along with as much additional information (like exactly where you are in the project) and I will try and help you solve it.
I hope this helps you, get back to me if not and I will try and help further.
Good luck,
John
thanks john i just have one more question is the main activity java in the same project as the game activity,playership and tdview??, i thought main activity was in a seperate project
thanks john!
Pleasure, Alberto, All in the same project.
Hi, I am 243 pages into this 358 page book. Thank you for writing it. Is there a web forum where I can ask questions? Thanks.
Hi Chris,
Thanks for reading my book, nice to hear from you. Feel free to ask any book related questions right here.
well explained in the book, Thank You
Hi John, I’m going to learn how to make games for Android and this looks like a great book to get me started. Just a question: do you use android studio or eclipse for the IDE in the book? If it’s eclipse I might have to get some other book first to help me get familiar with AS (so I can translate the steps in making the game over to AS). Either way I’m getting this book. Cheers in advance
Hi Loren,
Thanks for your message. The book uses Android Studio so hopefully you won’t need any other books. Android Studio has obviously evolved since the book was written but most of the book is about the code rather than Android Studio specific stuff.
Good luck,
John
Hey John,
Thanks for the speedy reply. Awesome! That’s what I was hoping for. I’m right on the verge of finishing up Head First Java, so I’ll be adding Android Game Programming to the top of the stack after that. Cheers again ?
Head First is a great book and just the right level to move on to game programming. Good luck.
Hi John
I’m working on your Bob game. I have the game running but the Number Cipped images = 0. In the Viewport class, the boolean clipped = true is never called. I can’t find where this is meant to be in the book or in the coding samples from the website. Please help. Thanks
Ill add my code at the bottom the first is the View port and the second is from the PlatformView
public boolean clipObjects (float objectX, float objectY, float objectWidth, float objectHeight) {
boolean clipped = true;
//if level1
if (objectX – objectWidth currentViewportWorldCentre.x – (metresToShowX / 2 ));{
//if level3
if (objectY – objectHeight currentViewportWorldCentre.y – (metresToShowY / 2 ));{
clipped = false;
}//End if Level4
}//End if Level3
}//End if Level2
}//End if level1
//For DeBugging purposes
if (clipped){
numClipped++;
}
return clipped;
}//Endo fo clippedObjects =====================================================================
private void update(){
for (GameObject gameObjectUpdate: levelManager.gameObjects){
if(gameObjectUpdate.isActive()){
//Clip anything off screen
if (!viewport.clipObjects(gameObjectUpdate.getWorldLocation().x,
gameObjectUpdate.getWorldLocation().y,
gameObjectUpdate.getWidth(),
gameObjectUpdate.getHeight())){
//Set Visibility flag to true
gameObjectUpdate.setVisible(true);
Hi Tom,
Nice to hear from you.
In the draw method back in the main class the getNumClipped method retrieves the value when debugging is set to true.
// Text for debugging
if (debugging) {
paint.setTextSize(16);
paint.setTextAlign(Paint.Align.LEFT);
paint.setColor(Color.argb(255, 255, 255, 255));
canvas.drawText(“fps:” + fps, 10, 60, paint);
canvas.drawText(“num objects:” +
lm.gameObjects.size(), 10, 80, paint);
canvas.drawText(“num clipped:” +
vp.getNumClipped(), 10, 100, paint);
canvas.drawText(“playerX:” +
lm.gameObjects.get(lm.playerIndex).
getWorldLocation().x,
10, 120, paint);
canvas.drawText(“playerY:” +
lm.gameObjects.get(lm.playerIndex).
getWorldLocation().y,
10, 140, paint);
//for reset the number of clipped objects each frame
vp.resetNumClipped();
}// End if(debugging)
// Unlock and draw the scene
ourHolder.unlockCanvasAndPost(canvas);
Hope this helps,
John.
Hi John
Thank you for getting back to me. I already have the code you suggested:
//Text for debugging
if (debugging){
paint.setTextSize(24);
paint.setTextAlign(Paint.Align.LEFT);
paint.setColor(Color.argb(255,255,255,255));
canvas.drawText(“Frames Per Second: ” + fps, 10, 60, paint);
canvas.drawText(“Number of Objects: ” + levelManager.gameObjects.size(), 10, 80, paint);
canvas.drawText(“Number of Clipped: ” + viewport.getNumClipped(), 10, 100, paint);
canvas.drawText(“Player X: ” + levelManager.gameObjects.get(levelManager.playerIndex).getWorldLocation().x,10,120,paint);
canvas.drawText(“Player Y: ” + levelManager.gameObjects.get(levelManager.playerIndex).getWorldLocation().y,10,140,paint);
canvas.drawText(“Gravity: ” + levelManager.gravity,10,160,paint);
canvas.drawText(“X velocity: ” + levelManager.gameObjects.get(levelManager.playerIndex).getxVelocity(),10,180,paint);
canvas.drawText(“Y velocity: ” + levelManager.gameObjects.get(levelManager.playerIndex).getyVelocity(),10,200,paint);
//for reset numer of clipped objects per frame
viewport.resetNumClipped();
}//End of if debugging
But, when I run the game, the clipped objects is reading as zero (0). I have about 2259 objects on the screen but none of them are clipped. I’m guessing this is why my fps is about 20 when the screen shots in your book have fps at about 90ish.
In my Viewport Class, the boolean clipped = true; is down as being redundant and never used.
Thank you for getting back to me!
Hi Tom,
Sorry for not reading your question correctly. This is odd. When you say “on the screen” do you mean on the level? Anything on the screen(or just off it) wouldn’t be clipped, just the stuff out of site. I have looked at your code and I can’t see any difference to mine which worked when I ran it just now. See pic.
The only thing I can see that is different is that you have named your instances slightly differently viewport instead of vp etc. I would suggest trying a copy & paste from the download bundle starting with the Viewport class. I really can’t see any reason for this.
Try the copy & paste and I would be interested to know if it works.
Thanks.
Hi John,
I figured it out! It was the lack of boolean clipped = true being called. Android Studio said it could be a range of things but the last remark was it can be ‘as simple as a typo’!! So I just copied your sample code into my code and … it worked!!! I don’t know what I missed but finally the boolean was called!
Thank you for your help though! I have to say, I love your books and relish the learning! I also love the challenges you set and figuring out how to improve the basic game you set out! It’s great and certainly makes me think of a career change.
Will you be writing another Game making book for Android Studio? I’d love to know how to make a candy crush style game.
Thank you for your help again!
Hi Tom,
Congrats for solving the problem and thanks for your kind comments.
I will be spending most of 2018 doing second editions. So nothing completely new but I will be updating and adding something new to all my books as well as adding a few more tutorials to this site.
Thanks again!
Hi John.
Thanks for 2 great gooks so far. I purchased “learning java by building android games” first and thoroughly loved it. I read somewhere that this book was a good next step but to be honest, it feels like a step backwards when coding the platformer (no game object factory).
anyway, I havent finished yet so I should hold back my criticism.
a couple of things to note.
firstly, i was struggling to get imageview to work and discovered a good replacement was android:background=”@drawable/background”. hope you canfirm this was a good choice..
next, SoundPool constructor has been depreciated so I was getting all kinds of problems until I discovered the following
soundPool = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? new SoundPool.Builder()
.setMaxStreams(10)
.build() : new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
again, it would be great to hear what you think of this little snippet.
many thanks
Matt
Hi Matt,
Thanks for your comment.
Nice to hear from you. Your code looks good. You could use the sound initialization code from Learning Java by Building Android Games as a guide but I think you have used the virtually same code.
Regarding Android Game Programming by Example, it was a step forward compared to the first edition of LJbBAG but the second edition is twice the size and actually in some ways is more advanced than this book by the end. However, this book in the final project does cover a simple Opengl ES game. Opengl replaces all the Canvas and Paint methods with code that is faster (like hundreds or thousands of fps rather than 60) and therefore is a stepping stone to 3d games.
So hopefully there is still something in it for you.
Thanks again,
John
Also regarding ImageView yes it has changed. It was a mistake for me to use native UI as it changes and evolves really fast and it is not really necessary in a game. I would adapt the home screen from project 1 and use the techniques used in the platformer from LJbBAG second edition.
Cheers.
John, thanks for your replies. I have made OpenGL games in the past when I was learning LWJGL. This project for me was to improve my understanding of Java and to get into Android. so far everything has been great. I also wanted to look into ways of doing powerups and weapons upgrades so I am hoping to enjoy those coming parts.
My ultimate aim is to work out whatever is the next step up for an android device to replace spritesheets and to get a handle on monetization.. do you have any recommendation where I should read ?
thanks again for these amazing books. I highly recommend them for anyone looking to code games for android.
Thanks for the comment Matt I appreciate it. I don’t have any good references for those things specifically but it sounds like you are taking your development seriously and will perhaps be building bigger and more complex games soon. As such I can reccomend http://gameprogrammingpatterns.com/
The website is superb for learning how to manage complexity as our projects evolve. The examples are in C++ but it might still be useful.
Well. I think I have taken the asteroids game to the place I wanted to see it.
Short YouTube video :
https://youtu.be/5lgSzrkiwrQ
Would love to share my code and especially would love your feedback on better ways to do it Mr Horton.
But the changes are quite extensive so feel free to drop me an email and I will gladly send it to you.
Thanks for a truly inspiring book.
Matt
That is a brilliant effect!
Hey, John. I’m reading your book. I really like. I can’t understand one thing on page 120
The method clipObjects() determines whether the object is on the screen or not.
if (objectX – objectWidth
currentViewportWorldCentre.x – (metresToShowX / 2)) {
………………….
I understand the second ” if (objectX + objectWidth …..”, because the object can be located on the left outside the screen, but it is long and therefore will fall on the screen.
But I don’t understand the first “if (objectX – objectWidth…..”.
If the object is located to the right of the screen, then its width does not matter.
It seems to me that it is more correct to write like this:
if (objectX < currentViewportWorldCentre.x + (metresToShowX / 2)) {
And on the Y axis as well.
Or am I wrong?