Reputation: 19 Tradesman
- Active Posts:
- 49 (0.05 per day)
- 19-June 12
- Profile Views:
- Last Active:
- Jun 10 2014 12:43 PM
- OS Preference:
- Favorite Browser:
- Favorite Processor:
- Who Cares
- Favorite Gaming Platform:
- Your Car:
- Who Cares
- Dream Kudos:
20 Apr 2014 - 07:50
18 Apr 2014 - 10:45
03 Mar 2014 - 10:06
01 Mar 2014 - 21:22
06 Jan 2014 - 11:03
22 Jan 2013 - 00:32
21 Jan 2013 - 11:18
24 Oct 2012 - 13:30
20 Oct 2012 - 05:55
11 Sep 2012 - 13:56
Posts I've Made
Posted 13 May 2014On line 6, you have renderTarget == NULL; which I think should be renderTarget = NULL;. That's not causing you any issues at the moment, because the first thing you do after that statement is renderTarget = NULL; anyway, but nonetheless you should correct that, or remove the line altogether.
Also, are you intentionally setting the render target at index 1? I would assume you want to be setting the render target at index 0?
i.e. device3d->SetRenderTarget(0, renderTarget); and device3d->SetRenderTarget(0, windowTarget);
Posted 2 May 2014A common, and very easy, method of doing this is to keep an animation timer which is constantly increased and used to determine which frame of the animation to show. Also, it helps if you have each different animation on it's own row in the sprite sheet.
| WalkingLeft1 | WalkingLeft2 | WalkingLeft3 |
| WalkingRight1 | WalkingRight2 | WalkingRight2 |
| ...etc... | | |
Then when you change which type of animation you need, you set the Y component of the sample rectangle.
As the game runs, update AnimationTimer by the time passed in that frame. (e.g. AnimationTimer += frameTime). Then, your X component can be given as something like SpriteClipX = (AnimationTimer / AnimationFPS) * SpriteWidth
Then, if you change state or if the animation timer reaches greater than SpriteWidth * NumberOfFrames reset AnimationTimer to zero.
(I wrote this quickly on my phone, so there may be some mistakes)
Posted 22 Apr 2014Thanks for this clear answer! I will try to do it that way.
But do I need to create a container (vector) of all the Renderables? And then use sort() on it?
Ah, sorry I was going to mention that in my first reply, but when I saw the code you'd quoted that used the sort I had assumed you'd already done that bit.
Well, my previous answers were based on the assumption you were already using a vector of Renderables, and yes you can do that and it will work fine.
Depending on whether or not you intend to use the same container for anything else, you may wish to choose a different container than a vector (e.g. if you needed to perform fast lookups based on an ID or anything), however based on the scenario you've described I think a vector will be just fine.
Posted 21 Apr 2014Well, from your images it would appear that whichever character (player or non) is further "down" the screen will be infront of those behind it. Therefore, the Y position of the character can also be used to represents its draw order.
So, if you set things in the background to Z=-1 to ensure they will always be drawn first, then anything in the foreground (e.g. things that players/characters will "disappear" behind) to Z=MaxScreenY+1 they will be draw last. Then, for the rest of the scene, the Z position could equal the Y position on screen.
Then, each frame before rendering you sort the Renderables by the Z values that have been set, and draw them one by one.
[Edit] It may also be worth pointing out that you should probably use the "bottom" Y value of the sprites as that's where they appear to touch the floor (Probably SpriteY+SpriteHeight in most cases, as the sprite coordinates tend to be the top-left)
Posted 20 Apr 2014You seem to have mostly solved this, unless I'm missing something in your question...
Can't you just set a Z position and use that to determine the drawing order?
For example, for your NPCs and player, their Z could equal their Y, and for things like the background, or scene elements, they can use a predetermined Z position to keep them behind or in front of other objects as required.
- Member Title:
- New D.I.C Head
- 22 years old
- October 14, 1992
- Full Name:
- Years Programming:
- Programming Languages:
- Website URL: