本文介绍了PacMan角色未呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XNA 4.0中有一个基于图块的PacMan克隆.一切都在正确的位置进行绘制-除了PacMan.看来他在x和y上都偏移了16个像素,但我不知道为什么.

这是我画他的地方:

I have a PacMan clone I am making in XNA 4.0 that is tile-based. Everything is drawing in the correct position - except PacMan. It seems as if he is offset by 16 pixels on both x and y, but I don''t know why.

Here is where I draw him:

/// <summary>
        /// Draws PacMan.
        /// </summary>
        /// <param name="spriteBatch">The sprite batch to draw with.</param>
        /// <param name="tileWidth">The width of a tile.</param>
        /// <param name="tileHeight">The height of a tile.</param>
        public void Draw(SpriteBatch spriteBatch, int tileWidth, int tileHeight)
        {
            // Draw PacMan.
            if (openMouth)
            {
                spriteBatch.Draw(pacMan1, new Rectangle(PosX * tileWidth, PosY * tileHeight,
                    tileWidth, tileHeight), null,
                    Color.White, MathHelper.ToRadians(Rotation), new Vector2(tileWidth / 2, tileHeight / 2),
                    SpriteEffects.None, 0f);
            }

            else
            {
                spriteBatch.Draw(pacMan2, new Rectangle(PosX * tileWidth, PosY * tileHeight,
                    tileWidth, tileHeight), null,
                    Color.White, MathHelper.ToRadians(Rotation), new Vector2(tileWidth / 2, tileHeight / 2),
                    SpriteEffects.None, 0f);
            }
        }



tileWidth和tileHeight用于绘制重影,它们显示得很好,所以不能成为它们.

我尝试将其发布到App Hub,但由于只有13岁,所以无法执行.

谢谢,
ge-force



tileWidth and tileHeight are used for drawing the ghosts, and they show up fine, so it can''t be them.

I tried posting this on App Hub,, but I can''t since I''m only 13.

Thanks,
ge-force

推荐答案

Vector2 origin = new Vector2(tileWidth / 2, tileHeight / 2);


然后将位置传递给draw方法


then where you pass the position to the draw method

new Rectangle((PosX * tileWidth) + (int)origin.X, (PosY * tileHeight) + (int)origin.Y, tileWidth, tileHeight)



希望对您有帮助



hope this helps


这篇关于PacMan角色未呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 10:25