flashinpan

Members
  • Content count

    594
  • Joined

  • Last visited

Community Reputation

100 Neutral

About flashinpan

  • Rank
    Advanced Member

Personal Information

  1. SharpDX and image annotation?

    We're trying to increase the speed of the annotation. It has been using GDI+. It seems the next gen technology is Direct2D and that the C# version is a wrapper named SharpDX. Would it really take that much code to do what GDI+ is able to do in 2 lines? I'm not familiar with SharpDX, so I'm asking.
  2. Does anyone know how you would do simple text annotation using "SharpDX" library (for C#)? Here is how GDI+ does it currently in my app (in particular, the bold red lines are of interest): using (Graphics g = Graphics.FromImage(bm)) using (SolidBrush solidWhiteBrush = new SolidBrush(Color.White)) using (SolidBrush solidBlackBrush = new SolidBrush(Color.Black)) { // Write out annotation text [color=#ff0000][b] g.FillRectangle(solidWhiteBrush, 0, 0, bm.Width, bm.Height);[/b][/color] [color=#ff0000][b] g.DrawString(AnnotationText, AnnotationFont, solidBlackBrush, new PointF(7f, 2f));[/b][/color] Thank you for sample code showing how this would be done using SharpDX! Tom
  3. spritesheet generation

    I can make the individual images, but I need help creating a spritesheet. Can someone recommend a tool that they use for this that they like using that is easy to use?
  4. spritesheet woes

    I've read your most recent post, and I will try to implement your suggestions as soon as I can. Just need to find some quiet time...which is sometimes in rare quantities....
  5. [answered] Animated Sprite not working

    [quote name='Auskennfuchs' timestamp='1324816837' post='4897256'] So is it working properly now? Instead of hardcoding your height and width you can also write: [code] int width = Texture.Width / Rows-1; int height = Texture.Height / Columns-1; [/code] 256/8-1 = 31 32/1-1 = 31 [/quote] I'll be sure to try that suggestion next chance I get (currently at work) Tom
  6. spritesheet woes

    I am struggling with making my sprite sheets work correctly. It seems like every time I make a small change, like adding a few more cells to an animation sequence - I start to get some "drift" in the animation. Instead of the animation staying in one place it kind of moves while it is animating. I hope somebody knows what I am talking about. Sometimes playing with the width of the destination rectangle seems to adjust it and fix it, but not this time. Are there tools that can help me create and maintain stable dependable spritesheets?
  7. [quote name='Tsus' timestamp='1324716005' post='4897033'] [quote name='flashinpan' timestamp='1324694350' post='4896982'] I was wondering if there was a way to add more of a delay once the frame hits frame 4. The reason I ask is that on frame 4 the power "light" has hit the max intensity before it fades again and I want it to stay "fully lit" for longer than the other cells in the sequence. I just think it makes the power source "pulsing" look cooler. How can I do that? [/quote] The trick would be to manipulate the progress of the time. You can keep a variable that stores “your” totally passed time and with every update you add the elapsed time since the last update, but (here it comes) if your currentFrame == 4 then you add only a fraction of it. This way it takes you longer to leave the time window of frame 4. So store in some member of the AnimatedSprite that total time: [code]double virtualTotalTimeInMsecs = 0;[/code] And in the update method you can add: [code]if (currentFrame == 4) virtualTotalTimeInMsecs += gameTime.ElapsedGameTime.TotalMilliseconds * 0.25; else virtualTotalTimeInMsecs += gameTime.ElapsedGameTime.TotalMilliseconds;[/code] And change the previous code to this: [code]int frame = ((int) virtualTotalTimeInMsecs ) / updateRateInMsecs;[/code] This is rather a hack, though. However, if you want to change the animation speed you have to manipulate the time somehow. Hope this helps! [/quote] Worked like a charm!!! Thank you very much for your help. Tom
  8. [quote name='Tsus' timestamp='1324688651' post='4896968'] Hi! [quote name='flashinpan' timestamp='1324660211' post='4896853'] I want to slow down the frame rate...it is really fast. [/quote] At the moment you update you animation [b]every[/b] frame. Usually you want animations to be played in a certain rate measured per milliseconds (to make them independent from the performance of your game, since this depends among other things on the hardware). You can get the total elapsed time since start of your application from the GameTime object that is a parameter of the Game’s update method. You can pass it to the update method of your AnimatedSprite and do something like this: Store in some member of your Animator: [code] int lastFrame = -1;[/code] And in your update: [code] int updateRateInMsecs = 500; // update each 500 ms int frame = ((int)gameTime.TotalGameTime.TotalMilliseconds) / updateRateInMsecs; // compute the frame we are in. if (frame != lastFrame) // are we in a new frame now? { currentFrame = frame % totalFrames; // compute the number of the frame to show. } lastFrame = frame; // memorize for the next pass.[/code] [quote name='flashinpan' timestamp='1324660211' post='4896853'] I set the background color to "CornflowerBlue" so that the background of the cell would blend in with the background, but it ended-up adding a slight blue tint to the image as well. How can I prevent that? [/quote] The last argument of the draw call is the tint color (usually set to white). This color is multiplied with your texture when it is rendered. By this you can implement by very simple means different colors for teams or add some diversity to objects. It is not meant to define a transparent color. If you want to remove the white borders you have to add an alpha channel to your textures (many image editing tools can do that). Then you have to enable alpha blending, by specifying the following arguments when drawing: [code]spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);[/code] Actually it would be better to use an Alpha Test for that, since it rejects pixels based on their alpha value if they are below or above some specified threshold. The test is much faster than blending, but in XNA 4.0 it was removed, because it is deprecated in modern DirectX. You’d have to do the test manually in a shader or use the built-in AlphaTestEffect. For starters, I’d recommend sticking with blending until you hit performance problems or feel ready to take the leap to shader development. Hope this helps! [/quote] Okay....I think I have the delay down now. Thank you. I am still struggling with the blue tint thing. I tried adding those params as you suggested to the Begin method of the spriteBatch, but it did not seem to work right. The .png is actually saved with a transparent background, not a white background. Does that make a difference in your advice? Are you saying that if I had saved the png with a White background instead of a Transparent background this suggestion of yours would have worked??? I'll keep experimenting, but I am hoping for a reply from you. Regardless...thanks for the help with the timing. [[EDIT]] - [color="#FF0000"]UPDATE: Actually....the .png was NOT saved with a transparent background, it WAS saved with a White background. Once I saved it with a transparent background it began working and looking as it was intended....so that is sorted out now...thank you!! This still remains a question though: [/color] Oh....one more thing on the timing.....I was wondering if there was a way to add more of a delay once the frame hits frame 4. The reason I ask is that on frame 4 the power "light" has hit the max intensity before it fades again and I want it to stay "fully lit" for longer than the other cells in the sequence. I just think it makes the power source "pulsing" look cooler. How can I do that?
  9. [answered] multiplayer xna games?

    [url="http://www.youtube.com/watch?v=N-VgBMzO25g&feature=mfu_in_order&list=UL"]xna chat and multiplayer[/url] For clarity, the above link gives the essentials of what I am looking for. So...yes it is possible....just looking for source code at this point. Thank you for the posts and guidance so far! I really appreciate all the help! Tom
  10. [answered] multiplayer xna games?

    [quote name='Hyunkel' timestamp='1324166454' post='4894903'] Unless you want to use LIVE, which I assume you are not since you aren't targeting the 360, networking will be identical to any other C# application, so you don't necessarily need to look at XNA examples. Of the top of my head I can only think of Terraria, which uses XNA and has multiplayer support, but I'm sure there's quite a few more. If you want to use UDP I can recommend "lidgren-network" [url="http://code.google.com/p/lidgren-network-gen3/"]http://code.google.c...n-network-gen3/[/url] which I have used with XNA before. [/quote] Yeah...I don't want to use LIVE (I take it that LIVE is only available for the xBox 360...PC games written with XNA can't use LIVE?). I'll check-out Terraria, thx. So, given that my choices are UDP / TCP-IP etc. --- are there wrappers or 3rd party components that can make the talking back and forth between two players easier? For example...are there xna code snippets or tutorials that show how two xna games can talk to each other....both real time chat (so you can trash talk, etc.) as well as internal communications that the players do not see (like game board updates). I am also interested in hosting a site where people who are available to play a game can see other players who are waiting to play and join a game.
  11. embed movie clips

    Can we / are we allowed to embed movie clips in our posts? Like if I wanted to share a short movie clip showing some sort of demo from my game? How is this done? I know how to share a link to a movie on You Tube, but not how to embed the movie inside my post. Thank you, Tom
  12. The following code displays a simple cell animation from a spritesheet. I have some questions on how to modify my code to do the following: -I want to slow down the frame rate...it is really fast. -I set the background color to "CornflowerBlue" so that the background of the cell would blend in with the background, but it ended-up adding a slight blue tint to the image as well. How can I prevent that? Here is my current code: First, the sprite sheet: [img]http://3.bp.blogspot.com/-sNi8hII4Pdc/Tu67eCtamFI/AAAAAAAAAR0/u1zdNWj8a-w/s320/powersourceanimated1a.png[/img] main source [code] 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 XNARobotz { /// <summary> /// This is the main type for your game /// </summary> public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; AnimatedSprite animatedSprite; private Texture2D powersource1; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } /// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); } /// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); powersource1 = Content.Load<Texture2D>("powersource1"); Texture2D texture = Content.Load<Texture2D>("powersourceanimated1a"); animatedSprite = new AnimatedSprite(texture, 1, 8); // TODO: use this.Content to load your game content here } /// <summary> /// UnloadContent will be called once per game and is the place to unload /// all content. /// </summary> protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } /// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); // TODO: Add your update logic here animatedSprite.Update(); base.Update(gameTime); } /// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here spriteBatch.Begin(); spriteBatch.Draw(powersource1, new Rectangle(0, 0, 32, 32), Color.White); spriteBatch.End(); animatedSprite.Draw(spriteBatch, new Vector2(100, 100)); base.Draw(gameTime); } } } [/code] class to support the cell animation [code] using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework; namespace XNARobotz { public class AnimatedSprite { public Texture2D Texture { get; set; } public int Rows { get; set; } public int Columns { get; set; } private int currentFrame; private int totalFrames; public AnimatedSprite(Texture2D texture, int rows, int columns) { Texture = texture; Rows = rows; Columns = columns; currentFrame = 0; totalFrames = Rows * Columns; } public void Update() { currentFrame++; if (currentFrame == totalFrames) currentFrame = 0; } public void Draw(SpriteBatch spriteBatch, Vector2 location) { //int width = Texture.Width / Rows; //int height = Texture.Height / Columns; int width = 31; int height = 31; int row = (int)((float)currentFrame / (float)Columns); int column = currentFrame % Columns; Rectangle sourceRectangle = new Rectangle(width * column, height * row, width, height); Rectangle destinationRectangle = new Rectangle((int)location.X, (int)location.Y, width, height); spriteBatch.Begin(); spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.CornflowerBlue); spriteBatch.End(); } } } [/code] Also, here is a short movie showing the above code running in the XNA IDE: [url="http://www.youtube.com/watch?v=62PZwZUCtgQ&feature=youtu.be"]robotz anim demo[/url]
  13. [answered] Animated Sprite not working

    [quote name='Auskennfuchs' timestamp='1324317900' post='4895382'] How your current result looks like? Is the sprite flickering? After a quick look I would guess your Framecounter is way too fast. You go to next Spriteframe every Draw-Frame of your application. So if you have 60fps you rotate your Sprite 7,5 times. First try would be to make your currentFrame a float and add in Update just the elapsed Time. To calculate your Frame cast it to int. Then you can vary the speed of animation by dividing or multiply some value. And your animation is "time-safe" [/quote] Auskennfuchs: Thank you for your reply. Here's an update on this problem: The two lines of code commented-out at the top were the original lines (the cause of the problem) and the next 2 lines that follow (where width and height are hard-coded) are my fix. [code] public void Draw(SpriteBatch spriteBatch, Vector2 location) { //int width = Texture.Width / Rows; //int height = Texture.Height / Columns; int width = 31; int height = 31; int row = (int)((float)currentFrame / (float)Columns); int column = currentFrame % Columns; Rectangle sourceRectangle = new Rectangle(width * column, height * row, width, height); Rectangle destinationRectangle = new Rectangle((int)location.X, (int)location.Y, width, height); spriteBatch.Begin(); spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.CornflowerBlue); spriteBatch.End(); } [/code]