Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline TopperDEL  
#1 Posted : Tuesday, December 31, 2013 4:27:02 PM(UTC)
TopperDEL

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

Wanna join the discussion?! Login to your forum accountregister a new account. Or Connect via Facebook Twitter Google

Offline elasto  
#2 Posted : Tuesday, December 31, 2013 4:41:06 PM(UTC)
elasto

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!
Offline TopperDEL  
#3 Posted : Wednesday, January 1, 2014 2:47:03 PM(UTC)
TopperDEL

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!
Offline ollimorp  
#4 Posted : Wednesday, January 1, 2014 4:16:53 PM(UTC)
ollimorp

Joined: 7/22/2013(UTC)
Posts: 13

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
Originally Posted by: TopperDEL Go to Quoted Post
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
Offline elasto  
#5 Posted : Wednesday, January 1, 2014 4:31:07 PM(UTC)
elasto

Joined: 8/23/2011(UTC)
Posts: 245

Thanks: 6 times
Was thanked: 12 time(s) in 11 post(s)
Originally Posted by: TopperDEL Go to Quoted Post
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

Offline TopperDEL  
#6 Posted : Wednesday, January 1, 2014 5:26:04 PM(UTC)
TopperDEL

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". ;)
Rss Feed  Atom Feed
Users browsing this topic
OceanSpiders 2.0
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.

Powered by YAF.NET | YAF.NET © 2003-2017, Yet Another Forum.NET
This page was generated in 0.070 seconds.