首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >和引擎:游戏15和数字图像运动

和引擎:游戏15和数字图像运动
EN

Stack Overflow用户
提问于 2011-10-23 22:00:25
回答 1查看 535关注 0票数 0

我已经在图像网格中设置了数字图像,现在的问题是如何用一个50像素的“模块”(单个单元格的尺寸)移动数字图像,就在其中有一个自由单元?我正在使用Andengine,每一个数字图像都是一个Sprite,网格映像也是一个。

编辑:--我是这样工作的:

我用以下两个函数设置了瓷砖的位置:

代码语言:javascript
运行
复制
private void getGrid()
{
    boolean end     =   false;
    Random random   =   new Random();

    int x = 0;
    while( ALDef.size() < 15 && x < 100 )
    {
        // Genera un numero a caso, da 1 a 15
        int numRandom       =   random.nextInt( 15 );

        System.out.println( x++ + ") Scelgo un numero RANDOM:" + numRandom );

        // il numero e' gia' presente in array?
        if ( !memory.contains( numRandom ) )
        {
            System.out.println( "ADD " + numRandom );
            // Non e' presente...
            ALDef.add( numRandom );
            memory.add( numRandom );
        }
        else
        {
            System.out.println( "ESISTE " + numRandom );
            memory.add( numRandom );
        }
    }

    System.out.println( "------------------------------" );
}

// ===========================================================
// Restituisce le coordinate
// ===========================================================
public HashMap getCoordinates( int numInArray )
{
    // Ottiene l'integer corrispondente a numInArray, ovvero il tasto
    Integer value       =   ALDef.get( numInArray );

    int row         =   0; // riga della tabella
    int position    =   0; // posizione
    // Definisce la riga
    if ( numInArray <= 3 )
    {
        row         =   0;
        position    =   3 - ( 3 - numInArray );
    }
    else if ( numInArray >= 4 && numInArray <= 7 )
    {
        row     =   1;
        position    =   numInArray - 4;
    }
    else if ( numInArray >= 8 && numInArray <= 11 )
    {
        row     =   2;
        position    =   numInArray - 8;
    }
    else if ( numInArray >= 12 && numInArray <= 15 )
    {
        row     =   3;
        position    =   numInArray - 12;
    }

    HashMap HM      =   new HashMap();
    HM.put( "btn" , value );
    HM.put( "x" , width * position );
    HM.put( "y" , height * row );

    System.out.println( "Colloco il numero " + ( value ) + " nella casella " + numInArray + "(ROW=" + row + ",POS=" + position + ")" );

    return HM;
}

这两个函数的逻辑是getGrid将对应于平铺数图像的ArrayList随机数(从0到15)放入其中。使用getCoordinates,函数返回平铺的坐标(在第0行、第1行、第2行、第3行和位置- 0、1、2、3中),以对雪碧进行定位。

EN

回答 1

Stack Overflow用户

发布于 2011-10-25 03:38:40

假设您使用2D数组Cell[4][4] cells跟踪单元格,则可以初始化单元格并拥有emptyCellLocation = (emptyCell.row, emptyCell.col)。然后,您可以确定要拖动哪个单元格,并且只允许它移动到emptyCellLocation。确保更新emptyCellLocation

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7869550

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档