Jump to content
  • Advertisement
Sign in to follow this  
romainechester

Animation that uses one big picture with different drawings in it.

This topic is 5074 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Woooh... It's been a long time since I posted here. Don't surf that much anymore. Anyway, I was wondering how to animate images using one big image. I've seen these in Insaniquarium, where there's a lot of drawings in one bitmap. Hmm... how does one do this in programming. Do you like clip the images or something?? Hmm... Any answer/reply would be appreciated, of course.

Share this post


Link to post
Share on other sites
Advertisement
depends on what you use, with DX and OGL you can just draw part of the image by setting the correct texture coordinates. With something like bitblt i believe you can specify the source rect to draw from into the dest rect again setting the source to part of the image.

HTH

Share this post


Link to post
Share on other sites
You just blit the appropriate frame from the big image to your back buffer/screen/wherever. Most APIs have a command that lets you copy an arbitrary rectangle from one image to another, so no clipping is necessary as long as you know the layout of the big image. Otherwise I think you've got the basic concept right. :)

Share this post


Link to post
Share on other sites
Could use the graphics object in the Paint method and use the 'drawImage' function.

the draw image function has an overload with destination coordinates (dx1, dy1, dx2, dy2) and source coordinates (sx1, sx2, sy1, sy2). Set the destination where you want the image to appear on the screen and the source from where to draw the image from (in respect to the original image). So you could set the source rectangle to a small subsection of the image to draw from (ie one frame of the animation).

HTH

Share this post


Link to post
Share on other sites
In J2ME, you will implement a .paint(Graphics g) method in some Canvas object, which handles screen updates.

Within this method, you will mostly be calling methods on the Graphics object, in order to draw the screen image.

Conceptually, to draw a part of a loaded Image to a location on the Graphics, you need to:

- .setClip() on the graphics at the appropriate location, with the appropriate width and size (according to how much of the Image you want to draw). This "protects" the rest of the Graphics buffer from being painted on.

- .drawImage() with the desired image, offset such that the part of the image you want lines up with that clipping rectangle. The upper-left coordinate of the image should be the upper-left coordinate of the clip rect, minus the upper-left coordinate of the part of the Image that should be drawn. If you have trouble visualizing this, try testing it out with a couple pieces of paper.

- restore the clip again with .setClip() so that future drawing is not affected.

Of course there are optimizations you can do :) You may also find .translate(), etc. methods useful. Getting the best code will require you to Think(TM).

Share this post


Link to post
Share on other sites
Hello... I just want to make an update of what I have posted here and it seems that there's another thing that I want to know.

How do you implement double buffering in J2ME games? I do have an idea on how its done in java applets though. You put the code in the update(Graphics g) method right? I can't seem to make it work on J2ME. I'm making an MIDP game by the way....

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net 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!