Timer Problams...

Working on a SwinGame and want to share your progress? Post up a link to your game and let everyone know.

Re: Timer Problams...

Postby mitch on Mon May 05, 2008 7:47 pm

Okay, you wanted to rotate them. The most probabale way that you could do this is by rotating them in the image editor, but this can be quite annoying. Another way would be to find a program that rotates them for you. Or you could do it in memory, by conveting it to another image format... but that is really compelx and time consuming.

Your best option would be to build the image with the rotations already I think, unless you really wanted to do it in memory.
Projects
Spawn (Concept) (SGSDK or SDL.NET) - War ("Alpha") (SGSDK) - PD (SDL.NET)
User avatar
mitch
Master
 
Posts: 90
Joined: Thu Mar 13, 2008 12:26 pm
Location: Hamilton, Victoria

Re: Timer Problams...

Postby Miles on Mon May 05, 2008 8:14 pm

you would think something as basic as rotation would be in the API,...
is there no other way>:? i dont wanna have to compile 8x the # of sprites i other would have to.
Member of Team : "Not Yet Named"
Working on a "Not Yet Named" Top Down Something or other....
User avatar
Miles
Journeyman
 
Posts: 11
Joined: Thu Apr 17, 2008 10:43 am
Location: Melbourne

Re: Timer Problams...

Postby mitch on Mon May 05, 2008 8:16 pm

Miles wrote:you would think something as basic as rotation would be in the API,...
is there no other way>:? i dont wanna have to compile 8x the # of sprites i other would have to.

It wasn't that there wasn't another way, its just that the speed of the solution I have is very slow on large images. But it provides a way of converting it to a format where I can rotate it.
Projects
Spawn (Concept) (SGSDK or SDL.NET) - War ("Alpha") (SGSDK) - PD (SDL.NET)
User avatar
mitch
Master
 
Posts: 90
Joined: Thu Mar 13, 2008 12:26 pm
Location: Hamilton, Victoria

Re: Timer Problams...

Postby Miles on Mon May 05, 2008 8:18 pm

orighty, assume i know nothing and am using small images (all images less than 100x100) already in a .png format.
is there an easy solution to make these rotate?
Member of Team : "Not Yet Named"
Working on a "Not Yet Named" Top Down Something or other....
User avatar
Miles
Journeyman
 
Posts: 11
Joined: Thu Apr 17, 2008 10:43 am
Location: Melbourne

Re: Timer Problams...

Postby mitch on Mon May 05, 2008 8:24 pm

I think that it would be alright, you would get a noticeablt slowdown with alot, but I have never tried it yet. However, I have used to to blur images that are of about 200x200 and got alright speeds from that, so technically you would be able to do something like a rotate.

Hint: You don't use the SwinGame.Bitmap format for this, you convert it to that format when you have what you want. But you can't use create image or stuff, you have to do it another way (*Thinking along the lines of Graphics...*) ;)

If you want, I can post you a bit of code to help you if you want...
Projects
Spawn (Concept) (SGSDK or SDL.NET) - War ("Alpha") (SGSDK) - PD (SDL.NET)
User avatar
mitch
Master
 
Posts: 90
Joined: Thu Mar 13, 2008 12:26 pm
Location: Hamilton, Victoria

Re: Timer Problams...

Postby Pox on Tue May 06, 2008 4:29 pm

mitch wrote:I think that it would be alright, you would get a noticeablt slowdown with alot, but I have never tried it yet. However, I have used to to blur images that are of about 200x200 and got alright speeds from that, so technically you would be able to do something like a rotate.

Hint: You don't use the SwinGame.Bitmap format for this, you convert it to that format when you have what you want. But you can't use create image or stuff, you have to do it another way (*Thinking along the lines of Graphics...*) ;)

If you want, I can post you a bit of code to help you if you want...


It may be a slowdown to rotate sprites using other APIs during runtime, but it's perfectly CPU-efficient to generate an array of pre-rotated images to a certain granularity during loadtime: there's obviously a space-time power/storage tradeoff, but I'm sure a few mb won't hurt anybody.

Here's some code I shamelessly stole from the web and hacked to fit my needs, all you need to do is to convert between the .NET bitmaps and SG's... not hard. ;)

