Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Chat / [STICKY] AppGameKit for Java & Kotlin

Author
Message
Hockeykid
DBPro Tool Maker
10
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 3rd Jul 2018 22:41 Edited at: 3rd Jul 2018 22:44
App Game Kit for Java and Kotlin is here!

Now you can utilize the power of App Game Kit with the flexibility of Java or Kotlin. Java/Kotlin offer the perfect alternative to Tier 1 due to the simple yet very powerful and versatile syntax.

Here a just a few of the Benefits
Object Oriented Programming
Java & Kotlin are built around OOP using modern and well known concepts such as Classes, Interfaces, Inheritance, etc. These allow for clean, elegant, and organized code that is both reusable and extensible
Vast Libraries
Java & Kotlin have a wide range of both 1st party and 3rd party libraries that can add lots of functionality from basic Data Structures (Queues, Linked Lists, HashMaps, etc) all the way to libraries for Gesture Recognition, Digital Signal Processing, etc.
User Interface
Want to make a desktop tool in AppGameKit? Kotlin & Java have plenty of different libraries for UI like JavaFX, AWT, or Java Swing which will work alongside AGK.

Supported Platforms
Windows
Linux

Future Platforms
Mac OSX
Android

Getting Started
To use AppGameKit for Java or Kotlin you will need the following:
Java Development Kit
The latest version of the JDK can be downloaded here: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Your Favorite Java IDE
Java & Kotlin have tons of Integrated Development Environment (IDEs) avaliable and you can use whichever one you want

Below are two recommendations
Netbeans (Simple and full-featured Java IDE): https://netbeans.org/downloads/

Intellij (Best for Kotlin, works for Java too): https://www.jetbrains.com/idea/download/

Once you have downloaded and installed the JDK and your IDE of choice you can download the ZIP file attached to this post. The ZIP file contains mainly 3 things:
AGK for Java Examples
AGK for Java Template
AGK for Kotlin Template


Using The Templates
Once you have unzipped the provided ZIP file, there will be two folders: NetBeansProjects and IntelliJ projects (If you are using a different Java IDE then converting the templates should be simple). Each of these folders contain a "JavaTemplate" (the IntelliJ folder also includes "KotlinTemplate").

Open the JavaTemplate in either NetBeans or IntelliJ. Inside of the "src/main" folder you will find "AGKMain.java" This is where your code will go (ignore the "com/thegamecreators/agk" folder).

You should see the following methods:

public void begin()

This is where all the code to setup your app should go. Things like Loading images, creating sprites, sounds, resolution, etc

public void loop()

This is your main loop. Every frame, AppGameKit Java will call this loop() method and execute the code inside of it (which is why the template has AGKLib.Sync() in here).

public void complete()

This will be called when the application has been asked to close (user clicks the X on the window or maybe the OS asks the application to close). This is where you should cleanup all of your resources.

How to Call AppGameKit Functions
Calling AppGameKit functions is simple take any AppGameKit Function and prepend "AGKLib." to the front. For example AGKLib.CreateSprite(5) or AGKLib.LoadImage("Test.png") or AGKLib.CreateSprite(AGKLib.LoadImage(AGKLib.toAGKPath("Test.png"))) the only thing to note is that the case of the AppGameKit function does matter and must match the casing in the AppGameKit Documentation (https://www.appgamekit.com/documentation/search.html). Trying something like AGKLib.createsprite will not work.

The only caveat is when loading a resource file such as an image, sound, etc. You must call AGKLib.toAGKPath("myFile.png") first to convert the file path to one that will work with AGK. For example:

AGKLib.LoadImage(AGKLib.toAGKPath("Test.png"))

or

AGKLib.LoadSound(AGKLib.toAGKPath("chirp.wav"))


Testing the Template

Inside of the "loop()" method if you add: AGKLib.Print("Hello World") then go to the top of your IDE and hit "Run > Run Project" the project should run and you should see your "Hello World" message on the screen along with the "Screen FPS"


Example Code

Below is AGK's "3D-FirstPersonExample" converted to Java line by line (so not taking advantage of Java's powerful syntax):



Attachments

Login to view attachments
Tumira
2
Years of Service
User Offline
Joined: 28th Oct 2015
Location:
Posted: 4th Jul 2018 07:19
Can we use android studio and openjdk with this ? Without installing Java sdk?
Hockeykid
DBPro Tool Maker
10
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 4th Jul 2018 07:35
Quote: "Can we use android studio "


If you can setup a normal desktop Java project in Android Studio (I think you can) then yes, that will work. Or you could get IntelliJ if you want which is the IDE that Android Studio is based on.

Quote: "openjdk with this "


Yes, OpenJDK will work



Sean
Phaelax
DBPro Master
15
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Jul 2018 13:35
I'll check this out soon as I get a chance, probably with netbeans.

Why didn't you just call the begin() function main() instead? For java folks that just makes sense.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
krid
3
Years of Service
User Offline
Joined: 2nd Dec 2014
Location: Almaty / Kazakhstan
Posted: 4th Jul 2018 18:27
Guys! This is huge update! I was strugling with my UI lib, which is fully written in basic, and now you release this?! Awesome!

