嘿,我有点麻烦了。我使用xna已有一段时间了,但是我对3D完全陌生。我正在从msdn网站上的winformsgraphicsdevice示例中逐字查看代码。它具有一个将原始三角形绘制到屏幕上的控件。就这么简单,但是我在这一行遇到了一个例外:
GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1);
Run Code Online (Sandbox Code Playgroud)
其中说:
"The current vertex declaration does not include all the elements required by the current vertex shader. Normal0 is missing."
我假设它与我的VertexPositionColor变量有关vertices。该代码在这里:
vertices = new VertexPositionColor[3];
vertices[0] = new VertexPositionColor(new Vector3(-1, -1, 0), Color.Black);
vertices[1] = new VertexPositionColor(new Vector3( 1, -1, 0), Color.Black);
vertices[2] = new VertexPositionColor(new Vector3(0, 1, 0), Color.Black);
Run Code Online (Sandbox Code Playgroud) 我一直在研究我的richtextbox,但是我遇到了一些奇怪的事情......我想在每行粗线上创建第一个单词
使用此代码:
RichTextBox bold = richTextBox1;
foreach (string line in bold.Lines)
{
string name = line.Split(' ')[0];
int srt = bold.Find(name);
bold.Select(srt, name.Length);
bold.SelectionFont = new Font(bold.Font, FontStyle.Bold);
}
Run Code Online (Sandbox Code Playgroud)
但由于某种原因,一些行被跳过.从我注意到它取决于行开头的单词
例如Name:被跳过但是Name1:很好,ProcessId,VirtualSize和WorkingSetSize也是如此.
示例http://i40.tinypic.com/4lov91.png
如果需要更多解释,请告诉我.
这些行添加如下
richTextBox1.Text += "Name: "+ queryObj["Name"] + Environment.NewLine;
Run Code Online (Sandbox Code Playgroud)
在将所有内容添加到richtextbox之后调用使所有第一个单词变为粗体的函数.
我这样做:https : //stackoverflow.com/questions/12069002/autofac-resolve-with-and-without-named-parameter
我注册了一个接口。对于初始化,需要一个参数。第一次调用将传递此参数。
在另一个地方,我也想解析这个接口实例,但我不能传递这个参数。是否可以检查此接口是否已解析(在当前范围内。我使用 ASP.NET WEB API)?如果我在没有参数的情况下解决它,我会得到一个例外。
我需要检查当前 HttpRequest-scope 中是否已经解析(所以我可以在不传递参数的情况下获取它,因为如果它已经解析,注册的创建委托将不会被调用两次)
m_builder.Register<IMyClass((c, p) =>
{
//...
return new MyClass;
}).InstancePerHttpRequest();//.InstancePerApiRequest();
Run Code Online (Sandbox Code Playgroud) 我目前在我的游戏中有这个代码:
Vector2 pixelpos = new Vector2(x, y);
Vector2 center = new Vector2(t.Width / 2, t.Height / 2);
Vector2 pixelposWorld = (pixelpos - center);
float rotation = (float)Math.Atan2(pixelposWorld.Y, pixelposWorld.X);
float rotationPercent = (MathHelper.ToDegrees(rotation) / 360);
Run Code Online (Sandbox Code Playgroud)
我的目标是最终使 rotationPercent 成为 0.0 到 1.0 之间的值,0 度为 0.0,180 为 0.5,360 为 1.0。
目前,rotationPercent 仅作为 1.0 出现。
我能做些什么来解决这个问题?
我正在使用这段代码,但我仍然不明白为什么当我开始游戏时球模糊,有人可以帮助我吗??我只是在用户点击时试图向我发球,但我不知道为什么它模糊,我还在检查代码,请帮忙
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace Critters
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D ball;
Vector2 playerPosition;
Vector2 direction;
Vector2 destination;
float speed;
float playerPosX;
float playerPosY;
MouseState oldState;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
this.IsMouseVisible = true;
}
/// <summary>
/// …Run Code Online (Sandbox Code Playgroud) 我在xna游戏的update()部分有这个:
while (TouchPanel.IsGestureAvailable)
{
GestureSample gs = TouchPanel.ReadGesture();
switch (gs.GestureType)
{
case GestureType.Flick:
_GameMap.GameCamera.Translate(new Vector2(-gs.Delta.X/2, 0));
//moves the camera by this amount
break;
}
}
Run Code Online (Sandbox Code Playgroud)
但不出所料,当我轻弹没有滚动(如谷歌地球或愤怒的小鸟),它只是一个开始和结束.如何在轻弹中实现滚动?
我试图在我的XNA项目中序列化数据.我有一个在运行时使用的Texture2D背景属性,但我也有一个'字符串属性'来保存我的背景名称.这将允许我序列化资产名称,以便稍后我可以使用该信息进行反序列化并加载到我的游戏中.
问题是myTexture.Name属性是为了保存资产名称,但是当我尝试序列化为XML文件时,BackgroundName元素为空.
以下是Property代码的样子:
//This property is Only used for serialization, myTexture is Texture2D and is assigned in the ctor of the class
public string BGName { get { return this.myTexture.Name;} set{/*Empty on purpose*/} }
Run Code Online (Sandbox Code Playgroud)
有人可以建议,如何从Texture2D检索资产名称,根据MSDN,这个字段保存纹理的名称.