등각보기로 게임을 만들었습니다. 나는 현재 두 개의 행렬을 사용하여 매우 효과적으로 작업하고있는 구조를 가지고있다. 그러나이 작업을 수행하려면 추가 구성원과 기능이 필요합니다. SpriteBatch.Begin
함수 중 하나는 변환 행렬을 매개 변수로 허용합니다. 나는 새로운 SpriteBatch.Begin
함수를 작성하여 두 개의 행렬 (카메라 변형 용과 등각 투영 중 하나)을 허용합니다. 어떻게 실제 SpriteBatch.Begin
함수가 작동하는지 모르겠다. 그리고 나는 어떤 소스가 있는지 모른다. 누구나 아이디어가 있습니까?새로운 SpriteBatch.Begin 함수를 작성할 수 있습니까?
1
A
답변
3
좋아, 편집 후 SpriteBatch.begin() 함수의 소스 코드를 검색했습니다. XNA의 오픈 소스 구현 인 monogame의 소스 코드를 발견했습니다.
그래서 여기있다 :
using System;
using System.Text;
namespace Microsoft.Xna.Framework.Graphics
{
public class SpriteBatch : GraphicsResource
{
readonly SpriteBatcher _batcher;
SpriteSortMode _sortMode;
BlendState _blendState;
SamplerState _samplerState;
DepthStencilState _depthStencilState;
RasterizerState _rasterizerState;
Effect _effect;
bool _beginCalled;
Effect _spriteEffect;
readonly EffectParameter _matrixTransform;
readonly EffectPass _spritePass;
Matrix _matrix;
Rectangle _tempRect = new Rectangle (0,0,0,0);
Vector2 _texCoordTL = new Vector2 (0,0);
Vector2 _texCoordBR = new Vector2 (0,0);
public SpriteBatch (GraphicsDevice graphicsDevice)
{
if (graphicsDevice == null)
{
throw new ArgumentException ("graphicsDevice");
}
this.GraphicsDevice = graphicsDevice;
// Use a custom SpriteEffect so we can control the transformation matrix
_spriteEffect = new Effect(graphicsDevice, SpriteEffect.Bytecode);
_matrixTransform = _spriteEffect.Parameters["MatrixTransform"];
_spritePass = _spriteEffect.CurrentTechnique.Passes[0];
_batcher = new SpriteBatcher(graphicsDevice);
_beginCalled = false;
}
public void Begin()
{
Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Matrix.Identity);
}
public void Begin (SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix)
{
if (_beginCalled)
throw new InvalidOperationException("Begin cannot be called again until End has been successfully called.");
// defaults
_sortMode = sortMode;
_blendState = blendState ?? BlendState.AlphaBlend;
_samplerState = samplerState ?? SamplerState.LinearClamp;
_depthStencilState = depthStencilState ?? DepthStencilState.None;
_rasterizerState = rasterizerState ?? RasterizerState.CullCounterClockwise;
_effect = effect;
_matrix = transformMatrix;
// Setup things now so a user can chage them.
if (sortMode == SpriteSortMode.Immediate)
Setup();
_beginCalled = true;
}
public void Begin (SpriteSortMode sortMode, BlendState blendState)
{
Begin (sortMode, blendState, SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Matrix.Identity);
}
public void Begin (SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState)
{
Begin (sortMode, blendState, samplerState, depthStencilState, rasterizerState, null, Matrix.Identity);
}
public void Begin (SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect)
{
Begin (sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, Matrix.Identity);
}
public void End()
{
_beginCalled = false;
if (_sortMode != SpriteSortMode.Immediate)
Setup();
#if PSM
GraphicsDevice.BlendState = _blendState;
_blendState.ApplyState(GraphicsDevice);
#endif
_batcher.DrawBatch(_sortMode);
}
파일이 완전하지 않습니다, 당신은 전체 파일을 읽으려면 내가 최종 함수 뒤에 붙여하지만하지 않았다. 링크는 다음과 같습니다. https://github.com/mono/MonoGame/blob/7ec1ec8a0e924eca60588e770121ed3e2593e74d/MonoGame.Framework/Graphics/SpriteBatch.cs
이 소스 코드가 여러분이 찾고 있었기를 바랍니다.
행운을 빈다.
이 내 다른 대답 :
당신은 당신이 실제로 그릴 수 있도록 기본 그리기에() 함수를 spriteBatch.Begin()와 spriteBatch.End()를 호출 할 필요가있다.
연신() 기능은 Game1.cs에서 :
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// Start drawing
spriteBatch.Begin();
player.Draw(spriteBatch);
// Stop drawing
spriteBatch.End();
base.Draw(gameTime);
}
연신() 함수에 Player.cs :
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(playerTexture, playerPosition, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 1f);
}
것은이 그리는 것 여기
은 일례이며 Player.cs에서 Draw() 함수가있는 화면의 플레이어. spriteBatch는 Game1.cs의 LoadContent() 함수에서 초기화됩니다.이 도움이 되었기를 바랍니다.
0
개체에 대한 "그리기"를 직접 만들고 "Game1.cs"의 "그리기"내에서 개체를 호출 할 수 있습니다.
예 :
protected override void Draw(GameTime gameTime){
myObject.Draw(gameTime);
}
희망이 도움이!
관련 문제
- 1. CoffeeScript에서 익명 제곱 함수를 작성할 수 있습니까?
- 2. 암시 적 인수가있는 함수를 작성할 수 있습니까?
- 3. if else 문에서 함수를 작성할 수 있습니까?
- 4. 함수를 사용하는 대신 쿼리로 작성할 수 있습니까?
- 5. 문자열 화하는 C++ 함수를 작성할 수 있습니까?
- 6. iconv_substr없이 php 함수를 재 작성할 수 있습니까?
- 7. C에서 _alloca와 유사한 함수를 작성할 수 있습니까?
- 8. addEventListener에 "새로운"익명 함수를 전달할 수 있습니까?
- 9. 클라우드에 코드를 작성할 수 있습니까?
- 10. SpriteBatch.Begin 및 SpriteBatch.End
- 11. 'with'문에서 호출되는지 여부를 감지하는 함수를 작성할 수 있습니까?
- 12. 표준 sql에서이 pgplsql 함수를 어떻게 다시 작성할 수 있습니까?
- 13. 중복 회선없이 비 반복적으로이 함수를 작성할 수 있습니까?
- 14. n 차원의 배열을 취할 수있는 함수를 작성할 수 있습니까?
- 15. 어떻게 C++에서 일반 정렬 함수를 작성할 수 있습니까?
- 16. 숫자 형식 만 허용하는 .NET의 제네릭 함수를 작성할 수 있습니까?
- 17. 형식을 취하여 다른 형식을 반환하는 함수를 작성할 수 있습니까?
- 18. 어떻게 내 가상 코드의 재귀 함수를 작성할 수 있습니까?
- 19. lisp에서 매크로처럼 재귀 함수를 재 작성할 수 있습니까?
- 20. 자바 함수를 호출하는 ant 대상을 작성할 수 있습니까?
- 21. C# 에서처럼 우아하게 순열 함수를 작성할 수 있습니까?
- 22. 어떻게이 urllize 함수를 자바 스크립트로 작성할 수 있습니까?
- 23. SpriteBatch.Begin 및 .END 중복
- 24. SpriteBatch.begin() 및 end() 호출
- 25. Grails에서 Spring을 작성할 수 있습니까?
- 26. Javascript로 컴파일러를 작성할 수 있습니까?
- 27. 어떻게이 쿼리를 작성할 수 있습니까?
- 28. CURSOR없이이 쿼리를 작성할 수 있습니까?
- 29. Groovy에서 어노테이션을 작성할 수 있습니까?
- 30. SpriteBatch.begin/end에 중첩 ShapeRenderer.begin/end
감사합니다. 이것은 내가 필요한 것입니다. 빠른 질문 ... SpriteBatch에서 클래스를 파생시키고 해당 파생 클래스에 Draw 함수를 숨기고 있지만 여전히이 새 함수에서 base.Draw를 호출하는 데 문제가 있습니까? –
새로운 spriteBatch.begin() 함수를 작성하는 것과 비슷한 것을 시도한 적이 없으므로 미안하다는 점을 알려 드릴 수 없습니다. 행운을 빕니다!! – Basecrosser