PacMan角色未呈现 [英] PacMan character not rendering

查看:50
本文介绍了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

推荐答案

好吧,您正在将pacman纹理的原点设置为纹理宽度和高度(纹理中心)的一半,这将抵消您的纹理如果您的纹理是32x32像素,请在x和y上放置16个像素.

如果今天我的思维正常,我认为您在绘制纹理时需要将原点添加到您的位置.
例如
Well you are setting the origin of your pacman texture to half the textures width and height (the center of the texture) and this would offset your texture position 16 pixels on the x and y if your texture is 32x32 pixels.

If my mind is working correctly today I think you will need to add the origin to your position when drawing the texture.
e.g.
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角色未呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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