[QUOTE=Funley;33994418]Im having problems sorting textures in XNA during the drawing. This whole drawing code is in a DrawableGameComponent that is created during the first game initialization.
[code]sprite.Begin(SpriteSortMode.Texture, BlendState.AlphaBlend);
sprite.DrawString(guifont, "FPS: " + Math.Round(fps, 2), new Vector2(10, 10), Color.White);
sprite.DrawString(guifont, "Player's world position: " + terrain.playerVirtualPos, new Vector2(10, 30), Color.White);
sprite.DrawString(guifont, "Player's tile: " + terrain.playerTile, new Vector2(10, 50), Color.White);
sprite.DrawString(smallfont, player.brasskeys.ToString(), new Vector2(175, 847), Color.Black);
sprite.DrawString(smallfont, player.silverkeys.ToString(), new Vector2(175, 880), Color.Black);
sprite.DrawString(guifont, player.health + "/" + player.maxhealth, new Vector2(55, 900), Color.Red, 0f, Vector2.Zero, 1.2f, SpriteEffects.None, 1);
sprite.Draw(guitex, new Rectangle(0, 840, guitex.Width, guitex.Height), null, Color.White, 0f, Vector2.Zero, SpriteEffects.None, 1);
foreach (ItemButton ibtn in itemButtons)
{
ibtn.Draw(gameTime, sprite);
if (ibtn.currentItem != null)
{
if (ibtn.currentItem.count > 1)
{
sprite.DrawString(smallfont, ibtn.currentItem.count.ToString(), ibtn.position, Color.Black, 0f, Vector2.Zero, 1f, SpriteEffects.None, 1);
}
}
}
health.Draw(sprite);
player.Draw(gameTime, sprite);
sprite.End();[/code]
The health bar has two sprites that both have to drawn, and the second has to be drawn behind the another. At first, all the GUI objects are drawn correctly, but when one of the ibtns have to draw something more, the health bar draws incorrectly as the sprite behind is drawn on the front. Halp mee![/QUOTE]
Are you drawing two of the same texture at any point?
[QUOTE=reevezy67;33994914]Are you drawing two of the same texture at any point?[/QUOTE] The health bar is drawn from the same texture, just a different color for the bottom texture. And the additional drawings for the ibtns are also from a same texture, just a different part. I also noticed that the text which is supposed to show the count variable of the ibtns is not shown.
[QUOTE=Funley;33994972]The health bar is drawn from the same texture, just a different color for the bottom texture. And the additional drawings for the ibtns are also from a same texture, just a different part. I also noticed that the text which is supposed to show the count variable of the ibtns is not shown.[/QUOTE]
Try creating a new texture for each part.
[QUOTE=reevezy67;33995028]Try creating a new texture for each part.[/QUOTE] Will take memory, but ill try.
[editline]hahalol[/editline]
The health bar drawing worked for 10 minutes, now its broken again. I don't know what could have broken it.
Got the code for Health.Draw()?
strlen is not working on a string variable. This is the error: "no suitable conversion function from std::string to const char* exists"
What am I doing wrong?
[cpp]#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout << strlen(name);
cout << "Enter name: ";
getline (cin,name);
name[0] = toupper(name[0]);
for(int i=0; i <= 10; i++)
{
if (name[i] == ' ')
name[i+1] = toupper (name[i+1]);
}
cout << name << "\n\n";
}
[/cpp]
[QUOTE=WhatTheEf;33995527]strlen is not working on a string variable. This is the error: "no suitable conversion function from std::string to const char* exists"
What am I doing wrong?
[/QUOTE]
You're mixing C-string functions with C++ std::strings. Instead of strlen, use string::length (name.length()). Instead of toupper, use this snippet (and include <algorithm>):
[cpp]
std::transform(name.begin(), name.end(), name.begin(), ::toupper);
[/cpp]
This is using iterators instead of thinking std::string is an array of chars. It goes from the beginning to the end of the string, char by char, calls ::toupper (:: at the beginning means global scope) on every char and writes it into the third parameter. The third parameter is also an iterator, which is incremented by one for every step the function does.
So it basically calls toupper on every character and writes them back into the string.
name.size()
[QUOTE=raBBish;33995596]You're mixing C-string functions with C++ std::strings. Instead of strlen, use string::length (name.length()). Instead of toupper, use this snippet (and include <algorithm>):
[cpp]
std::transform(name.begin(), name.end(), name.begin(), ::toupper);
[/cpp]
This is using iterators instead of thinking std::string is an array of chars. It goes from the beginning to the end of the string, char by char, calls ::toupper (:: at the beginning means global scope) on every char and writes it into the third parameter. The third parameter is also an iterator, which is incremented by one for every step the function does.
So it basically calls toupper on every character and writes them back into the string.[/QUOTE]
That's useful.
What I wanted to do is capitalize only the first letter of the name (so the surname and family name) so that's why I used that large chunk of code.
[QUOTE=WhatTheEf;33995713]That's useful.
What I wanted to do is capitalize only the first letter of the name (so the surname and family name) so that's why I used that large chunk of code.[/QUOTE]
I completely missed that. In that case your original code just needs some changes:
[cpp]
name[0] = ::toupper(name[0]);
for(auto it = name.begin(); it != name.end(); ++it)
{
if (*it == ' ' && it + 1 != name.end())
name.replace(it + 1, it + 1, 1, ::toupper(*(it + 1)));
}
[/cpp]
We use iterators to iterate through the string instead of a hard-coded length (10) and use string::replace to convert the characters to uppercase.
How to draw a simple debug message somewhere in corner? For Android 2.1.
This is what I have now:
[cpp]
Activity:
import android.os.Bundle;
import android.app.Activity;
import android.opengl.GLSurfaceView;
public class Activitytest extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
GLSurfaceView view = new Viewtest(this);
OpenGLRenderer open = new OpenGLRenderer();
view.setRenderer(open);
setContentView(view);
setRequestedOrientation(6);
}
}
...
Viewtest:
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.opengl.GLSurfaceView;
public class Viewtest extends GLSurfaceView
{
private Paint Paint;
public Viewtest(Context context)
{
super(context);
Paint = new Paint();
Paint.setTextSize(64);
Paint.setColor(0xFF000000);
}
public void draw(Canvas canvas)
{
super.draw(canvas);
canvas.drawText("TEST", 150f, 30f, Paint);
}
}
[/cpp]
[QUOTE=reevezy67;33995266]Got the code for Health.Draw()?[/QUOTE] [code]sprite.Draw(crossbacktex, new Rectangle(9, 854, crosstex.Width, crosstex.Height), new Rectangle(0, 0, crosstex.Width, 69), Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0);
sprite.Draw(crosstex, new Rectangle(9, 854, crosstex.Width * player.health / 100, crosstex.Height), new Rectangle(0, 0, crosstex.Width * player.health / 100, 69),
Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0);[/code] With some sick magicks, it works! The SpriteSortMode has to be Deffered for it to work. [B]Yes![/B]
For my camera's in c++ I am used to passing a entity or vector as a reference to the camera so the camera can follow that entity / vector.
Now I am working in c# and I know I can use pointers but that requires me to convert a lot methods to unsafe methods and I don't even know if you may do that when trying to publish something to the xbox.
Forgot the question lol, what would be the proper way to do this in c# ?
[QUOTE=quincy18;33999669]For my camera's in c++ I am used to passing a entity or vector as a reference to the camera so the camera can follow that entity / vector.
Now I am working in c# and I know I can use pointers but that requires me to convert a lot methods to unsafe methods and I don't even know if you may do that when trying to publish something to the xbox.
Forgot the question lol, what would be the proper way to do this in c# ?[/QUOTE]
If you're using XNA then you should probably use a View Matrix - this is basically the code i use
[code]
public Matrix transformationMatrix;
public Matrix GetTransformation(GraphicsDevice device)
{
transformationMatrix = Matrix.CreateTranslation(new Vector3(-position.X, -position.Y, 0)) * // sets the matrix's position
Matrix.CreateRotationZ(rotation) * //sets the rotation
Matrix.CreateScale(new Vector3(Zoom, Zoom, 1)) * // sets all the zooming shit, lets you zoom in and out
Matrix.CreateTranslation(new Vector3(device.Viewport.Width * 0.5f, device.Viewport.Height * 0.5f, 0)); // scales it to the screen's resolution
return transformationMatrix;
}[/code]
It's all put into it's own class, which you then put into the spritebatch.Begin() of the Game1 class
[code]
spriteBatch.Begin(SpriteSortMode.Immediate,
null,
null,
null,
null,
null,
camera.GetTransformation(GraphicsDevice));
[/code]
Of course if you're not using XNA then fuck I dont know
[QUOTE=Em See;33993030]Been wondering this for a while; how would one add control over the Steam Overlay to an application? Like, controlling which processes get the overlay applied and such?
If it matters, I'm working with C# here.[/QUOTE]
I don't quite follow what you're asking here. Are you asking if your application can interact with the Steam Overlay? Or are you asking how to add the steam overlay to your application, which should be as simple as adding it to steam. (The overlay injects itself into the game afaik)
How would I go about making a sprite rotate depending on the location of the mouse? (I'm using SFML and C++)
[QUOTE=quincy18;33999669]For my camera's in c++ I am used to passing a entity or vector as a reference to the camera so the camera can follow that entity / vector.
Now I am working in c# and I know I can use pointers but that requires me to convert a lot methods to unsafe methods and I don't even know if you may do that when trying to publish something to the xbox.
Forgot the question lol, what would be the proper way to do this in c# ?[/QUOTE]
In C#, all classes are 'references' which are basically safe pointers.
I'm pretty new to programming, I want to make some kind of graphical UI that shows different information about a game to gain more programming experience. Is there some kind of library with useful stuff for this? I don't really like the default UI colors etc. (the windows one) I'm coding in Java.
There's an issue with what I assume is either my installation of XNA, or visual studio. Whenever I save a project, the content folder for said project instantly thinks it's corrupt, even though it can still access the content within it. This prevents me from adding any new resources, and is very frustrating. What can I do to fix this?
The content folder is doing this:
[img]http://dl.dropbox.com/u/12024286/Wasd%20awasrd.PNG[/img]
[QUOTE=Lord Ned;34004033]I don't quite follow what you're asking here. Are you asking if your application can interact with the Steam Overlay? Or are you asking how to add the steam overlay to your application, which should be as simple as adding it to steam. (The overlay injects itself into the game afaik)[/QUOTE]
I'm asking if I can control which processes launched by my application gain the overlay (by default any process launched by an application added to Steam gets it, but not reliably).
Would something like Steamworks allow me to do this?
[QUOTE=swift and shift;34007064]In C#, all classes are 'references' which are basically safe pointers.[/QUOTE]
Does this mean I can simpy pass a class through a method and it will use a reference and not copy it ?
Working on my dissertation on AI pathfinding middleware,
anyone know any pathfinding middleware that allows evalutation by students?
(except PathEngine, opensteer...)
[QUOTE=quincy18;34010499]Does this mean I can simpy pass a class through a method and it will use a reference and not copy it ?[/QUOTE]
yep.
Classes are reference types, structs are value types.
You will never copy a class unless you explicitly Clone() it or something. Structs are always copied when they're passed around (unless the method takes a 'ref' or 'out' parameter)
I'm making a top-down 2D exploration game (using Slick), and I want to continuously reveal more of the map through fog as the player explores. I can't think of a good way to do this. Ideas?
[QUOTE=Nigey Nige;34010988]I'm making a top-down 2D exploration game (using Slick), and I want to continuously reveal more of the map through fog as the player explores. I can't think of a good way to do this. Ideas?[/QUOTE]
I know one of the more common/efficient methods is called shadow casting and I would actually know how to do this too.
End of December Thread (make a January thread)
Sorry, you need to Log In to post a reply to this thread.