我想检测哪个精灵被触摸。如果我做 :
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);
listener->onTouchMoved = CC_CALLBACK_2(HelloWorld::onTouchMoved, this);
listener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener->clone(), mySprite);
Run Code Online (Sandbox Code Playgroud)
然后在我的触摸方法中我这样做:
bool HelloWorld::onTouchBegan(Touch* touch, Event* event)
auto spriteBlock = static_cast<Block*>(event->getCurrentTarget());
Run Code Online (Sandbox Code Playgroud)
精灵被很好地检测到。
问题是我在图层上有大约 20 个精灵,我需要能够检测到它们,我需要设置吗
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener->clone(), mySprite);
Run Code Online (Sandbox Code Playgroud)
对于每个精灵?
我有这个plist文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<key>levels</key>
<array>
<dict>
<key>x</key>
<int>80</int>
<key>y</key>
<int>266</int>
</dict>
<dict>
<key>x</key>
<int>170</int>
<key>y</key>
<int>266</int>
</dict>
</array>
</plist>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用cocos2dx v3.2读取该文件:
ValueMap data;
std::string path = FileUtils::getInstance()->fullPathForFilename("my.plist");
data = FileUtils::getInstance()->getValueMapFromFile(path);
auto arrLevels = data.at("levels").asValueVector();
for(int i = 0; i < arrLevels.capacity(); i++){
//I don't know what I have to do here to get the x value and y value of the current item.
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮我吗?我正在所有互联网中搜索,为此发现的所有示例均不足。
我正在尝试在我的项目中使用 SimpleAudioEngine 。我将 SimpleAudiEngine 标头包含到 AppDelegate 中。
#include "SimpleAudioEngine.h"
Run Code Online (Sandbox Code Playgroud)
当我为 Android 构建项目时,一切编译和构建都很好。SimpleAudioEngine 工作正常。如果针对 Linux 运行构建,我会收到一条错误消息:
fatal error: SimpleAudioEngine.h: No such file or directory
#include "SimpleAudioEngine.h"
Run Code Online (Sandbox Code Playgroud)
我尝试将 SimpleAudioEngine 包含到 CMake 文件中 - 结果仍然是以前的。
我正在使用 android sdk 4.2.2 在 mac os 上创建 cocos2d-x 游戏(v. 3.4),但我也尝试了其他。我想让 NativeHelper 类从 C++ 调用一些原生的 android 东西。我使用本教程作为基础:http : //www.cocos2d-x.org/wiki/User_Tutorial-Integrate_AdMob 它正在工作,但我想使用带参数的 java 函数。并且出现错误:
02-13 09:33:20.690: W/dalvikvm(28873): 假方法描述符: (I;)V 02-13 09:33:20.690: E/JniHelper(28873): 找不到 showBanner 的静态方法 ID
这是java实现:
public static void showBanner(int position) {
final int _position = position;
_appActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
if(_appActivity != null){
if (!_appActivity.adView.isEnabled()){
_appActivity.adView.setEnabled(true);
}
if (_appActivity.adView.getVisibility() == View.INVISIBLE){
_appActivity.adView.setVisibility(View.VISIBLE);
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
if(_position == 0){
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
}
else{
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用瓷砖地图在Cocos2D-X中创建一个游戏,我收到以下错误:
行setContentSize(CCSizeZero)中的EXC_BAD_ACCESS(代码= 2,地址= 0x0 ); 方法CCTMXTiledMap :: initWithTMXFile(const char*tmxFile)
我正在以这种方式创建瓷砖地图:
tileMap->initWithTMXFile("TileMap.tmx");
this->background = tileMap->layerNamed("Background");
Run Code Online (Sandbox Code Playgroud)
有人知道它发生了什么吗?
拜托,你能帮帮我吗?
我最近决定在花了一两年的时间学习如何用iOS编写代码来开发Android开发.现在我正在尝试将我的Cocos2d-iphone代码移植到Cocos2d-x上,我对如何处理所有不同的图像密度感到困惑.现在,我正在为480x800编码,我正在试图如何自动选择使用哪种图像密度.我认为(虽然我可能错了)对于本机java,你可以为hdpi,ldpi,mdpi等创建子目录,设备会自动选择要使用的文件.但是,基于Wenderlich的页面(http://www.raywenderlich.com/33752/cocos2d-x-tutorial-for-ios-and-android-space-game),您不应该在资源中使用子目录夹.那么如何找出设备使用的密度?
我试过用int
getResources().getDisplayMetrics().density;
Run Code Online (Sandbox Code Playgroud)
但我最终得到的错误是"getResources"未在此范围内声明.我需要做些什么才能让Cocos2d-x查找正确的图像并进行适当的缩放?
在Cocos2d中,我用来通过代码获取当前运行的场景:
CCScene *runningScene = [[CCDirector sharedDirector] runningScene];
if ([runningScene isKindOfClass:[GameScene class]])
Run Code Online (Sandbox Code Playgroud)
有没有类似的方法来获得这个cocos2d-x也???
我在用:
CCScene *scene = (CCScene *)CCDirector::sharedDirector()->getRunningScene();
Run Code Online (Sandbox Code Playgroud)
但如何将其与当前场景进行比较?
我正在遵循将cocos2d-x中的nextpeer与c ++集成的接下来的指导原则,我已经在项目中复制了所需的框架和类,然后为nextpeer添加了所需的框架,还添加了链接器标志但是有Apple Mach-O链接器错误,这是一个日志:
Undefined symbols for architecture i386:
"_CTFontCopyFullName", referenced from:
-[NSMutableAttributedString(NP_OHCommodityStyleModifiers) npSetTextBold:range:] in Nextpeer(NP_NSAttributedString+Attributes.o)
"_CTFontCreateCopyWithAttributes", referenced from:
___NP_NSAttributedStringByScalingFontSize_block_invoke in Nextpeer(NP_TTTAttributedLabel.o)
"_CTFontCreateCopyWithSymbolicTraits", referenced from:
-[NSMutableAttributedString(NP_OHCommodityStyleModifiers) npSetTextBold:range:] in Nextpeer(NP_NSAttributedString+Attributes.o)
"_CTFontCreateUIFontForLanguage", referenced from:
-[NSMutableAttributedString(NP_OHCommodityStyleModifiers) npSetTextBold:range:] in Nextpeer(NP_NSAttributedString+Attributes.o)
"_CTFontCreateWithFontDescriptor", referenced from:
-[NSMutableAttributedString(NP_OHCommodityStyleModifiers) npSetFontFamily:size:bold:italic:range:] in Nextpeer(NP_NSAttributedString+Attributes.o)
"_CTFontCreateWithName", referenced from:
_NP_NSAttributedStringAttributesFromLabel in Nextpeer(NP_TTTAttributedLabel.o)
-[NSMutableAttributedString(NP_OHCommodityStyleModifiers) npSetFontName:size:range:] in Nextpeer(NP_NSAttributedString+Attributes.o)
"_CTFontDescriptorCreateWithAttributes", referenced from:
-[NSMutableAttributedString(NP_OHCommodityStyleModifiers) npSetFontFamily:size:bold:italic:range:] in Nextpeer(NP_NSAttributedString+Attributes.o)
"_CTFontGetSize", referenced from:
___39+[NP_OHASBasicMarkupParser tagMappings]_block_invoke_3 in Nextpeer(NP_OHASBasicMarkupParser.o)
___NP_NSAttributedStringByScalingFontSize_block_invoke in Nextpeer(NP_TTTAttributedLabel.o)
"_CTFontGetSymbolicTraits", referenced from:
-[NSAttributedString(NP_OHCommodityConstructors) npTextIsBoldAtIndex:effectiveRange:] in Nextpeer(NP_NSAttributedString+Attributes.o)
"_CTFrameGetLineOrigins", referenced from:
-[NP_TTTAttributedLabel …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的cocos2dx项目中包含一个UI类.
在我的场景课中,我有:
#include "CocosGUI.h"
Run Code Online (Sandbox Code Playgroud)
它适用于iOS编译,但当我尝试使用命令行为Android编译时,我收到以下错误:
fatal error: CocosGUI.h: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我理解这是因为它无法找到库.我一直在努力找到合适的人,但没有运气.
我已经添加:
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_ui_static
Run Code Online (Sandbox Code Playgroud)
和
$(call import-module,extensions)
$(call import-module,ui)
Run Code Online (Sandbox Code Playgroud)
但这似乎没有帮助.
我正在使用cocos2dx v3.0
嗨我正在尝试使用Android Studio运行使用Cocos2d-x 2.5创建的应用程序,但在运行项目时我一直收到此错误:
:myApp:compileDebugNdk AGPBI:{"kind":"ERROR","text":"***Android NDK:Aborting ....停止.","sourcePath":"/ mypath/ndk/android-ndk-r10d /build/core/add-application.mk","position":{"startLine":199},"original ":""}
FAILED执行失败,任务':myApp:compileDebugNdk'.
建筑工作正常.我有Android Studio 1.1.0和Mac OS X Yosemite 10.10.
你们有什么想法可能有什么不对吗?
我在这里讨论了类似的错误在尝试使用NDK源代码编译Android Studio项目时执行失败的任务':app:compileDebugNdk'
但该解决方案对我不起作用(在jni文件夹中创建一个空的.c文件).看起来这是在Windows上发生的事情我使用Mac.
android android-ndk cocos2d-x cocos2d-android android-studio