Code: Select all
      private Drawing.Bitmap rotateImage(Drawing.Bitmap b, float angle)
      {
         Drawing.Bitmap returnBitmap = new Drawing.Bitmap(b.Width, b.Height);
         Drawing.Graphics g = Drawing.Graphics.FromImage(returnBitmap);
         g.InterpolationMode = Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
         g.TranslateTransform((float)b.Width/2, (float)b.Height / 2);
         g.RotateTransform(angle);
         g.TranslateTransform(-(float)b.Width/2,-(float)b.Height / 2);
         g.DrawImage(b, new Drawing.Point(0, 0));
         return returnBitmap;
      }
Pox
Journeyman
 
Posts: 12
Joined: Fri Mar 07, 2008 3:41 pm
Location: Virgle City

Re: Timer Problams...

Postby mitch on Tue May 06, 2008 4:53 pm

You could make it write them to the systems temp folder, where they are loaded when needed... you would just need to remove them at the end of it :D
Projects
Spawn (Concept) (SGSDK or SDL.NET) - War ("Alpha") (SGSDK) - PD (SDL.NET)
User avatar
mitch
Master
 
Posts: 90
Joined: Thu Mar 13, 2008 12:26 pm
Location: Hamilton, Victoria

Re: Timer Problams...

Postby Sc4Freak on Tue May 06, 2008 5:04 pm

Pox wrote:
mitch wrote:I think that it would be alright, you would get a noticeablt slowdown with alot, but I have never tried it yet. However, I have used to to blur images that are of about 200x200 and got alright speeds from that, so technically you would be able to do something like a rotate.

Hint: You don't use the SwinGame.Bitmap format for this, you convert it to that format when you have what you want. But you can't use create image or stuff, you have to do it another way (*Thinking along the lines of Graphics...*) ;)

If you want, I can post you a bit of code to help you if you want...


It may be a slowdown to rotate sprites using other APIs during runtime, but it's perfectly CPU-efficient to generate an array of pre-rotated images to a certain granularity during loadtime: there's obviously a space-time power/storage tradeoff, but I'm sure a few mb won't hurt anybody.

Here's some code I shamelessly stole from the web and hacked to fit my needs, all you need to do is to convert between the .NET bitmaps and SG's... not hard. ;)

Code: Select all
      private Drawing.Bitmap rotateImage(Drawing.Bitmap b, float angle)
      {
         Drawing.Bitmap returnBitmap = new Drawing.Bitmap(b.Width, b.Height);
         Drawing.Graphics g = Drawing.Graphics.FromImage(returnBitmap);
         g.InterpolationMode = Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
         g.TranslateTransform((float)b.Width/2, (float)b.Height / 2);
         g.RotateTransform(angle);
         g.TranslateTransform(-(float)b.Width/2,-(float)b.Height / 2);
         g.DrawImage(b, new Drawing.Point(0, 0));
         return returnBitmap;
      }

Yup, this is the same idea I had earlier. IMO, it's the best solution to the problem, since it is customisable and extensible and yet is runtime efficient. Unlike images saved to hard drive, it's quick and easy to add or remove new rotations. And when drawing, it runs at the same speed as any regular old bitmap image, which you won't get with a runtime-generated (as opposed to load time generated) solution.
DevBlog
Adrian Tsai, Micron Game Studios
NextWar: The Quest for Earth
User avatar
Sc4Freak
Journeyman
 
Posts: 41
Joined: Fri Mar 07, 2008 12:25 pm
Location: Melbourne

Re: Timer Problams...

Postby Pox on Tue May 06, 2008 5:09 pm

mitch wrote:You could make it write them to the systems temp folder, where they are loaded when needed... you would just need to remove them at the end of it :D


"When they are needed"? As in at runtime? You can't be loading images from the HDD during runtime, massive slowdowns will ensue... trust me, the difference between a SwinGame.Bitmap and a System.Drawing.Dot.Net.Is.So.****ing.Verbose.Bitmap is miniscule, you can do it all in memory.
Pox
Journeyman
 
Posts: 12
Joined: Fri Mar 07, 2008 3:41 pm
Location: Virgle City

Re: Timer Problams...

Postby Miles on Tue May 06, 2008 6:13 pm

how would i convert a swingame.bitmap to a system.drawing.bitmap or vice verca.

or a way to draw and animate sprites without swingame?

or make swingames sprite api take system.drawing.bitmaps instead of the swingame.bitmaps ??
Member of Team : "Not Yet Named"
Working on a "Not Yet Named" Top Down Something or other....
User avatar
Miles
Journeyman
 
Posts: 11
Joined: Thu Apr 17, 2008 10:43 am
Location: Melbourne

Previous

Return to Projects

Who is online

Users browsing this forum: No registered users and 0 guests

cron