【问题标题】:In Cocos2d , How to move background sprite image?在 Cocos2d 中,如何移动背景精灵图像?
【发布时间】:2012-09-18 05:17:05
【问题描述】:

我正在做汽车游戏,我想以纵向模式移动背景图像(图像大小为 320 × 1024),为此我不想使用 CCParallaxNode 来移动背景图像,甚至不是 TiledMap。有没有其他方法可以在纵向模式下移动背景。

2分钟后我想提高背景精灵的速度,谁能帮我怎么做。

提前致谢。

【问题讨论】:

  • 你的意思是,你想滚动你的背景向下病房..?像无限滚动的背景..?
  • 每次更新都改变精灵的位置属性?使用 CCMoveTo 操作?

标签: cocos2d-iphone xcode4.2


【解决方案1】:

只需在预定更新方法上设置背景精灵的位置即可。

-(void) anUpdate:(ccTime)dt {

    bgSprite.position = ccp(<new x coordinate>, <new y coordinate>);

【讨论】:

    【解决方案2】:

    在更新方法中定位你的 bgImage:

    -(void) update:(ccTime)dt{
        total_time_ += dt;
        if(total_time_> 2*60)
          speed_ *=2;
        bgSprite.position = ccp(bgSprite.position.x, bgSprite.position.y+speed_*dt);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多