I have few questions:
1) Is everything works in a same way as if I wrote that code in basic? (I mean speed, bugs etc)
2) Is this kind *experiment release or it will be fully supported and I can switch to Java? (talking about longterm, bugs and news features , etc)
Hockeykid
DBPro Tool Maker
10
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 4th Jul 2018 19:36
Quote: "Why didn't you just call the begin() function main() instead? "


I was trying to keep consistent with Tier 2 naming (though "complete" is different)

Quote: "For java folks that just makes sense."


I wouldn't want AppGameKit Tier 1 users to try and write a persistent loop in the begin/main method.

Quote: "Is everything works in a same way as if I wrote that code in basic?"


Yes everything except speed. While I haven't done benchmarks, Java Virtual Machine is likely faster than AppGameKit Basic.

Quote: "s this kind *experiment release or it will be fully supported and I can switch to Java? "


It will be fully supported by me. But at the moment the agreement I have with TGC is that I use AppGameKit version 2018.06.22 so we are locked into that. Also keep in mind the supported platforms are different than AppGameKit Basic.


Sean
Hopelessdecoy
2
Years of Service
User Offline
Joined: 17th Apr 2016
Location:
Posted: 5th Jul 2018 01:57
Any way we could get an eclipse template version too? Not that I want to ask for too much more this is awesome!
KultiVator
3
Years of Service
User Offline
Joined: 2nd Jan 2015
Location: Sunny Northamptonshire
Posted: 5th Jul 2018 10:47 Edited at: 5th Jul 2018 10:58
Very interesting development... may I ask if we can use Kotlin to target Windows / Android / LLVM / etc from the same source code (e.g. in projects without any platform-specific stuff going on) ?

Best Regards,



Jon
( Aggravated > Constipated > Mutilated ) < KultiVated
Hockeykid
DBPro Tool Maker
10
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 6th Jul 2018 00:03
Update

Attached to the first post is a new ZIP with the correct libraries for Linux (accidentally included old non-functional Linux libraries).

Quote: "Any way we could get an eclipse template version too? Not that I want to ask for too much more this is awesome!"


I'm trying to avoid having a template for too many IDEs. It should be very simple to create an Eclipse template. Simply create a new Eclipse project, and then go into the Netbeans Template and copy the agk64.dll, libagk64.so (just updated the ZIP on the first post), the "src" folder, and the "media" folder into your new Eclipse project and it should all work.


Quote: "may I ask if we can use Kotlin to target Windows / Android / LLVM / etc from the same source code"


Yes, for all platforms you should be able to use the same source code. For all desktop targets you could even use all of Java's "platform" commands (like file access, Java FX, etc). Keep in mind this is Kotlin running under the JVM so you won't be able to target LLVM.


Sean
nonom
User Offline
Joined: 12th Nov 2017
Location: Spain
Posted: 7th Jul 2018 11:49
Pretty interesting work congrats, It works for me

https://i.imgur.com/Nb51qxB.jpg
http://www.nyan.cat/pirate
Alebrije
5
Years of Service
User Offline
Joined: 27th May 2013
Location: Toluca
Posted: 8th Jul 2018 06:40
I successfully created the typical Hello World using Eclipse. I had to do minor changes but it works as expected. Great addition.
Classics games, modern wonders
rongzhilee
User Offline
Joined: 10th Jul 2018
Location:
Posted: 10th Jul 2018 23:57
Great!!!!!!!
ghostek
User Offline
Joined: 6th Jul 2018
Location:
Posted: 11th Jul 2018 09:26
So this is your c++ wrapper over API and exposed to java? If I am corret with this it will be possible to create c# wrapper using same technique, even calling methods from your library
Hockeykid
DBPro Tool Maker
10
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 12th Jul 2018 02:24
Quote: "If I am corret with this it will be possible to create c# wrapper using same technique,"


This already exists, MadBit created AGKSharp which you can find here: https://forum.thegamecreators.com/thread/222274
sarahjones
User Banned
Posted: 30th Jul 2018 20:58
I'm also looking foe AppGameKit for JAVA, but I couldn't find it when I searched it on Hotmail Support. If anybody has any suggestion, please let me know here.
THE_NOTORIOUS_PIGGY
2
Years of Service
User Offline
Joined: 17th Jun 2016
Location:
Posted: 31st Jul 2018 18:10
In college I am currently studying java, so this is an excellent alternative! Might switch from tier 1 to this java. Excellent work @hockeyKid, I hope that thegamecreators incorporate this as a full feature!
BenKenobi
User Offline
Joined: 11th Aug 2018
Location:
Posted: 12th Aug 2018 01:17 Edited at: 13th Aug 2018 19:17
First of all this is great, i started a new project in AppGameKit after hearing this got released and everything seems to running well, except that theres one problem, AGKLib.SetAntialiasMode( 1 ); doesn't seem to do anything.

This happened before with tier 2 C++ https://forum.thegamecreators.com/thread/217522. Unfortunately without anti aliasing 3D is of not much use to me. Im not sure how I am able to fix this with Java.

EDIT: found out the problem persists when compiling with C++

just needed to add the following line to 'cpp_library_folder/apps/template/Core.cpp'
glfwWindowHint(GLFW_SAMPLES,16);

you may want to recompile the library files with the anti aliasing enabled.

Login to post a reply

Server time is: 2018-08-14 10:18:59
Your offset time is: 2018-08-14 10:18:59