My first cocos2d-x game is finally live on AppStore, here is the link: https://itunes.apple.com/us/app/lemonade-jack/id892275639?ls=1&mt=8
It is also Open Source, if you wish to learn how it is made please check out github: https://github.com/dkstar88/lemonade-jack
For the past few month I have been learning and coding using Xcode in Objective-C and C++.
Here are the result:
It is a food suggestions app based on 24 chinese solar terms.
Apart from objective-c, I have also been learning and working on c++, using cocos2d-x making a lemonade stand game. So far I have touched plist configuration, cocos2d-ui, Game Center Leaderboard, Achievements, In-App purchases (using soomla), animation, sound, many areas I never tried on.
Right now its in the finishing stages.
For those who wants to learn cocos2d-x, I have posted all source up to date.
In my current application I have some images I need to add a glow effect on the image and convert it to an Windows icon.
The conventional way would be add a TImage with a TGlowEffect child control, and using MakeScreenshot to capture the result image. But I found this is not possible at least TGlowEffect do not work (or any other effects) when the control is not visible.
The problem lead me to dig into FMX.Effects, FMX.Filter and FMX.Filter.Custom. This is what I found.
- Filters code are in FMX.Filter.Custom, TGlowFilter, TInnerGlowFilter, etc.
- They are registered to TFilterManager
- TGlowEffect component and other effect components uses TFilterManager to work
- Filter’s parameter can be set using ValueAsFloat, and ValueAsBitmap etc as long as you know the key string, e.g. ValuesAsFloat['BlurAmount'] := FSoftness
Here is my code using GlowFilter manually. Call GlowFilter.ApplyWithoutCopyToOutput will render a new image with the effect only, and I manually render the original image on top of it to make the actually resulted image.
with TFilterManager.FilterByName('GlowFilter') do
ValuesAsFloat['BlurAmount'] := 0.2;
ValuesAsColor['Color'] := $FFFFFFFF;
ValuesAsBitmap['Input'] := icon;
TFilterManager.FilterContext.CopyToBitmap(icon2, Rect(0, 0, icon2.Width, icon2.Height));
icon2.Canvas.DrawBitmap(icon, RectF(0, 0, icon.Width, icon.Height),
When I tried to make a a simple game for Android using Delphi XE5, I encountered an problem using TBitmap in threads. When ever I use TBitmap in thread it just causes the App to quit back to the Launcher screeen. Delphi doesn’t catch any exceptions.
In order to find out what the problem was, and to isolate the problem. I created a test project with 3 threads.
- loads a jpeg from file
- only creates 100×100 bitmap
- on top of (2), calls FillRect
This is what test project UI look like. Each button calls each thread.
This is the result from Logcat. I pressed buttons from bottom up (since I knew which one fails). The result is very interesting.
Thread 3: Thread executed from start to finish, but paint failed with “Cannot create render buffers from TContextAndroid” exception.
Thread 2: No exceptions
Thread 1: It caused the app to quit, it obviously failed. But looking at the log. I can see the thread actually ran from start to finish. There were no exceptions in the middle. Two exceptions were raised after the thread operation.
“10-15 11:51:25.283: I/info(1159): FMX: Project5: [Context Exception]: Cannot create OpenGL context for ‘CreateDummyContext’.
10-15 11:51:25.283: I/info(1159): FMX: Project5: [Context Exception]: Cannot create OpenGL context for ‘eglMakeCurrent’.”
For anyone wants to investigate this problem further, or just to try it out, here is the source code. threadtest.7z
(I first post this problem on stackoverflow.com)
TDiskCache is a easy use local cache manager, stores data in a specified storage folder, all stored files are
stored in a flat dir structure, no sub folders, filenames are hashed using md5.
In the root folder, a hidden file “cache.ini” will be created to store cache time, and other data.
Full Source: https://gist.github.com/dkstar88/6129742
It requires HashUtil.pas, which can be also found at Gist.
If you ever tried to use MD5 or SHA hash function came with Indy library, especially when you want to make a cross platform application using FireMonkey. You are pretty much locked to Indy, there may be many other better options, I only found Indy to be cross platform so far.
In Indy, to get a MD5 from a string, you need to do:
with TIdHashMessageDigest5.Create do
Result := HashStringAsHex(S);
Not too complicated, but it become obvious to create a wrapper function if you have lots of places needs md5 hashes.
So it becomes
function MD5(S: String): String;
with TIdHashMessageDigest5.Create do
Result := HashStringAsHex(S);
lMd5 = MD5('string to hash');
Full source can be found at gist.
A generic Version structure utilizing operator override feature in Delphi versions.
Currently it supports comparison, and not so useful addition and substraction.
Now you can do
TVersion('184.108.40.206') > TVersion('220.127.116.11')
I also put AppVersion, which returns the version of your running application for both Windows and MacOS. So checking where if the current running app is the latest version.
// get LatestVersion info from the net
if (LatestVersion > AppVersion) then
// Pull latest version from the net
A ImageLoader for FireMonkey TImage component. I written this when I found I need to load a few images from the Internet. Obviously delphi isn’s browser, if I just call download using Indy it will just block my app’s UI.
ImageLoader is very simple class with a loading queue, and a timer to trigger the work on the queue. You just need to call the LoadImage from TImageLoader, you don’t even need to create TImageLoader there is a default “DefaultImageLoader” already created on unit initialization. A simple cache machanism is also there to prevent waste of bandwidth.
Right now, ImageLoader only loads the image for TImage, it doesn’t fire any event when the image is ready, so post processing is not available. That will be added in the future. Ajax waiting animation will be added as option.
TWebLabel is recently added graphix component pack for FireMonkey. I was looking for a a URL label component and found TUrlLabel from monkeystyler.com.
But it doesn’t have a dedicated field to store URL, it treat text as url link. Thankfully the source code is there.
I made many changes to the orignal code.
- Added TFontTextSettings – TTextSettings with Font and FontColor exposed as published properties
- Added FontNormal, FontHover, FontDown property to change label appearance on different mouse state
- Added a dedicated attribute to store url
- Changed parent object to TText rather than TLabel
TWebLabel added to graphix FireMonkey component package, opens URL in system’s Internet browser with full Mouse Hover, Mouse Down effect.
Download code at http://github.com/dkstar88/graphix