Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon
22. January 2016

 

Cocos2D-X, the popular cross platform C++ 2D game library, just released version 3.10.  If you are interested in learning more, I have a full Cocos2D-x tutorial series available here.Cocos2d-x Logo

 

From the release notes:

[HIGHLIGHT] UI: Rewrite Scale9Sprite and improve the scale9sprite performance and reduce memory consumption.

[HIGHLIGHT] UI: Change PageView to derive from ListView.

[NEW] Core: Added Application::getVersion() to get the app version.

[NEW] UI: Add PageView indicator.

[NEW] UI: Label add three Overflow type to new label, see release note for more information.

[NEW] UI: UIText::clone supports clone the text effect.

[NEW] Label: Add methods to query label effect state.

[NEW] UI: UIRichText support the new line element.

[REFINE] 3rd party: WebP loading improvements WebP loaded as premultiplied alpha if it has.

[REFINE] UI: Slider `setCapInsetProgressBarRebderer` change to `setCapInsetProgressBarRenderer`.

[REFINE] UI: RichText support new line element.

[REFINE] UI: Set focus to Widget when touched.

[REFINE] 3D: Change char* to string in Terrain.

[REFINE] Studio: Merge Studio ActionTimeLine change back into engine.

[REFINE] Studio: Merge Studio changes for compatible withe 32bit Mac System.

[REFINE] Studio: Merge Studio changes for lua-binding, js-binding and simulator.

[REFINE] Mac: Make engine compatible for 32bit Mac.

[REFINE] 3rd party: WebP loading improvements WebP loaded as premultiplied alpha if it has.

[REFINE] Audio: AudioEngine on Linux replace the original SimpleAudioEngine with a new version of FMOD, now AudioEngine support all platforms!

[REFINE] IOS: Add virtual keyword for some render related function.

[REFINE] UI: Fixes boring deprecated warning in HttpRequest.

[REFINE] Network: Fix Downloader bug on iOS & Android platform.

[REFINE] Studio: Fix deprecation warning in SkeletonRenderer.

[REFINE] JS: Add js test case for fix, improve template.

[REFINE] Network: Permit http access to cocos2d-x.org in test projects on iOS.

[REFINE] Network: Crash when removing a remotely downloaded image from texture cache in js-binding.

[REFINE] Win10: WinRT project update version to v3.10.

[REFINE] Console: Add quiet option for Cocos Toolkit.

[REFINE] JS: New GC model for js-binding.

[REFINE] Doc: Fix typos in documentation and comments.

[REFINE] UI: update controlButton size calculate with new Scale9Sprite logic.

[REFINE] Win10: Added missing _USRJSSTATIC preprocessor define for ARM builds.

[REFINE] JS: Added ccvector_to / ccmap_to converted to new js-binding API.

[REFINE] UI: Slider misprint fix.

[FIX] Network: fix possible websocket crash in its destructor.

[FIX] Core: Fix premultiplyAlpha for mipmaps and compressed textures.

[FIX] UI: Fix Scale9sprite rendering error when content size smaller than the sum of leftInset and rightInset.

[FIX] Win32: Fix EditBox crash when removing an EditBox in a scheduler.

[FIX] Android: Fix cannot add view to mFrameLayout when extends Cocos2dxActivity.

[FIX] 2D: Fixed actionNode set at wrong position bug.

[FIX] 3D: Fix the movement of PUParticle lags one frame.

[FIX] UI: Fix the wront argument of setPlaceholderFontName in EditBox.

[FIX] UI: Fix EditBox editBoxEditingDidEnd may use the original text after change the text of EditBox in user script.

[FIX] Audio: Fix `FinishCallback` never be called in Windows.

[FIX] UI: Fix Layout stencil clipping nested with Clipping Node rendering issue.

[FIX] UI: Keyboard doesn't hide when click the screen outside of EditBox on iOS platform.

[FIX] UI: Fix a fatal bug in EditBox implement on Windows platform.

[FIX] UI: Fix edit box setPlaceholderFontName and scale font size issue.

[FIX] Core: Fix memory leak when initWithImage() failed.

[FIX] Network: CCDownloader on iOS is broken in v3.9 js-binding.

[FIX] JS: Bindings fixes for Menu, Sprite and Label.

[FIX] Studio: Remove weak reference in ActionNode.

[FIX] UI: shouldStartLoading method should return value to js in js-binding.

[FIX] UI: Fix scrollview render error.

[FIX] JS: Fix win32 js project crash issue.

[FIX] UI: Button touch doesn't work with scale9 enabled.

[FIX] JS: Fix evalString doesn't return result issue.

[FIX] JS: Fix ComponentJS proxy management issue in JSB.

[FIX] Android: Fix include in cocos network module.

[FIX] Network: Fix web socket crash.

[FIX] UI: Fix TextField missing default password style text setting.

[TEST] S9SpriteTest: Scale9Sprite fade actions with cascade opacity.

[TEST] Web: Remove default focus block from UIFocusTestVertical.

[TEST] Lua: Fix pageViewTest Horizontal scroll won't work in Lua-test.

 

Cocos2d-x can be downloaded here.

GameDev News ,

18. January 2016

 

I just published this up to Youtube, but figured I would share it here as well.  I have long held that C++ isn’t a great choice as a first programming language.  This video is an attempt to illustrate why, including the same simple task in three different languages, C++, C# and Lua/Love.

Again, I don't think learning C++ is a bad idea, it's a very good idea. It's just starting with C++ that I believe is a mistake. If you are completely new to programming and want to know why I personally recommend against starting with C++, I recommend you watch this. Of course, you can start with C++... it's not going to harm you and it very much can work. I just think you would be more effecient using another language first.

Programming

1. January 2016

 

When I set up the news monitoring on GameFromScratch.com I noticed that Ogre3D hadn’t had an update since June and was somewhat concerned that the project was dying off.  Thankfully today there were signs of life over at ogre3d.org.  If you have never heard of it, Ogre3D is a C++ based renderer and scene graph and has been used to create several shipped titles.  The major challenge to Ogre3D is that it is currently Windows and Linux only.

 

From the update:

So… what’s new?

1. Added TagPoints to the new Skeleton system! This has been a sort of unfinished business for me. I’m glad it’s finally done!

2.1’s TagPoints are superior to their 1.x counterparts. The TagPoints from v1.x had many issues: they didn’t follow RenderQueue, visibility rules, nor LOD rules correctly (they were subordinated to the settings from the main entity/skeleton they were attached to). The v1 TagPoints also belonged to an Entity. If the Entity was destroyed, it took down its TagPoints with it. Meaning if you wanted to still keep the attachments, you had to iterate through them, detach them from their TagPoints, and add them to a new SceneNode. Ugh!!! Personally, I gave up trying to use those in my projects a long time ago.

In Ogre 2.1; TagPoints are much better: they are exactly like regular SceneNodes, except they occupy a little more RAM (a few more bytes per node), and can be attached to Bones. Other than RAM consumption, there is no performance penalty for replacing SceneNodes with TagPoints (*).

You can make a TagPoint child of a SceneNode, a SceneNode child of a TagPoint, and a TagPoint child of another TagPoint. The only thing you can’t do is make a SceneNode child of a Bone. You must use a TagPoint for that.

If you want, you can use TagPoints throughout your entire codebase and forget about having to deal with whether an Item/Entity was attached to a TagPoint or a SceneNode and get downcasts correctly.

(*)When a SceneNode or TagPoint is attached to a TagPoint that is child of a Bone, the performance is slower because these nodes need to support non-uniform scaling. But if the TagPoint is child of the Root SceneNode (instead of a bone) like all regular SceneNodes, then there’s no performance penalty.


2. Added PSOs (Pipeline State Objects). This brings us one step closer to Vulkan, DX12 and Metal support. We’ve also noticed some minor performance improvements since there are less hoops now when tying shaders with input layouts in the D3D11 RenderSystem. Overall it simplified our workflow. It also fixed a rare culling winding bug in GL3+ as a nice side-effect.

This work is in the branch 2.1-pso. It’s ready. It hasn’t been merged yet back to main 2.1 branch because I am waiting to test it on a big engine (since it was a big change) in case there are edge cases to fix.


3. Added alpha tested shadows and transparency to PBS! These have requested by many. Alpha tested shadows are useful for grids, leaves and other alpha tested objects.

We offer two transparency modes: Transparent and Fade. The former is physically based and still emits some specular light even at alpha = 0; the latter is good old alpha blending; and becomes invisible when alpha = 0.

 


4. Added Metallic and Specular workflow options. We’ve been working hard and closely with other teams and artists, tuning the BRDF settings. We now have 3 workflows: specular_ogre, specular_as_fresnel (what most popular engines do when they say “specular” workflow) and metallic.

For the tech-curious, specular_ogre maps the specular texture to the coefficient “kS”, whereas specular_as_fresnel maps the specular texture to the fresnel, colouring it. And metallic uses the slot reserved for the specular texture to control the metallness.

John Hable has an interesting discussion about the topic. Long story short specular_ogre allows more variety in the amount of materials that can be represented; but the specular_as_fresnel is more intuitive and is what most artists are used to.


5. Optimized vertex buffers for shadow mapping! If you’ve got VRAM to spare, you may want to enable this option to generate vertex buffers optimized specifically for shadow mapping.

Normally, GPUs require us to split a vertex when two triangles can’t share it (i.e. it has a different normal, it has got an UV seam, etc). But shadow mapping only requires position, and these cloned vertices (alongside fatter vertices) reduce performance unnecessarily. This new feature creates a vertex buffer with position data exclusively, thus reducing bandwidth requirements, fitting the cache better; and reducing the vertex count by avoiding duplicates.

Performance improvements vary wildly depending on scene and model complexity.

To enable it, set the global variables:

Mesh::msOptimizeForShadowMapping = true;
v1::Mesh::msOptimizeForShadowMapping = true;

Note that this will increase loading times. For large meshes (i.e. 300k vertices), it is better to do it offline and save it to disk using the OgreMeshTool. If you do this, then there is no need to set msOptimizeForShadowMapping to true.

Also bare in mind this optimization will not be used for meshes using materials with alpha testing, as we require UV data for alpha testing; and not just position data.

For more information, visit the forum thread.


6. Updated and merged OgreMeshUpgrader and OgreXMLConverter into one tool: OgreMeshTool. This new tool supports many similar options and most of the same functionality the other two provided; with the addition of new v2.1 features like exporting to v2 formats, optimizing vertex formats to use half floating point and QTangents, generate optimized vertex buffers for shadow mapping.


7. Compositor improvements. Finished UAV (texture) support, finished resource transition/barriers project (needed by OpenGL, Vulkan and D3D12) see what are barriers and why they are needed, Compositor now allows for rendering to 3D and texture 2D arrays, also declaring cubemaps.

Automatic generation of mipmaps was added for RTTs (useful for cubemap probes). See section 4.1.3.2 generate_mipmaps from the porting manual for more information.

With proper UAV support, compute shaders are around the corner!


8. Added JSON materials. The previous script syntax was not scaling well. JSON rocks! Drop on the forum thread for more details. It was our latest addition so there may still be things to polish. The old hlms material script system will continue to work while we iron out the issues and finish DERGO as a material editor.

GameDev News , ,

30. December 2015

 

GarageGames have just released Torque2D version 3.2.  Torque2D is 2D game engine built over the Torque 3D engine, which is now open source and MIT licensed.

From the release:

While you were singing carols door to door and sipping eggnog by the fireplace, the T2D Steering Committee was hard at work wrapping up one last present! Presenting Torque2D 3.2! This latest incarnation of everybody's favorite 2D engine sports several shiny new features! But before we get into that, let's take a moment of silence to remember the many bugs that lost their lives to make this release possible.


Now then, our first new feature is the FadeTo function. This works like MoveTo except that it changes the blend color over time instead of the position. If you ever wanted to fade a bad guy out when it died or fade a slightly transparent object in, then this function was written for you! It could be used to make your hero flash red when his life is low or slowly change the color of the sky as the sunsets. FadeTo comes with all the support functions of MoveTo including a cancel function and callback when it's finished.


We also added GrowTo which changes the size of an object over time. With GrowTo you can change the x and y at different rates and create all kinds of neat effects. But, there's a catch! Collision shapes don't grow with the sprite. So if your object has collision shapes attached you'll want to use it sparingly. Slight changes can do a lot. Like FadeTo, GrowTo is supported by functions to test and cancel. When an object reaches its target size it will fire a callback.
We also have support now for one way collisions. This is most commonly seen in platformer games when a character jumps up through the platform and magically lands on top of it, but in theory there's many other uses for it. This only works for edge and chain collision shapes.
And finally, last but not least, we have revived ogg! That's right! The open source, compact audio format is back by popular demand. You can start using ogg files again on Windows and Mac OSX.

GameDev News, Programming , ,

23. November 2015

 

 

In this tutorial we are going to look at audio programming in Cocos2d-x.  We will look at playing music and sound effects using SimpleAudioEngine, one of two engines built into Cocos2d-x.  There is a second, newer, more commplex and experimental audio engine AudioEngine, that we will discuss later.  Let’s start straight away by playing some music.  To make use of SimpleAudioEngine we need to add an additional include call:

#include "SimpleAudioEngine.h"

 

Next we need a song of some sorts to play, simply copy an appropriate file into your resources folder.  Myself I used an mp3 file named creatively enough song.mp3.

Supported Audio File Formats


The audio formats supported by Cocos2D-x depend entirely on what platform you run on.  The primary thing to be aware of is the ogg format is the preferred music format on Android platforms, while it is completely unsupported on iOS, which prefers MP3.

You should be aware that the MP3 format is patent encumbered format and generally should be avoided when possible.  If your app reaches certain sales thresholds, you may be required to pay license fees.  Sadly this generally isn’t an option on iOS devices as MP3 is the primary audio format used.  For sound effects, WAV are commonly used offering quick playback ability at the cost of file size.  Here are the details of supported audio files on iOS

Time now for some coding.  Implement the following init() method:

bool HelloWorld::init()
{
   if (!Layer::init())
      return false;

   auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
   audio->preloadBackgroundMusic("song.mp3");
   audio->playBackgroundMusic("song.mp3");

   return true;
}

That is all that is required to load and play a music file. In fact the preloadBackgroundMusic() call wasn't even required so we could have used even less code. However preloading your music guarantees that you will not suffer a slow down the first time a song plays. You can also pause and resume playback of background music, or switch tracks completely, like so:

   eventListener->onKeyPressed = [audio](EventKeyboard::KeyCode keyCode, Event* event) {

      switch (keyCode) {
         case EventKeyboard::KeyCode::KEY_SPACE:
            if (audio->isBackgroundMusicPlaying())
               audio->pauseBackgroundMusic();
            else
               audio->resumeBackgroundMusic();
            break;

         case EventKeyboard::KeyCode::KEY_RIGHT_ARROW:
            audio->playBackgroundMusic("song2.mp3");
            break;

         case EventKeyboard::KeyCode::KEY_LEFT_ARROW:
            audio->playBackgroundMusic("song.mp3");
            break;
      }
   };

   _eventDispatcher->addEventListenerWithFixedPriority(eventListener, 2);

Hitting the spacebar will toggle the playback of the currently playing song.  Hitting the right arrow will start playing (or start over if already playing) song2.mp3. Hitting the left arrow will start or re-start playback of song.mp3.  You will notice from this example that only one song can be played at a time.  Generally this isn’t a limitation as it is normal to only have one active sound track at a time. 

setBackgroundMusicVolume() doesn't work!


A bit of a warning, at least on Windows, calling setBackgroundMusicVolume() does nothing, making it impossible to change the volume of a playing music file. This may not be the case on other platforms, I did not test. It was filed as a bug a long time back and does not appear to have been addressed.

 

Now let's look at playing sound effects instead.  Playing music and effects is almost identical.  The biggest difference is that sound effects are expected to support multiple concurrent instances.  That is to say, while you can only play one song at a time, you can play multiple sound effects at once. Consider this sample:

bool HelloWorld::init()
{
   if (!Layer::init())
      return false;

   auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
   
   audio->preloadEffect("gun-cocking-01.wav");
   audio->preloadEffect("gun-shot-01.wav");

   audio->playEffect("gun-cocking-01.wav");

   Director::getInstance()->getScheduler()->schedule([audio](float delta) {
      audio->playEffect("gun-gunshot-01.wav");
      audio->unloadEffect("gun-cocking-01.wav");
   }, this, 1.5f, 0, 0.0f, false, "myCallbackKey");

   return true;
}

 

In this example we preload two WAV sound effects, a gun cocking and a gun shot.  Playing a sound effect is as simple as calling playEffect() passing in the file name.  Of course, be certain to copy the appropriate sound files to your project’s resource folder before running this example.  Next this example queues up a lambda method to be called 1.5 seconds of the gun cocking sound is played to play our gun shot sound.  At this point we are done with our gun cocking effect so we unload it from memory using unloadEffect().  You can still call playEffect with that file in the future, but it will result in the file being loaded again.

 

This example might be somewhat convoluted, but it illustrates and works around a key weakness in the CocosDenshion audio library.  It is a very simple and straight forward library but if you want to do “advanced” things like detecting when a song or audio effect has ended, unfortunately this functionality is not available.  You either have to use the experimental AudioEngine, which we will cover later, or use an external audio library such as FMOD.  SimpleAudioEngine is extremely easy to use, but not very powerful, so it’s certainly a trade off.  If you just need background music and fire and forget sound effects SimpleAudioEngine should be just fine for you.

 

One final topic to cover is handling when your app is minimized or forced into the background, you most certainly want to stop audio playback.  This is thankfully easily accomplished in your AppDelegate there are a pair of methods, applicationDidEnterBackground() and applicationWillEnterForeground().  Simply add the following code:

void AppDelegate::applicationDidEnterBackground() {
   auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
   audio->pauseAllEffects();
   audio->pauseBackgroundMusic();
}

void AppDelegate::applicationWillEnterForeground() {
   auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
   audio->resumeAllEffects();
   audio->resumeBackgroundMusic();
}

 

This will cause all of your currently playing sound effects and music files to be paused when your application enters the background and they will all result when your application regains focus.

Programming , ,

 

Month List

Popular Comments