Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About flashinpan

  • Rank
    Advanced Member

Personal Information

  1. flashinpan

    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] g.FillRectangle(solidWhiteBrush, 0, 0, bm.Width, bm.Height); [color=#ff0000] g.DrawString(AnnotationText, AnnotationFont, solidBlackBrush, new PointF(7f, 2f)); Thank you for sample code showing how this would be done using SharpDX! Tom
  3. flashinpan

    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. flashinpan

    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. flashinpan

    [answered] Animated Sprite not working

    I'll be sure to try that suggestion next chance I get (currently at work) Tom
  6. flashinpan

    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. 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: double virtualTotalTimeInMsecs = 0; And in the update method you can add: if (currentFrame == 4) virtualTotalTimeInMsecs += gameTime.ElapsedGameTime.TotalMilliseconds * 0.25; else virtualTotalTimeInMsecs += gameTime.ElapsedGameTime.TotalMilliseconds; And change the previous code to this: int frame = ((int) virtualTotalTimeInMsecs ) / updateRateInMsecs; 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. At the moment you update you animation every 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: int lastFrame = -1; And in your update: 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. 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: spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); 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 that is sorted out now...thank you!! This still remains a question though: 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. flashinpan

    [answered] multiplayer xna games?

    xna chat and multiplayer 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. flashinpan

    [answered] multiplayer xna games?

    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. flashinpan

    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 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: main source 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); } } } class to support the cell animation 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(); } } } Also, here is a short movie showing the above code running in the XNA IDE: robotz anim demo
  13. flashinpan

    [answered] Animated Sprite not working

    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. 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(); }
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!