[java] Draw method, how to draw map

Started by
5 comments, last by D3Sphil 20 years, 2 months ago
I am working on a tile-based game which has to draw a map. I know how to do this alright, but once i add animation, is there any way to not have to keep re-drawing the map each frame? I have an animated character that walks over the map, and thus at the moment I am updating the screen when he walks and I have to re-draw the map each time.. is there any way to not have to do this? Or is there any way to increase the speed, because draw the map is eating up a lot of CPU.
rm -fr /
Advertisement
I''d like a look at the code, but what I''d do would be to have a boolean global that determines if the map needs updated via some random method, then an ''if'' statment inside the paint() method.
But I''m fairly new to Java, so I don''t know how much that fixes the CPU problem.

Hope this helps,
~Justin
Curse you windows and your poor explanation of my errors!!!
You could just redraw the map characters the player over laps

That would save some time, of course for lots of players then you should also check if a square has already been redrawn and there is a point when you have X players and it''s quicker to do a full redraw of the map.

If you are scrolling the map then it is also easier to redraw the entire map as well and you can draw ontop of it as much as you like.

:-)
ujhkfkfk
well, i plan to be scrolling the map, and I also plan to have like 5 plus player as well, so I suppose I will just re-draw the map
rm -fr /
1. Keep track of where the map was obscured and only redraw that portion.

2. Also look at clipping in the Graphics class.

3. Even though you are using tiles, you could draw out the entire map ahead of time and then transfer the portion you need to the screen as needed. You can do this with drawImage of the Graphics class.


First make it work, then make it fast. --Brian Kernighan

The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities. We need men and women who can dream of things that never were. - John Fitzgerald Kennedy(35th US President)

Do not interrupt your enemy when he is making a mistake. - Napolean Bonaparte
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
It''s called dirty rectangles, btw
Investigate using VolatileImages to speed up the tile rendering as well. VolatileImages reside in graphics card RAM; they get blitted to your backbuffer very fast indeed. Assuming you''re using a BufferStrategy etc.

Cas

This topic is closed to new replies.

Advertisement