播放视频和游戏在cocos2dx同一场景 [英] Play video and game in same scene in cocos2dx

查看:112
本文介绍了播放视频和游戏在cocos2dx同一场景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

COCOS2dX主人,我刚开始游戏的开发与COCOS2dX和停留在某个时候。

COCOS2dX masters ,I just started game development with COCOS2dX and stuck at some point.

我被从cocos2dx发展kit.Every事提供的样本学习工作好开发simplegame。

I am developing a simplegame by learning from sample provided by cocos2dx development kit.Every thing is working good.

游戏要求:


  1. 游戏具有单一的屏幕。

  2. 屏幕分为零件。

  3. 屏幕的40%将用于播放视频剪辑。

  4. 屏幕
  5. 60%将用于玩游戏。

我曾与所做的是:


  1. 游戏中工作,并使用整个屏幕。

  2. 能够播放视频它也使用整个屏幕。

我要实现的:


  1. 视频应该是在屏幕的40%,连续播放

  2. 其余部分应该用玩游戏。

总之我需要在单CCScene执行这两个功能

In short I need to perform both the functionality in single "CCScene"

先谢谢您的最佳方案。

推荐答案

这可以通过更改Cocos2dxActivity类libcocos2dx了一下,加了VideoView有实现的。

This can be achieved by changing the Cocos2dxActivity class in libcocos2dx a bit, to add the VideoView there.

首先,这种XML布局添加到RES /布局libcocos2dx:

First of all, add this xml layout to res/layout in libcocos2dx :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <VideoView
        android:id="@+id/video"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="4" />

    <FrameLayout
        android:id="@+id/frame"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="6" >

    </FrameLayout>

</LinearLayout>

此布局将是您的应用程序的新布局。

This layout will be the new layout for your app.

其次,你必须修改的init()方法Cocos2dxActivity这样:

Secondly you have to change the init() method in Cocos2dxActivity to this:

public void init() {

    // Set our new layout as the content view
    setContentView(R.layout.test);

    // FrameLayout
    //ViewGroup.LayoutParams framelayout_params =
    //new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
    //ViewGroup.LayoutParams.FILL_PARENT);
    //FrameLayout framelayout = new FrameLayout(this);
    //framelayout.setLayoutParams(framelayout_params);

    Resources res = this.getResources();
    int id = res.getIdentifier("YOUR_VIDEO_NAME_HERE", "raw", getPackageName());

    if (id == 0) {
        Log.e("Cocos2dx VIDEO", "ERROR! Resource id == 0");
        Log.e("Cocos2dx VIDEO", "ERROR! Check name of video!");
    } else {

        VideoView vv = (VideoView) findViewById(R.id.video);
        MediaController mc = new MediaController(this);
        mc.setAnchorView(vv);
        vv.setMediaController(mc);
        vv.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + id));
        vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mp) {
                if (mp != null)
                    mp.setLooping(true);
            });

        vv.requestFocus();
        vv.start();
    }

    FrameLayout framelayout = (FrameLayout) findViewById(R.id.frame);

    // Cocos2dxEditText layout
    ViewGroup.LayoutParams edittext_layout_params =
        new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                                   ViewGroup.LayoutParams.WRAP_CONTENT);
    Cocos2dxEditText edittext = new Cocos2dxEditText(this);
    edittext.setLayoutParams(edittext_layout_params);

    // ...add to FrameLayout
    framelayout.addView(edittext);

    // Cocos2dxGLSurfaceView
    this.mGLSurfaceView = this.onCreateView();

    // ...add to FrameLayout
    framelayout.addView(this.mGLSurfaceView);

    // Switch to supported OpenGL (ARGB888) mode on emulator
    if (isAndroidEmulator())
       this.mGLSurfaceView.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);

    this.mGLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer());
    this.mGLSurfaceView.setCocos2dxEditText(edittext);

    //// Set framelayout as the content view
    //setContentView(framelayout);
}

这会给你覆盖40%在屏幕的左侧,您科科斯游戏区覆盖60%的权VideView。

This will give you a VideView covering 40% on the left of the screen and your cocos gameplay area covering 60% on the right.

您应该将您的视频在res /原始文件夹中的项目。

You should place your videos in res/raw folder in YOUR project.

此外,这是Android的唯一的解决方案(根据您的问题提供的标记)。要在iOS和其他平台实现这一点,你不得不做出科科斯库code这些平台的其他变化。

Also, this is Android-only solution (based on the tag you provided in the question). To achieve this on iOS or other platforms you'd have to make other changes in cocos library code for these platforms.

编辑:Remeber清洗(以防万一),并重建库

Edit : Remeber to clean (just to be safe) and rebuild the library.

这篇关于播放视频和游戏在cocos2dx同一场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