如何绘制多个CCSprite而不降低性能?

发布于 2024-12-05 05:02:33 字数 880 浏览 0 评论 0原文

我正在制作这样一个射箭游戏。一切都很好。但我意识到如果我画一条线追踪我的箭头,那就太好了。所以我在调度程序中的游戏中添加了一些代码,该代码应该在箭头所在的位置绘制圆圈。但我必须画很多圆圈,所以当我拍摄多箭头时,游戏帧不好。

还有其他更好的办法吗?我已经使用CCSpriteBatchNode、plist、CCSpriteFrameCache。我已经尽力了。我需要帮助非常感谢

这是我的代码

...............
    [self schedule:@selector(CollisionDetection:)];
}


- (void)CollisionDetection:(ccTime)dt 
{
    for (CCSprite *arrow in arrows->arrowsArray) 
    {
            CCSprite *track = [CCSprite spriteWithSpriteFrameName:@"WhiteCircle.png"];
            [track setPosition:arrow.position];
            [arrows->rootLayer->arrowsSheet addChild:track];

            id delete = [CCFadeOut actionWithDuration:1.0];
            id deleteAction= [CCSequence actions:delete ,[CCCallFuncN actionWithTarget:self selector:@selector(spriteActionFinished:)], nil];
            [track runAction:deleteAction];
    .......    

I'm making such a arrow shooting game. Everything is good. but I realized if I draw line tracking my arrow, It will be great. so I put some code on my game in my Scheduler that is supposed to draw circle where arrow is going. But I had to draw so many circle, so game frame is not good when I shoot multi arrow.

Is there other better way? I use CCSpriteBatchNode, plist, CCSpriteFrameCache already. I did all I can do. I need help Thanks so much

this is my code

...............
    [self schedule:@selector(CollisionDetection:)];
}


- (void)CollisionDetection:(ccTime)dt 
{
    for (CCSprite *arrow in arrows->arrowsArray) 
    {
            CCSprite *track = [CCSprite spriteWithSpriteFrameName:@"WhiteCircle.png"];
            [track setPosition:arrow.position];
            [arrows->rootLayer->arrowsSheet addChild:track];

            id delete = [CCFadeOut actionWithDuration:1.0];
            id deleteAction= [CCSequence actions:delete ,[CCCallFuncN actionWithTarget:self selector:@selector(spriteActionFinished:)], nil];
            [track runAction:deleteAction];
    .......    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

睫毛溺水了 2024-12-12 05:02:33

对象的分配是一个很大的开销。如果您的游戏运行缓慢,您应该考虑在游戏开始时创建一个箭头池,并且仅在需要时才触发其上的操作。如果它不再可见,只需将其设置为非活动状态,并在下次需要箭头时重复使用它。

The allocation of objects is a large overhead. If your game runs to slow you should consider creating a pool of arrows at the beginning of the game and only trigger the action on it as soon as you need it. If it is not visible anymore just set it to inactive and reuse it the next time you need an arrow.

氛圍 2024-12-12 05:02:33

听起来你的问题不是箭头,而是圆圈,我想它们也是 Cocos 对象。您最好学习如何使用 opengl 命令而不是对象将圆形纹理直接绘制到屏幕上。这会有很大帮助。

Sounds like your problem isn't the arrows, but the circles, which I imagine are Cocos objects too. You'd be better off learning how to draw the circle texture directly to the screen using opengl commands instead of objects. That'll help a lot.

泛滥成性 2024-12-12 05:02:33

当有一个时间关键的动画时,我远离 CCCallFunc(N),因为它可以使调度程序停滞相当长的时间。当我阅读您的代码时,您在每个计划的时间间隔都有一个 CallFunc ... 嗯。您是否尝试过在没有调度程序的情况下运行它,即打包并立即启动所有动画,最后有一个 CallFunc ?不要将位置更改作为计划间隔的一部分,而是使用与跟踪动画同时运行的 CCMoveTo。

When have a time critical animation, i stay clear from CCCallFunc(N), as it can stall the scheduler for a noticeable amount of time. As I read your code, you have a CallFunc at every scheduled interval ... hmmmm. Have you tried running this without the scheduler, ie package and start all your animations at once, with a single CallFunc at the end ? Instead of changing the position as part of the scheduled interval, use a CCMoveTo that you will run at the same time as your tracking animation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文