none
Question about grass style overlays in tile based games

    Question

  •  Hey,

    My tile based system is coming along nicely, although ive just come to a point where im not sure how to get the effect i want in silverlight...

     

    If anyone has used RMXP/VX im sure you will know what im on about but just incase anyone else doesnt, if you imagine having a tile that contains 3 layers.

    The first layer is the ground layer where the player is always displayed on top of, the third layer is above the player and is always displayed that way. However the 2nd layer is the tricky bit, as this is on the same layer as the player. So for this layer it isnt below or above the player, its relative to the players position.

    An example would be if you have 2 players on the screen, if player A is at Y 80 and player B is at Y 90, you would expect player A to take the topmost rendering position and overlay the bottom 10 pixel rows of player B... i would upload some images to show what i mean but i havent got anything but MSpaint on here :(

    In my XNA based game i basically work off the Y value, so when it renders each entity it assigns a layer based on their Y value. Now for Silverlight i could update the Canvas.ZIndex property based on the Y value although i would need to make sure they dont go as low as the ground tile layer, and as high as the overlay layer... which solves that problem.

    However a similar problem occurs with tiles placed on the same layer as the player, now imagine you have a green ground tile put down, but it looks plain and you want to put a 2nd layer of flowers down on that ground tile. So it looks like a flower bed, all fine and dandy, but at this point when the player steps on the flower bed you cant really put the player fully behind the flowers, or fully in front of them, as if you imagine how he would walk through them, his feet would always be covered by flowers but it would never go higher than his feet...

    So in the above scenario if you have a ground tile of 32x32, and a player that is also 32x32 if the player was fully standing on the flower bed in line with the tile you would expect him to either overlay the flowers or be completely covered by them. However im only wanting his feet to be covered... and i dont have a clue how to do this... as it would seem like you would need to draw it in 2 parts, the first part being the flowers that are displayed under the character which have a lower Y value than his feet, then the 2nd part would be the part that should be displayed over his feet which have a higher Y value...

     Without diagrams im sure this just seems like inane babble, so i apologise for that and will try and put a diagram or picture up of what i mean... although if anyone does know what im on about it would be great if you could think of any solution...

    Tuesday, September 22, 2009 3:56 AM

All replies

  • It's been a few decades since I did game programming but it sounds as though you need to split the flower layer into 2 parts.

    Say a split of 75/25. The 25 percent (lower portion) is rendered in front of the player and the 75 behind.

    It's more work but would look and feel better. I've seen a few SL games where the character walking around doesn't look realistic because of what you've mentioned above.

    Tuesday, September 22, 2009 7:17 AM
  •  Hey,

    The 75/25 wouldnt work as if your player was walking down onto the tile and only 10 pixels of him were on the tile and the other 22 pixels were off it you would want the top 10 pixels of the tile to be displayed in front of the player... the opposite could be said for if the player was walking upwards towards the tile. Its head would be the first to touch it and the flowerbed would then need to be displayed behind the player...

    Normally i can see a way to do this sort of stuff, even if it is tricky, but currently the way that silverlight deals with displaying things i cant think of a way to do this... well unless i completely redid everything to work as part of a writable bitmap, but performance on that was dire, so its not really an option...

    Even if i was to render pixel by pixel though i would still need some sort of flag for those sorts of tiles to specify that its a custom render, and it sounds like hell... like you say though, if you really want a *good* looking and feeling game, you cant cut corners and have to implement crazy stuff like this...

    Tuesday, September 22, 2009 7:32 AM
  • Sorry I hadn't grasped the nature of how your char would move about.

    It sounds as though you would need to implement some form of planes or a vertical layer concept, sort've like foreground background layering.

    If you imagine say a tree positioned at the top of the tile (Overlaying into tile above) which would have the lowest z-order. The smaller bushes at the foreground with a higher z-order your char could walk between them. This would negate the need for cutting items into 80/20 etc.

    It's all about perspective really and how the additional elements fit into the overall layout.

    Will be interesting to see how you proceed. Any works in progress to have a look at?

    Tuesday, September 22, 2009 8:08 AM
  • Hey,

    Currently its more of a framework im making rather than a specific game, although i will be wanting to make a game with the framework...

    The tileset sort of system i have implemented is very similar to how RPG Maker works, with the below/overlay/overhead layers, and the player being somewhere between overlay and overhead... Ususally in those sort of games a tree would be split over multiple tiles, so the bottom of the tree would be on the overlay or ground layer, then the top of the tree would be on the overhead layer. However things such as small bushes and ground flora seem to react differently and give this weird masking sort of effect, which gives me this big headache, as how much should be shown behind/infront depends on the amount of content in the level tile and how far over it the player is....

    Im oversimplifying how my levels work in the above post, as its acctually made up of numerous layers that are compressed and baked together to allow for lots of customization while not losing speed due to lots of items on screen. Unfortunatly it uses WCF services behind the scenes and i dont have a MSSQL host online at the moment, only some MySQL ones and they dont let me used stored procs, so i cant hook up my WCF service online to give a preview of how far ive got...

    The framework should be fine for having pre rendered backgrounds or tileset type systems, as (without going too indepth) it allows images of any size to be dumped wherever you want in the scene, so you could have 10 2048x2048 images as backgrounds with some other custom stuff on top with custom triggers at certain points to run scripts. While on the flip side you could have 1000s of 32x32 images dotted around with triggers and animations...

    Currently the game im going to want to make with the framework will ideally have side scrolling style characters with a kinda topdown/isometric background mix, a bit like Gaia Online. That way i can just have mirrored sprites for movement, keeping it simple to create new animations and equipment as well as making players download fewer resources, as one of the main problems im finding so far is that a *common* tile level is about 500kb - 1mb in size (after condensing tiles etc), but then i have to be able to get the players to pre-load scripts/character sprites on the fly for other players, other effects... so its a pain trying to balance how much stuff you force the user to preload and stream as the game plays and how much bandwidth you eat into on the server side and the client side...

    Got lots of work to go yet though :(

    Tuesday, September 22, 2009 8:29 AM
  •  A bit of a rubbish example, i saw a brilliant one the other day... but you can see in this one how their feet are in the grass, but the rest of their bodies are not, and if you imagine them walking into those grass tiles from various different ways it would only overlay the characters feet...

     look at the feet

    Tuesday, September 22, 2009 12:48 PM
  • From that screen shot it looks like they are setting the opacity of the foreground. I wonder if you could just have a transform doing something similar or that might be too much of a cpu hit.

    Tuesday, September 22, 2009 5:34 PM
  •  Yeah they seem to be cheaping out a bit there, as im pretty sure i saw a system that had it spot on when a character walked through flowers... i would only be doing opacity if they were over a certain tile and i could do it in a pixel shader and only target a specific area of the player sprite, so it wouldnt hit the CPU too much i dont think...

    Still it feels like a cop out, but i cant really see any other way of doing it...

    Tuesday, September 22, 2009 6:09 PM