Book Image

Cocos2d-x Cookbook

By : Akihiro Matsuura
Book Image

Cocos2d-x Cookbook

By: Akihiro Matsuura

Overview of this book

Table of Contents (18 chapters)
Cocos2d-x Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Playing movies


You might want to play a movie in your game in order to enrich the representation. Cocos2d-x provides a VideoPlayer class for this purpose. This class makes it easy to play a movie; however, it is still an experimental class. So, you have to be very careful while using it.

Getting ready

You have to prepare something before using the VideoPlayer class.

  1. You have to add the movie file to the Resources/res folder. In this case, we add the video called splash.mp4.

  2. Next, you have to including a header file. The code to do so is as follows:

    #include "ui/CocosGUI.h"
    USING_NS_CC;
    using namespace experimental::ui;
  3. Then, you have to add the following code to the proj.android/jni/Android.mk file for building an Android application.

    LOCAL_WHOLE_STATIC_LIBRARIES += cocos_ui_static
    $(call import-module,ui)
  4. In Xcode, you have to add MediaPlayer.framework for iOS, as shown in the following image:

How to do it...

Let's try to play the video in your game. Here, it is:

auto visibleSize = Director::getInstance...