Jump to content

  • Log In with Google      Sign In   
  • Create Account


I have an easy question that's hard to ask Google


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Zerocyde   Members   -  Reputation: 116

Like
0Likes
Like

Posted 14 October 2012 - 11:18 PM

I'll make this simple. Here's what I'm trying to do and how I'm currently doing it. My question is, are there any methods I'm not aware of for doing it better?


Basically I'm working 100% in 2d (directx 9) using textures and sprites. Very simple. I want to draw a square sprite that can be of variable height and width. It's a top-down view of a "room" with "walls" on all 4 sides. Of course you can't just draw that in a bitmap and scale it because the "wall" bordering would be stretched.

So I have 8 bitmaps. The floor, the 4 walls, and the 4 corners. I make 8 sprites, draw the floor scaled to whatever size, then draw the walls and corners in the proper bordering positions. The "walls" are 1 pixel wide so they can be scaled properly. (see attached images)

Is there a better way to do this? Perhaps a way to attach multiple textures to one sprite?

Thanks for any help!

Attached Thumbnails

  • adf.jpg


Sponsor:

#2 Muzzy A   Members   -  Reputation: 594

Like
0Likes
Like

Posted 14 October 2012 - 11:36 PM

you could make Your sprite class have child sprites. And the child sprites draw relative to their parent sprite.

so for your problem


Sprite
{
	 Sprite *parent;
	 Sprite childSprites[];
	
	 void Render();
};

void Render()
{
	 // if you have a parent
	 	 // Draw relative to the parent (parent pos + this pos)
	
	 // else draw like normal
}


Edited by Muzzy A, 14 October 2012 - 11:41 PM.


#3 Arthur Souza   Members   -  Reputation: 1382

Like
0Likes
Like

Posted 14 October 2012 - 11:39 PM

On my engine, using XNA, I use an image of the entire square, with corners and walls.

I made a function to which I can just pass the size of the rectangle I want to draw to a function, and the function will draw the sections of the image, according to the rectangle size.
This is similar to the spritesheet technique or the tileset technique, in which a single image contains several textures, and you draw a section of the image at a time.

Don't know if youre using XNA, but I believe that in whatever you're using, you can select which section of the texture you're going to draw.

Some C#ish pseudocode

void DrawRectangle(Rectangle area, int borderSize)
{
// Rect constructor = Rectangle(x, y, width, height)
// borders
// top left

draw(
  texture,
  new Rectangle(area.X, area.Y, borderSize, borderSize, // where is this going to be drawn
  new Rectangle(0, 0, borderSize, borderSize)); // section of the image to be drawn
// bottom left
batch.Draw(
  texture,
  new Rectangle(area.X, (area.Y + area.Height - borderSize), borderSize, borderSize),
  new Rectangle(0, texture.Height - BorderPadding.Y), (int)BorderPadding.X, (int)BorderPadding.Y));
// top right
batch.Draw(
  texture,
  new Rectangle(area.X + area.Width - borderSize, area.Y, borderSize, borderSize),
  new Rectangle((texture.Width -  borderSize), 0, borderSize, borderSize));
// bottom right
batch.Draw(
  texture,
  new Rectangle(area.X + area.Width - borderSize, area.Y + area.Height - borderSize, borderSize, borderSize),
  new Rectangle(texture.Width - borderSize, texture.Height - borderSize, borderSize, borderSize));
}

Edited by Arthur Souza, 14 October 2012 - 11:47 PM.

A.

Lotus - Action RPG In development http://www.gamedev.n...die-rpg-engine/ |
Personal blog In Portuguese: lotuzgames.wordpress.com |





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS