Joined: 12/27/2013(UTC) Posts: 11 Location: Bayern
|
Hi!
I'm quite stuck at the beginning - but I'm not sure if I'm just missing something.
I want to create an entity - basically a Card - with some dynamically added parts of that Card. So I want to just create the Card-entity with the constructor and it should create itself by adding some sprites to it's graphical represantation.
But how to do those nested entities? How can I place one Sprite (or entity) within another and have some properties like the Location and the size of the parent-entity projected on the nested ones?
Thanks for your help!
Best regards,
TopperDEL
|
|
|
|
Joined: 8/23/2011(UTC) Posts: 245
Thanks: 6 times Was thanked: 12 time(s) in 11 post(s)
|
The simplest way to do it would probably be as follows:
- Derive Card from Entity2D or Sprite. - Add a List of Sprites as components to your instance of Card when appropriate (your dynamically added parts) - Overwrite the DrawArea method in Card to update the DrawArea of each of the sub-component Sprites - Repeat for any other applicable properties (eg. Rotation)
At one point automatically making some properties of parent entities 'project' to child entities was considered, but it's not always wanted behavior - eg. if the color of the parent changes should the color of the child automatically change? etc. etc. So in the end it's just simpler and easier to leave the coder to do it when its applicable.
Hope this helps!
|
|
|
|
Joined: 12/27/2013(UTC) Posts: 11 Location: Bayern
|
Sorry, I don't really get your answer.
First of all: how do I overwrite the DrawArea-Method? Where do I find info about this Method and what it does?
Can you give me a short example on how to render a subcomponent-sprite in the area of the parent-sprite at a specific X/Y-Location in relation to the topleft-corner of the parent?
Thank you very much!
|
|
|
|
Joined: 7/22/2013(UTC) Posts: 13
Thanks: 1 times Was thanked: 2 time(s) in 2 post(s)
|
Originally Posted by: TopperDEL  Sorry, I don't really get your answer.
First of all: how do I overwrite the DrawArea-Method? Where do I find info about this Method and what it does?
Can you give me a short example on how to render a subcomponent-sprite in the area of the parent-sprite at a specific X/Y-Location in relation to the topleft-corner of the parent?
Thank you very much! Hi, I think he didn´t mean literally "to overwrite the DrawArea-Method". You need to take care of the visibility of the entities, which should be drawn. On 2D-applications you have to create your "container"-class (e.g. derrived from the Sprite-Class). Within this class you can add a List with additional sprites. Your "main"(container)-Sprite-Class has the Properties: DrawArea, Center, Size and so on. So you can place the child-Sprites within the DrawArea of your main-Sprite. Its visibility you can take affect of, by the Visible- and the Renderlayer-Property. short example: Code:
public class ContainerSprite : Sprite, Updateable
.
.
private List<Sprite> childList;
// Initialisations:
// set measures:
DrawArea = new Rectangle(......
RenderLayer = 1;
// set children
// childList[0] = new Sprite(...
childList[xx].Renderlayer = 2;
childList[xx].Visible = false;
//update loop of your container
void update(...)
if(askdjfaskd == false)
childlist[xx].visible = true;
That´s it
|
|
|
|
Joined: 8/23/2011(UTC) Posts: 245
Thanks: 6 times Was thanked: 12 time(s) in 11 post(s)
|
Originally Posted by: TopperDEL  Sorry, I don't really get your answer.
First of all: how do I overwrite the DrawArea-Method? Where do I find info about this Method and what it does? Sorry, I meant override the DrawArea property, not DrawArea method (and I meant override not overwrite! haha) This is a short example in code: Code:
public class Card : Sprite
{
public override Rectangle DrawArea
{
get { return base.DrawArea; }
set
{
base.DrawArea = value;
foreach (var subcomponent in subcomponents)
subcomponent.DrawArea = value;
}
}
private List<Sprite> subcomponents = new List<Sprite>();
}
So whenever Card's DrawArea changes (moves/resizes), all subcomponent DrawAreas will change along with it. Then just add and remove sprites from 'subcomponents' when appropriate. (If you wish you can add the subcomponent list as a component of Card but it isn't necessary for the code to work.) Sorry for any confusion caused! Edited by user Wednesday, January 1, 2014 4:32:51 PM(UTC)
| Reason: Not specified
|
|
|
|
Joined: 12/27/2013(UTC) Posts: 11 Location: Bayern
|
Override the DrawArea-Property does not work. But by using the Updateable-Interface I could simply adjust the TopLeft- and Size-Properties on my subsprites. I think I got it now. I just was "auf dem Schlauch gestanden". ;)
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.