Im new to xna. I'm creating a platform game for windows pc only and somehow needs to play an avi file
how can I do this on xna 4.0 or c# 2010?
anyone can help? :)
you can try this creating video player instance
Video video;
VideoPlayer player;
Texture2D videoTexture;
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
video = Content.Load<Video>("video");
player = new VideoPlayer();
}
here is the source of article with more examples
http://msdn.microsoft.com/en-us/library/dd904199.aspx
here are couple more dll
http://scurvymedia.codeplex.com/
http://xnadsplayer.codeplex.com/
This blog has some working code that you can download with xna media players. The project actually puts video on a 3d object (perhaps a little overkill for what you are trying to do), but I can imagine you could study the code that does the video playback to see how it works. There is a VideoPlayer class inside the project; maybe you can give that a look.
Related
So, I'm new to Unity and am trying to set the size of a Video Player, but this task seems so dificult.
Basically I'm loading my video from file using this:
videoPlayer.url = path;
Where the path is a variable that has the path of the video I'm using.
When my video is loaded into the player, it takes all the screen and I can't find a way to set the player dimension to like 100x100.
Found a way to set the dimension using a second camera.
Put my videoplayer inside the cam and set its viewport rect to they way I needed.
I think there has to be an easier way but this worked!
I am trying to access HoloLens camera using WebCamTexture, it works fine on standalone app, I am passing the frames to DLL for image processing but when deployed on HoloLens the communication between the script and the DLL is perfect it also works fine. The problem is I am not able to render the frames on 3D plane.
I tried this code on standalone app as well as on hololens. If tried this code without calling the DLL it worked for me. But when passing the frames to DLL the the 3D plane is missing.
// Use this for initialization
void Start ()
{
webcamTexture = new WebCamTexture();
Renderer renderer = GetComponent<Renderer>();
renderer.material.mainTexture = webcamTexture;
webcamTexture.Play();
data = new Color32[webcamTexture.width * webcamTexture.height];
}
Expected result: I want to display live video on 3D plane on HoloLens.
I am developing an mobile application for Android an iOS with Unity to display panoramic images.
The images are downloaded and saved in the local storage of the device. One image is about 5mb to 10mb.
I am using WWW.LoadImageIntoTexture at start of the app. But if I have more than seven images the app crashes. I figured out that LoadImageToTexture creates images with RGBA32 format. So each texture has about 100mb. So the crash is caused by full memory.
I tried Texture2d.Compress() but it only compresses to DXT1 or DTX5. Android can not handle DXT format.
New idea is to preload the image I want to view next. (Only one image is visible)
I tried to load the texture with a Coroutine. But the app stucks while using WWW.LoadImageIntoTexture about one second. So I tried threading. But WWW.LoadImageIntoTexture can not be executed outside the unity-main-thread.
Is there a way to execute WWW.LoadImageIntoTexture asynchronous? I tried with UniRX from the AssetStore:
public void StartPreloadPanorama(string targetid){
preloadFinished = false;
StartCoroutine (PreloadHandler ());
}
IEnumerator PreloadHandler(){
var preload = Observable.FromCoroutine(PreloadPanorama)
.Subscribe();
while (!preloadFinished) {
yield return null;
}
}
IEnumerator PreloadPanorama(){
//texture is a public string
WWW preloadTexturer = new WWW("file://"+texture);
Texture2D texTemp = new Texture2D (8192, 4096, TextureFormat.RGBA32, true);
preloadTexturer.LoadImageIntoTexture(texTemp);
preloadFinished = true;
//edit - there is some more code after that:
//preloadRenderer is a public Renderer attached to the gameobject displaying the panorama image
preloadRenderer.material.mainTexture = texTemp;
Resources.UnloadUnusedAssets();
Debug.Log("FINISHED");
yield return null;
}
But I still get the stucking...
Any ideas? Thanks!
Edit: according to the comments here is my setup:
I have two spheres, one active, one disabled. (GameObject.SetActive(false))
My camera is inside the spheres. Camera and the two spheres have the position 0,0,0 - you can move the camera by gyro.
There are some buttons placed inside the spheres. If you gaze at a button for 2 seconds the active sphere is disabled and the other sphere is activated. By starting the gaze the StartPreloadPanorama() function is called and a new picture is attached to the disabled sphere.
image size = 2048 x 512px
as what shown on image i uploaded
I don't know what happened with my 2d sprite many people say that was compress problem but i still can't fix it and i tried to use unity asset store 2D pack its look good in my unity, someone ever got the same?
i used photo shop to make these 2D sprite, i used brushes, burn and dodge tools.
public GameObject background;
I am working on a pong clone, and i want to display the player scores onscreen. I don't know how to display it.
The SpriteBatch object has a DrawString method that takes:
a SpriteFont which can be created
in your content project and loaded
via content.Load
the string you wish to write to the
screen
a Vector2 of the position
that you want to draw the text at
the Color you wish the text to be.
So for example your draw method might look like this:
public void Draw()
{
spriteBatch.Begin();
DrawPaddles(spriteBatch);
DrawBall(spriteBatch);
// this being the line that answers your question
spriteBatch.DrawString(scoreFont, playerScore.ToString(), new Vector2(10, 10), Color.White);
spriteBatch.End();
}
See http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.drawstring.aspx
You should start your XNA journey at the XNA Creators Club. Even the most basic tutorials output text.
The XNA Forums are a better resource for XNA-related questions.
MSDN has you covered: How To: Draw Text