很多游戏都是这样的,要将主角放在屏幕中间,无论主角怎样移动。
屏幕都是以主角为中心的。
我在网上查了资料,发现CCFollow可以实现这个功能。
用法相当简单,就一句话:
layer->runAction(CCFollow::actionWithTarget(hero));
其中layer是你需要移动的层,hero是屏幕需要跟随的精灵。
将这条语句放置在update方法中。就可以实现屏幕跟随主角移动了。
4楼MoonAgent昨天 18:01void GameLayer::step(ccTime dt)n{nt//屏幕跟随ntgameWorld->runAction(CCFollow::actionWithTarget(flight)); n}nn基本上解决了,放在这里就可以了,可见关键不是update,而是(ccTime dt)。 但是现在的问题是视角跟随之后···会逃离背景,也就是说会看到背景之外的东西。nn实际测试了一下这个方案不适合我现在做的游戏。不过谢谢了。对了,你对滚屏有研究吗?Re: weyson昨天 21:39回复MoonAgentn还没有研究滚屏,你可以使用一个大些的背景图片来遮盖后面的黑色区域。3楼MoonAgent3天前 08:23你好,这个layer怎么弄啊?新建一个层??nn问实际点就是如何让背景移动。Re: weyson昨天 15:17回复MoonAgentn其实就是你的游戏层。根据你的实际情况来确定。如果想让你的背景移动,那这个layer肯定就是你背景所在的层。不想随着移动的东西就放在其他层里。2楼autumnwinter4天前 15:10cocos2d-x tests工程中 ActionTest.cpp 倒数第7行(1.0-0.13) this->runAction(CCFollow::actionWithTarget(m_grossini, CCRectMake(0, 0, s.width * 2 - 100, s.height)));nn使用一个rect,这样就不会移出背景层了,当然,在移以边缘的时候,精灵是不在中央的..Re: weyson3天前 17:20回复autumnwintern没错,n我也长见识了。1楼MoonAgent4天前 12:07我也是这么理解的,但是···好吧,可能有点···。但是能否教我一下如何创建层并把背景放入···Re: weyson4天前 12:51回复MoonAgentn你可以去cn.cocos2d-x.org的论坛看一下教程。我记得好像有。
Qt4.7.3交叉编译移植
作者:风竹郎 2012-07-26
前言:
由于我新增加了一个扩展盘,启动系统后都必须挂在这个盘。
#sudo fdisk –l
#mount /dev/sdb1 /home/ema/dvsdk
一、 解压QTE,新建平台目录
1、 解压
#tar –xzvf qt-everywhere-opensource-src-4.7.3.tar.gz
#cd qt-everywhere-opensource-src-4.7.3/
2、 新建平台目录
#cd mkspecs/qws
#cp linux-arm-g++ linux-omap3-g++
#cd linux-omap3-g++
二、 安装交叉编译器,设置环境变量
1、 解压交叉编译器
#cd /home/ema/arm-linux
#tar –xjvf arm-2009q1-203-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
2、 设置编译器的环境变量
#vim ~/.bashrc
#export PATH=/home/ema/arm-linux/arm-2009q1/bin:$PATH
# export LD_LIBRARY_PATH =/home/ema/arm-linux/arm-2009q1/lib:$ LD_LIBRARY_PATH
三、 安装DVSDK,设置环境变量
1、 解压DVSDK
#cd /home/ema/
#mkdir dvsdk
#tar –xjvf ti-dvsdk_dm3730-evm_4_02_00_06.tar.bz2
2、 设置移植库的环境变量
#export LD_LIBRARY_PATH=/home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/linux-devkit/arm-none-linux-gnueabi/usr/lib:$LD_LIBRARY_PATH
#export LD_LIBRARY_PATH=/home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/gfx_dbg_es2.x/freedesktop/kdrive/usr/X11R6_SGX/lib:$LD_LIBRARY_PATH
#export LD_LIBRARY_PATH=/home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/gfx_dbg_es2.x:$LD_LIBRARY_PATH
四、 修改交叉编译文件,设定编译环境
添加DBUS、TSLIB、FREETYPE、ALSA、JPEG、PNG交叉编译库以及头文件路径
# cd /home/ema/qt-everywhere-opensource-src-4.7.3/mkspecs/qws
#vim qmake.conf
#
# qmake configuration for building with arm-linux-g++
#
include(../../common/g++.conf)
include(../../common/linux.conf)
include(../../common/qws.conf)
QMAKE_INCDIR = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/linux-devkit/arm-none-linux-gnueabi/usr/include/dbus-1.0 /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/linux-devkit/arm-none-linux-gnueabi/usr/lib/dbus-1.0/include /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/linux-devkit/arm-none-linux-gnueabi/usr/include/alsa /home/ema/arm-linux/arm-2009q1/lib/lib-arm/tslib/include /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/linux-devkit/arm-none-linux-gnueabi/usr/lib/glib-2.0/include /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/linux-devkit/arm-none-linux-gnueabi/usr/include/libxml2/libxml /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/linux-devkit/arm-none-linux-gnueabi/usr/include/glib-2.0/glib /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/linux-devkit/arm-none-linux-gnueabi/usr/include /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/linux-devkit/arm-none-linux-gnueabi/usr/include/glib-2.0/gobject /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/linux-devkit/arm-none-linux-gnueabi/usr/include/glib-2.0/include /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/linux-devkit/arm-none-linux-gnueabi/usr/include/gstreamer-0.10
QMAKE_LIBDIR = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/linux-devkit/arm-none-linux-gnueabi/usr/lib/alsa-lib/smixer /home/ema/arm-linux/arm-2009q1/lib/lib-arm/tslib/lib /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/linux-devkit/arm-none-linux-gnueabi/usr/lib /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/gfx_dbg_es2.x
LIBS += -ldbus-1 -lrt -lglib-2.0 -lgthread-2.0 -lIMGegl -lsrv_um -pthread -pthread -lgstreamer-0.10 -lgobject-2.0 -lgmodule-2.0 -lxml2 -lglib-2.0 -lgstinterfaces-0.10 -lgstvideo-0.10 -lgstbase-0.10 -lts -lz
# 修改g++里的宏定义
#设置使用ARM高级特性的编译标志
QMAKE_CFLAGS_RELEASE = -O2 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp
QMAKE_CXXFLAGS_RELEASE = -O2 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp
# modifications to g++.conf
QMAKE_CC = arm-none-linux-gnueabi-gcc
QMAKE_CXX = arm-none-linux-gnueabi-g++
QMAKE_LINK = arm-none-linux-gnueabi-g++
QMAKE_LINK_SHLIB = arm-none-linux-gnueabi-g++
# modifications to linux.conf
QMAKE_AR = arm-none-linux-gnueabi-ar cqs
QMAKE_OBJCOPY = arm-none-linux-gnueabi-objcopy
QMAKE_STRIP = arm-none-linux-gnueabi-strip
load(qt_config)
五、 制作shell脚本,配置编译选项
1、 查看配置参数,根据需要选配
//查看配置参数
#./configure –h
#cd /home/ema/ qt-everywhere-opensource-src-4.7.3
#vim arm-config.sh
#!/bin/sh
./configure \
-prefix /usr/local/qt-emembeded-4.7.3-arm-linux \
-opensource \
-release \
-shared \
-qt3support \
-webkit \
-system-nas-sound \
-qt-zlib \
-optimized-qmake \
-confirm-license \
-xplatform qws/linux-omap3-g++ \
-embedded arm \
-depths 16 \
-release \
-fast \
-no-pch \
-dbus \
-force-pkg-config \
-phonon \
-phonon-backend \
-qt-libjpeg \
-qt-libpng \
-qt-libtiff \
-multimedia \
-qt-libmng \
-qt-freetype \
-qt-mouse-tslib -qt-mouse-linuxtp -qt-mouse-pc \
-exceptions \
-opengl \
-openvg \
-xmlpatterns \
-no-mmx -no-3dnow -no-sse -no-sse2 -no-sse3 -no-sse4.1 -no-sse4.2 \
-no-avx -no-openssl -no-cups -no-ssse3 \
-nomake examples -nomake demos -nomake docs -nomake tools \
-no-qvfb \
-no-openssl \
-qt-gfx-linuxfb \
-v
2、 增加X11库的库文件、头文件配置
#vim ./mkspecs/qws/linux-omap3-g++/../../commen/qws.conf
#
# qmake configuration common for QWS
#
MAKEFILE_GENERATOR = UNIX
TARGET_PLATFORM = unix
TEMPLATE = app
CONFIG += qt warn_on release incremental link_prl
QT += core gui network
QMAKE_INCREMENTAL_STYLE = sublib
# modifications to linux.conf
QMAKE_INCDIR_X11 = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/gfx_dbg_es2.x/freedesktop/kdrive/usr/X11R6_SGX/include
QMAKE_LIBDIR_X11 = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/gfx_dbg_es2.x/freedesktop/kdrive/usr/X11R6_SGX/lib
QMAKE_INCDIR_OPENGL = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/GFX_Linux_SDK/OGLES/SDKPackage/Builds/OGLES/Include /home/linuxsir/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/GFX_Linux_SDK/OGLES2/SDKPackage/Builds/OGLES2/Include
QMAKE_LIBDIR_OPENGL = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/gfx_dbg_es2.x
QMAKE_INCDIR_OPENGL_ES1 = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/GFX_Linux_SDK/OGLES/SDKPackage/Builds/OGLES/Include
QMAKE_LIBDIR_OPENGL_ES1 = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/gfx_dbg_es2.x
QMAKE_INCDIR_OPENGL_ES2 = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/GFX_Linux_SDK/OGLES2/SDKPackage/Builds/OGLES/Include
QMAKE_LIBDIR_OPENGL_ES2 = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/gfx_dbg_es2.x
QMAKE_LIBS_X11 = -lXext -lX11 -lm
QMAKE_LIBS_X11SM = -lSM -lICE
QMAKE_LIBS_OPENGL = -lGLU -lGL
QMAKE_LIBS_OPENGL_QT = -lGL
3、增加OpenGL、OpenGV,2D、3D图形库机器头文件配置
#vim ./mkspecs/qws/linux-omap3-g++/../../commen/qws.conf
#
# qmake configuration for common linux
#
QMAKE_CFLAGS_THREAD += -D_REENTRANT
QMAKE_CXXFLAGS_THREAD += $$QMAKE_CFLAGS_THREAD
QMAKE_INCDIR =
QMAKE_LIBDIR =
QMAKE_INCDIR_X11 = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/gfx_dbg_es2.x/freedesktop/kdrive/usr/X11R6_SGX/include
QMAKE_LIBDIR_X11 = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/gfx_dbg_es2.x/freedesktop/kdrive/usr/X11R6_SGX/lib
QMAKE_INCDIR_QT = $$[QT_INSTALL_HEADERS]
QMAKE_LIBDIR_QT = $$[QT_INSTALL_LIBS]
QMAKE_INCDIR_OPENGL = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/GFX_Linux_SDK/OGLES/SDKPackage/Builds/OGLES/Include /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/GFX_Linux_SDK/OGLES2/SDKPackage/Builds/OGLES2/Include
QMAKE_LIBDIR_OPENGL = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/gfx_dbg_es2.x
QMAKE_INCDIR_OPENGL_ES1 = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/GFX_Linux_SDK/OGLES/SDKPackage/Builds/OGLES/Include
QMAKE_LIBDIR_OPENGL_ES1 = $$QMAKE_LIBDIR_OPENGL
QMAKE_INCDIR_OPENGL_ES2 = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/GFX_Linux_SDK/OGLES2/SDKPackage/Builds/OGLES2/Include
QMAKE_LIBDIR_OPENGL_ES2 = $$QMAKE_LIBDIR_OPENGL
QMAKE_INCDIR_EGL = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/GFX_Linux_SDK/OGLES/SDKPackage/Builds/OGLES/Include
QMAKE_LIBDIR_EGL = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/gfx_dbg_es2.x
QMAKE_INCDIR_OPENVG = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/GFX_Linux_SDK/OVG/SDKPackage/Builds/OVG/Include
QMAKE_LIBDIR_OPENVG = /home/ema/dvsdk/ti-dvsdk_dm3730-evm_4_02_00_06/omap35x_graphics_sdk_4.00.00.01/gfx_dbg_es2.x
QMAKE_LIBS =
QMAKE_LIBS_DYNLOAD = -ldl
QMAKE_LIBS_X11 = -lXext -lX11 -lm
QMAKE_LIBS_X11SM = -lSM -lICE
QMAKE_LIBS_NIS = -lnsl
QMAKE_LIBS_EGL = -lEGL
QMAKE_LIBS_OPENGL = -lGLU -lGL
QMAKE_LIBS_OPENGL_QT = -lGL
QMAKE_LIBS_OPENGL_ES1 = -lGLES_CM
QMAKE_LIBS_OPENGL_ES2 = -lGLESv2
QMAKE_LIBS_OPENVG = -lOpenVG
QMAKE_LIBS_THREAD = -lpthread
QMAKE_MOC = $$[QT_INSTALL_BINS]/moc
QMAKE_UIC = $$[QT_INSTALL_BINS]/uic
QMAKE_AR = ar cqs
QMAKE_OBJCOPY = objcopy
QMAKE_RANLIB =
QMAKE_TAR = tar -cf
QMAKE_GZIP = gzip -9f
QMAKE_COPY = cp -f
QMAKE_COPY_FILE = $(COPY)
QMAKE_COPY_DIR = $(COPY) -r
QMAKE_MOVE = mv -f
QMAKE_DEL_FILE = rm -f
QMAKE_DEL_DIR = rmdir
QMAKE_STRIP = strip
QMAKE_STRIPFLAGS_LIB += --strip-unneeded
QMAKE_CHK_DIR_EXISTS = test -d
QMAKE_MKDIR = mkdir -p
QMAKE_INSTALL_FILE = install -m 644 -p
QMAKE_INSTALL_PROGRAM = install -m 755 -p
include(unix.conf)
六、 执行配置,交叉编译安装
#./ arm-config.sh
#make
#sudo make install
以Camera为例,看看应用程序如何获得拍照的图片。
Camera类中拍照的方法是Capture(),它通过继承类android.hardware.Camera中的接口回调函数PictureCallback得到jpegData,
这个jpegData正是从底层得到的图像数据。
当我们按下快门按钮,Camera应用程序调用Capture方法,开启一个拍照的线程,当整个拍照过程在底层全部完成以后,该线程会把拍好的照片数据通过消息机制发送给Camera对象,
底层数据由C++空间进入JAVA空间,需要JN 层接口,这里就是postEventFromNative()
再往下走走,就到了Camera的本地代码,我们知道,Camera系统由客户端t和服务端组成,
客户端就是我们的应用程序,服务端CameraService调用抽象层方法得到底层数据。
这里,客户端由Camera::dataCallback()得到服务端CameraService::client::dataCallback()数据,
代码多了容易思路混乱,最后做个总结。