- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我根据我在网上找到的一些教程创建了一个简单的 2 帧 Sprite 动画。我拍摄了我的 2 张图片,用 plist 和 png 文件创建了一个 Sprite 表,并将它们合并到我的代码中,如下所示。此设置在 Cocos2d V 1.0.1 中运行良好。我刚刚将我的项目升级到 2.0rc0a,现在我的应用程序在应该从第一帧切换到第二帧时崩溃并出现以下错误:'CCSprite: setTexture doesn't work when the sprite is rendered using a CCSpriteBatchNode'
我看了这个SO question ,但我不确定这是否与我做错的事情相同,并且因为我对 Cocos2d 仍然很陌生,我不确定如何正确调整我的代码。这是我在 2.0 中没有在注释中看到的更改,我应该报告的错误,或者只是我的编码不正确?我仍然有一份 1.0.1 项目的副本,代码相同,动画正常工作。
//CHAMELEON
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"front page/mainchameleon.plist"];
mainChameleon = [CCSpriteBatchNode batchNodeWithFile:@"front page/mainchameleon.png"];
[self addChild:mainChameleon z:7];
NSMutableArray *chameleonFrames = [NSMutableArray array];
for (int i = 1; i <= 2; ++i)
{
[chameleonFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"chameleon%d.png", i]]];
}
CCAnimation *mouthAnim = [CCAnimation animationWithSpriteFrames:chameleonFrames delay:0.3f];
chameleon = [CCSprite spriteWithSpriteFrameName:@"chameleon1.png"];
CCAnimate *chameleonAction = [CCAnimate actionWithAnimation:mouthAnim];
CCDelayTime *chameleonDelay = [CCDelayTime actionWithDuration:10];
CCRepeatForever *chameleonRepeat = [CCRepeatForever actionWithAction:[CCSequence actions:chameleonDelay, chameleonAction, chameleonDelay, nil]];
[chameleon runAction:chameleonRepeat];
[mainChameleon addChild:chameleon];
chameleon = [CCSprite spriteWithSpriteFrameName:@"chameleon1.png"];
那么应用程序不会崩溃,但变色龙根本不会出现,正如当前编写代码的方式所预期的那样。
[chameleon runAction:chameleonRepeat];
然后变色龙出现显示帧,chameleon1.png,但显然没有通过动画。
chameleonDelay
在没有重复永远语句的操作之前,我也遇到了同样的崩溃。如果应用程序必须等待超过 1 秒才能执行切换,它似乎会崩溃。我需要的是让第 1 帧坐一会儿(10 秒)然后切换到第 2 帧 0.3 秒,然后切换回第 1 帧并再次坐一会儿。
CCAnimation *mouthAnim = [CCAnimation animationWithSpriteFrames:chameleonFrames delay:0.3f]; //<--- maxes out at 1.0. Anything more causes crash
chameleon = [CCSprite spriteWithSpriteFrameName:@"chameleon1.png"];
CCAnimate *chameleonAction = [CCAnimate actionWithAnimation:mouthAnim];
[chameleon runAction:chameleonAction];
[mainChameleon addChild:chameleon];
CCAnimation *mouthAnim = [CCAnimation animationWithAnimationFrames:chameleonFrames delayPerUnit:0.3f loops:5];
'-[CCSpriteFrame delayUnits]: unrecognized selector sent to instance'
.我不确定为什么这不起作用或从这里尝试什么。
//CHAMELEON
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"front page/mainchameleon.plist"];
mainChameleon = [CCSpriteBatchNode batchNodeWithFile:@"front page/mainchameleon.png"];
[self addChild:mainChameleon z:7];
NSMutableArray *chameleonFrames = [NSMutableArray array];
//Frame 1 - closed mouth
[chameleonFrames addObject:[CCSpriteFrame frameWithTexture:mainChameleon.texture rect:CGRectMake(0, 124, 149, 122)]];
//Frame 2 - Open Mouth
[chameleonFrames addObject:[CCSpriteFrame frameWithTexture:mainChameleon.texture rect:CGRectMake(0, 0, 149, 122)]];
//Frame 1 - closed mouth
[chameleonFrames addObject:[CCSpriteFrame frameWithTexture:mainChameleon.texture rect:CGRectMake(0, 124, 149, 122)]];
CCAnimation *mouthAnim = [CCAnimation animationWithSpriteFrames:chameleonFrames delay:0.9f];
chameleon = [CCSprite spriteWithTexture:mainChameleon.texture rect:CGRectMake(0,124,149,122)];
CCAnimate *chameleonAction = [CCAnimate actionWithAnimation:mouthAnim];
CCDelayTime *chameleonDelay = [CCDelayTime actionWithDuration:10];
CCRepeatForever *chameleonRepeat = [CCRepeatForever actionWithAction:[CCSequence actions:chameleonDelay, chameleonAction, nil]];
[chameleon runAction:chameleonRepeat];
[mainChameleon addChild:chameleon];
最佳答案
这是我最终得到的可以正常工作的代码。不知道为什么我必须进行这些更改,但确实如此。 (当我开始一个新项目来解决这个问题时,一些名称已经改变,但我的原始代码和这个之间的差异是显而易见的)。对于找到此线程的其他人,我的原始代码基于 Ray Wenderlich's sprite sheet tutorial .
CCSpriteBatchNode *chameleonBN = [CCSpriteBatchNode batchNodeWithFile:@"chameleonimages.png"];
[self addChild:chameleonBN];
//ADDED the texture part to resolve: 'CCSprite: setTexture doesn't work when the sprite is rendered using a CCSpriteBatchNode'
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"chameleonplist.plist" texture:chameleonBN.texture];
NSMutableArray *chameleonframes = [NSMutableArray array];
for (int i = 1; i <= 2 ; i++)
{
[chameleonframes addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"chameleon%d.png", i]]];
}
CCAnimation *mouthAnim = [CCAnimation animationWithSpriteFrames:chameleonframes delay:0.9f];
//ADDED this sprite frame to resolve texture id assert error
CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:chameleonBN.texture rect:CGRectMake(0, 0, 149, 122)];
CCSprite *chameleon = [CCSprite spriteWithSpriteFrame:frame];
chameleon.position = ccp(512,384);
CCAnimate *chameleonAnimate = [CCAnimate actionWithAnimation:mouthAnim];
CCDelayTime *chameleonDelay = [CCDelayTime actionWithDuration:10];
CCDelayTime *chameleonDelay2 = [CCDelayTime actionWithDuration:0.1];//Had to use this to ge tthe mouth to close. Using restore original frame doesn't work for me.
CCRepeatForever *chameleonRepeat = [CCRepeatForever actionWithAction:[CCSequence actions:chameleonDelay, chameleonAnimate, chameleonDelay2, nil]];
[chameleon runAction:chameleonRepeat];
[chameleonBN addChild:chameleon];
关于animation - 从 Cocos2d 1.0.1 升级到 2.0 后,Sprite Sheet 动画失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10030974/
我在 Android 中使用 Google Sheets API v4。 https://developers.google.com/sheets/api/quickstart/android 我需要
我想使用 googlesheetv4 api 在 googlesheet 中使用 rowno 删除一行。有人可以给我提供一个示例代码吗?我创建了一个删除行的方法公共(public)无效deleteRo
我想使用 googlesheetv4 api 在 googlesheet 中使用 rowno 删除一行。有人可以给我提供一个示例代码吗?我创建了一个删除行的方法公共(public)无效deleteRo
如何在 Google 表格中获取数据透视表,其中一列显示值在列中出现的次数? 我知道可以使用 countif 来完成。功能,但我想使用数据透视表来完成。 最佳答案 转到顶部菜单 Data--> Piv
在 Google 表格中,我尝试使用作用于其他两个单元格的条件格式公式将文本添加到不同的单元格。 例如,我有几列......“C”和“E”。我正在比较 C25 和 E25 中的值,如下所示:=E25<
假设我有一个带有随机工作表名称的工作簿,“Bob”、“Sally”、“Billy”、“John”或类似的非连续名称。我还有另一张名为“总计”的表格。我怎样才能对特定单元格的值求和,比如所有单元格的“H
我已经能够使用 Google Sheet 的 SEQUENCE为我提供 Partner 1 的顺序日期的公式但随后公式停止并且不会继续到 Partner 2 . 我曾尝试在 Google 的 Arra
我需要对字符串中的所有数字求和,在字符串中不会有任何字母只有数字。单元格包含 112121 . 我尝试使用 SUM和 CASE与 QUERY函数,但是 CASE不支持。 示例:1121 = 5。 最佳
在 Google Sheets 上,我试图在一个单元格中使用文本(比如 B4 包含:“Janet”)并在另一个单元格中的句子中引用它(比如 G4 是:“嗨{在此处输入 B4},我正在到达今天给你……”
我正在创建一个锻炼电子表格来跟踪我每周的表现,每张表格都涵盖了一周的锻炼。每张纸(除了第一张)都是前一张纸的副本,我想从上一张纸中继承一些值;例如,前一周的练习次数。 我已经阅读了一些 API,但似乎
我尝试使用示例“读取多个范围”: https://sheets.googleapis.com/v4/spreadsheets/{SpreadsheetID}/values:batchGet?range
我有一个从 Google 电子表格中获取数据的网站。我希望我的用户在不登录的情况下查看获取的数据。这可能吗?怎么做? 为了获取和更新工作表数据,我只需要一个帐户,最好在服务器端登录。但是,我没有看到任
我正在 Google Sheets 中使用 COUNTIF 公式进行一些动态蒙特卡罗模拟。有些事情不像我想象的那样工作,但我无法解决。我有两列要比较,我需要计算一列中的值大于另一列中的值的实例。如果我
我正在使用 Google Sheets 中的一个大(但简单)的公式,该公式重复使用相同的公式块。要从一堆不同的选项卡中获取一堆数据,我必须在该公式块中使用 708 个字符。但是随后我需要在 1 个单元
我在我的工作表中使用以下查询为艺术家导入总 Spotify 流。例子:=IMPORTXML("https://chartmasters.org/spotify-streaming-numbers-to
我正在尝试做一个非常简单的 lookup在数据验证字段上: 我有 4 个简单的值: 无风险 低 中级 高 除此之外,我还有以下值(value)观: 0 0.1 0.2 0.5 我使用 lookup公式
我有一个专栏 COLUMN H | Column R trading type | Closed P&L Lotto | 100% Lotto | 200% | 100% Day |
我正在寻找一种通过Google Sheets API创建一组行的方法-有没有办法做到这一点?我看不到找到可以做到这一点的API,但似乎应该是相当普遍的格式设置需求。 通过选择一组行,右键单击,该选项在
我有一个表,基本上显示了另一个表的数据。问题是:我在原始表中有一些脚本程序,这些程序涉及删除行,当它发生时,我丢失了对行所在位置的引用。 我怎样才能解决这个问题? 已经试过了:='INVENTORY'
我想通过 API v4 隐藏谷歌电子表格中的给定列,但我很难这样做。 有谁知道这是否可能并设法做到了? 我们在 Apps 脚本中有一个 dedicated method这样做,如果 REST API
我是一名优秀的程序员,十分优秀!