2048游戏开发者是如何使他们的瓷砖,以平滑移动?看到下面的细节 [英] How did the game developer of 2048 made their tiles to move smoothly ? see the detail below

查看:203
本文介绍了2048游戏开发者是如何使他们的瓷砖,以平滑移动?看到下面的细节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经取得2048场比赛的完整副本,但我有瓷砖通过远距传物(砖不平整动如它是在原来的游戏)

I have made the complete copy of 2048 game but i have moved by tiles by teleporting (no smoothness moving of tiles like it was in original game)

我感动用下面的代码移动砖台的铣平。

I have used the following code for smothness of moving tiles.

//GameManager script
 void MoveRight () {
     //some code ..
     AnimateTileMovement (newPosition); // newposition is the position to whihc the tiles is going to move
     //some code which i need to execute (ONLY AFTER MY COMPLETE MOVEMENT OF TILE)
     // BUT AS SOON AS TileMovement return its first null this code execute which is creating a lot of problem , what should i do ?
     //to stop execution these code until the tiles have moved towards its desired newPosition
 }

 //TilesMovement Script 

 public void AnimationTileMovement(Vector3 newPosition) {
     StartCoroutine ("TileMovement", newPosition);

 }

 IEnumerator TileMovement(Vector3 newPosition) {
     while (transform.position != newPosition) {
         transform.position = Vector3.MoveTowards (transform.position, newPosition, speedTile * Time.deltaTime);
         yield return null;

     }


 }

我一直在消磨时间来实现这一点,但我不能够做到如何停止执行以下 StartCoroutine(TileMovement,在newPosition)代码作为代码获取在执行在第一个动作时, IEnumerator的TileMovement(的Vector3在newPosition)一代产量首次空?

i have been spending days to achieve this but i am not able to do how to stop executing the code below StartCoroutine ("TileMovement", newPosition) as the code gets executed at the very first movement when the IEnumerator TileMovement(Vector3 newPosition) yeild it first null ?

我已经看过这篇文章并试图还,但未能如愿请建议我做什么的协同程序统一要求

I have read this Article and tried also but unable to do so please suggest me what to do Coroutines unity ask

推荐答案

您的问题是这个简单的,

Your problem is this simple,

后,才瓷砖我的完整运动...

ONLY AFTER MY COMPLETE MOVEMENT OF TILE...

以及

我一直在消磨时间来实现这一点,但我不能够做到如何停止执行代码...

i have been spending days to achieve this but i am not able to do how to stop executing the code ...

如果你想开始一个协程,但是坚持下去 ...

if you want to start a coroutine, but keep going....

Debug.Log("we're at A");
StartCoroutine("ShowExplosions");
Debug.Log("we're at B");

这将打印A,并启动爆炸动画,但他们马上继续下去并打印B。 (这将打印A,然后立即打印B,而爆炸将开始在同一时间为B运行打印,然后继续前进。)

that will print "A", and start the explosions animation, but them immediately keep going and print "B". (It will print "A" then immediately print "B", and the explosions will start running at the same time as "B" is printed and then keep going.)

不过....

如果你想开始一个协程,并等待 ...

if you want to start a coroutine, and wait...

Debug.Log("we're at A");
yield return StartCoroutine("ShowExplosions");
Debug.Log("we're at B");

这将打印A。然后,它会启动爆炸,它会等待:它会做什么的,直到爆炸完成只有这样将打印B。

That will print "A". It will then start the explosions and it will wait: it will do nothing until the explosions are finished. Only then it will print "B".

这是一个基本的错误经常出现在统一。

This is a basic mistake often seen in Unity.

不要忘了,收益回报!

希望它帮助!

当然,这个代码

Debug.Log("we're at A");
yield return StartCoroutine("ShowExplosions");
Debug.Log("we're at B");



本身必须是一个协程。所以你必须像...

must itself be in a coroutine. So you'd have something like...

public IEnumerator AnimationTileMovement(...)
   {
   Debug.Log("we're at A");
   .. your pre code
   yield return StartCoroutine("ShowExplosions");
   Debug.Log("we're at B");
   .. your post code
   }

和在MoveRight的你必须

and in MoveRight you'd have

public void MoveRight(...)
   {
   StartCoroutine( AnimateTileMovement(newPosition) );



有道理?

makes sense?

这篇关于2048游戏开发者是如何使他们的瓷砖,以平滑移动?看到下面的细节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