Im creating a rpg like game, I've made a list of items that contains alot of variables like:
Item type
Name
Weight
ItemID
Dmg
I want so that when you over your mouse over an item, a tooltip will appear telling you all the variables of that item, sorta like WoW and all the other rpg games.
I've been thinking about having a rectangle texture that stays on mouse position and will only be shown when mouse over an item.
Now here comes the part where im having problem. I do not know how to scale the texture depending on the amount of text and variable length of that item, so it doesn't look wired. Also is it possible to use some sort of loop that can loop through all my variables and put them under each other?
Cheers!
/Iskalder
Are you using a Texture (or Textures) for the text or a font to display the text?
For question 1. If you're using a Texture, you can get the height and width pretty easily and adjust the scale of the tooltip accordingly. If you are using a SpriteFont, you can use SpriteFont.MeasureString to get it's dimensions.
For question 2.
As for drawing the items on top of each other, if you are using a SpriteBatch, you can specify how to layer the items in the SpriteBatch.Begin and SpriteBatch.Draw overloads. If you don't mean to layer the variables/items and just want to display them so that they appear "stacked" on top of each other, you can simply specify the origin at which to draw the item in SpriteBatch.Draw and have each subsequent item drawn at a different height (y coordinate).
Related
I've been working on a proper slider for my C# WPF project.
I wanted to create a slider, with a background that indicates different parts of the process, by adding a different color to each section on the slider. Furthermore I wanted to add small indicators (like the default ticks, but custom shape and irregular position) to the background.
I achived this by creating a drawing brush and adding correspondingly colored rectangles. This seemed to work fine, but a small distortion was still present, so I investigated further and realized the following:
With slider.ActualWidth I get the width of the whole widget. So in order to create a background covering the actual "slider" part, I'll have to be aware of the distance from the widget to the actual slider. (See image)
I measured the distance in a very small window, in fullscreen and stretched on two screens. It seems this distance is always 5 pixels. I tried google and looked through the info WPF provides on its pages, but either I read over it, or there is no information on this.
Can I be sure this distance is always 5 pixels ? In there any place such information is kept ? Is there maybe another way, to determine the size of the slider itself?
Assuming you haven't tinkered with the Slider template you can just walk down the visual tree and check the ActualWidth of the track:
Border b = VisualTreeHelper.GetChild(slider, 0) as Border;
Grid g = VisualTreeHelper.GetChild(b, 0) as Grid;
Border track = VisualTreeHelper.GetChild(g, 2) as Border;
Console.WriteLine("Track ActualWidth: " + track.ActualWidth);
Say, I have some images drawn on screen, like in any average XNA project. Is it possible to make it so that only a selected array of triangles of the image is visible? Here's an example:
The red lines outline the triangles in the array. The blackness is completely hidden from view.
I tried googling and didn't find anything, so I hope this is even possible.
If you want to make a mask like that, you could have a sprite that's the exact shape of the blackness (bonus if you make that shape dynamic ;)). Have it drawn in a layer above whatever you want to hide.
You can use the VertexPositionTexture class.
Then use a mask consiting of a VPT for each triangle in you array to reveal the parts of your texture you want visible.
An example of how you can use it:
enter link description here
I have a UIImageView as a subview of a UIScrollView, the image view is filled using a CGBitmapContext which is drawn to using a DrawTileAtIndex method.
In order to increase performance, I would only like to draw those tiles that are visible, is there any way I can detect how much of my UIImageView is currently visible to the user? I.E What area, pixels etc If so, how do I detect this in order to draw the correct tiles?
CATiledLayer is not an option.
Thanks in advance,
Jack
Assuming you have an image that is larger than can be viewed at any one time, then create a UIView subclass with the image as a property. When you are sent drawRect:, then you can use the passed in rect to test your tiles against, and only those tiles that overlap that rect need to be drawn.
You can use the 'CGRectIntersectsRect' function to do the test.
I am developing a game similar to atomica in C# and WPF. I have a 4*4 grid in which three random images are generated. I must move image from present position to some other position in grid. I have starting position and end position of grid cell number and I have the path through which image or object must move through grid cells.
Here I am not able to animate to move the image first in x-direction for two cells then y-direction for one-cell and then one-cell in x-direction and so-on, so that I am able see the path in which the image is moving.
Please help me guys.
I think this: Improve animation smoothness (moving of controls) is a good solution also with suggetions how to make the animation smooth.
I am writing a program to control a mobile robot. One of the things it has to do is to draw a map of the "world" as the robot senses it and apply changes in the map as it senses them.
It also has to highlight in some way the location of the robot and (ideally) the direction it points to.
I currently have an auto-updating array (100 x150) representing the map, using the following representations: 0 represents a clear path, 1 represents an obstacle.
I also have a variable containing the robot's location and next location.
What I need is to visualize it. I thought about using labels, but it is way too tedious using them, and the end result is not so pretty. My other possibility is to write all that data into an Excel spreadsheet, but then I will be back to square one: visualizing the data in an attractive way. Is there a drawing package of some sort that can do the job?
To sum it up:
Using:
- int[] MapArray //100 x 150 array representing the robot's world, and the data there is changing.
- Point[] Locations //Locations[0] is the current location, Locations[1] is the next step.
And I want to draw a map on a Windows Forms application that updates itself in a nice visual manner.
I hope my question is clear enough, don't hesitate to contact me if not!
Try Code: Drawing a Filled Rectangle on a Form (Visual C#) or something similar.
Graphics Programming Example Topics
Just write a couple of cycles which accesses every cell of an array and draws a rectangle on a form according to coords - that's the simplest way.
for(int i=0; i<100; i++)
{
for(int j=0;j<150;j++)
{
<access[i,j] and draw a rectangle with color accordingly to your contents.>
}
}
The same for the drawing location.
If you don't find any nice controls, you can always use a DataGridView with the column width = row height so that it always displays square cells. After that, just change the background color of the obstacles.
You could also look into observable collections for the map array so that the grid updates based on events rather than on timers. Make sure that you overwrite the observable collection to send the CollectionChanged event even when a cell changes its value, not only when adding/removing cells.