Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (805)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Rendering Multi-Layer Tilemap w/ Animations  (Read 335 times)
0 Members and 1 Guest are viewing this topic.
Offline clemensr

Junior Newbie


Exp: 2 years



« Posted 2020-03-20 04:24:57 »

Hey everyone,

I'm working on a rather large 2D tile based game similar to a 2D zelda in style. I recently redid my maps and map editor to allow for more layers so that I could have an upstairs/downstairs type system going like in Zelda, link to the past. But now I am having trouble rendering a lot of layers on a map where some of them are animated and some aren't and I have a couple issues/questions.

Also, I'm programming the "game engine" as well this is a learning experience and it was going extremely well but I keep finding cool things I think I can add and this last one has become a major problem.

Dynamic Animated Tile Maps & High Frame Rates
A map usually has around 5-7 layers, but MOST of the tiles on the layer is empty especially when you get to the top layers. So in order to speed up FPS I started having the layers render to their own BufferedImage same size as the Graphics object's dimensions, then render that image to the screen each frame so it didn't redraw every tile. This got my frames up to 200 or so again. However that is making it rather difficult to have only a handful of tiles redraw if they're animated on a given frame. The maps have a Tileset class that has the tile images for all the tiles in it and I know one problem is scaling up those images each frame to draw.

Map Classes: All graphics tiles hold integer ids for the tile that they render, animated tiles simply have list of ids.

- Tile<T>
      - GraphicsTile<Int>
            - AnimatedTile
- TileLayer<Tile>
      - GraphicsTileLayer<GraphicsTile>
- TileMap

Scene classes: Handle rendering objects to screen. There are others besides these. They all worked beautifully besides this problem.

- Scene (abstract)
      - TileLayerScene
      - TileMapScene (list of TileLayerScenes)
- SceneEvent
- SceneObserver interface
      - SceneAdapter (implemeted version of SceneObserver)

The general rendering order is following:
(1) Game state tells current scene to render (TileMapScene)
(2) TileMapScene will either (a) draw it's buffered image if no changes were made or (b) redraw all the TileLayerScenes
(3) TileLayerScenes will either (a) draw its buffered image if no changes or (b) redraw all GraphicsTiles (doesn't need to know if its animated or not, that's handled in update() method call part of game loop)
(4) GraphicsTiles are drawn by the TileLayerScene getting the integer id, then accessing the Tileset that it has, grabbing that image, and rendering it.


So I'm trying to figure out what is the best concepts to implement when it comes to getting the fastest rendering time while still having tile maps that have a lot of layers and dynamically changing or animating tiles? I'm also trying to keep the Scene packages decoupled as possible from the rest of the game so I don't want to do what most of these engines do now a days and pass references to everything in every object. I can't figure out how to approach this. Any insight would be greatly appreciated!

THANKS!!
Offline clemensr

Junior Newbie


Exp: 2 years



« Reply #1 - Posted 2020-03-20 19:46:33 »

* UPDATE *

Okay, I've made some improvements.

(1) Added a SceneTile class:
This does for GraphicsTile and AnimatedTile what the others did for Layers. Basically wrapped a map tile in a Scene class, so that it could be observed by the TileLayerScene (through SceneObserver interface). So the SceneTile will update, and if the id of the tile image changes it will notify it's oberver (the TileLayerScene), then the TileLayerScene.

(2) TileLayerScene update:
When the TileLayerScene gets a callback from the SceneTile that changed it's image, it will redraw its full layer and then notify it's observer that it has redrawn, which it's observer will be the TileMapScene

This has gotten me full animated tiles without having to know where they are, and a frame rate of 170-180 frames!

I'm happy with the fact that the Scene objects are still only observing the actual physical Map and Tile objects and they don't know anything about how they're being rendered .....but, still have no idea if this is smart to do, or if there are techniques and concepts i'm oblivious to how other game designers or engines do this and I still love to know if any of you have thoughts on this?
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (585 views)
2019-09-04 15:33:17

hadezbladez (5526 views)
2018-11-16 13:46:03

hadezbladez (2407 views)
2018-11-16 13:41:33

hadezbladez (5788 views)
2018-11-16 13:35:35

hadezbladez (1228 views)
2018-11-16 13:32:03

EgonOlsen (4667 views)
2018-06-10 19:43:48

EgonOlsen (5685 views)
2018-06-10 19:43:44

EgonOlsen (3200 views)
2018-06-10 19:43:20

DesertCoockie (4102 views)
2018-05-13 18:23:11

nelsongames (5118 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!