Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Fl00Fy

Member Since 15 Mar 2013
Offline Last Active Nov 14 2013 04:40 AM

Topics I've Started

Reference/Value types in C#

10 November 2013 - 08:29 AM

I'm busy trying to make a game in Unity3D, but haven't had much experience in C# and having some trouble finding any specifics on how value/reference types are handled. I understand the basics of it; that most primitive data types, structs and enums are value type (unless specified by the ref qualifier), and all classes are reference types. Knowing that, I'm assuming the code I've currently got isn't working the way I meant it to because of my lack of knowledge. I'm trying to make a fairly simple card game, and have a Hand class, and a Deck class, both of which are simply containers for Card objects.

public class Deck
{
	private List<GameObject> cards;
	private const int TOTAL_CARDS = 52;
	private int iterator;

        //Constructors...

	public GameObject drawCard()
	{
		if (cards.Count == 0)
		{
			//Merge discard pile with deck
		}
		GameObject temp = cards[iterator];
		cards.RemoveAt(iterator++);
		
		return temp;
	}
}
public class Hand{
	
	private List<GameObject> cards;
	private int numCards;
	private Deck deck;
	
	public Hand(Deck deck)
	{
		this.deck = deck;
		numCards = 0;
		cards = new List<GameObject>(15);
	}

	public void drawCard()
	{
		GameObject card = deck.drawCard();
		Transform cardTransform = card.transform;
		cardTransform.position.Set(1, 1, 1);
		cardTransform.Rotate(new Vector3(0, 1, 0), 180);
		cards.Add(card);
		numCards++;
	}
}

Above is a simplified version of those two classes, the methods the question pertains to is the drawCard() methods in both classes. In the Deck's drawCard method, would removing the object from the List remove a reference or an object; and would the object returned by that method and used in the Hand's drawCard method be a reference pointing to an object that has been deleted(removed from the list) or will it be retained?

 

Thanks for any help. 


Problem setting up GLSurfaceView.Renderer

09 September 2013 - 06:46 AM

I'm trying to create an android app using OpenGL ES, but having some trouble with the GLSurfaceView.Renderer. 

Here's some of my code:

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature (Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                     WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(new MainView(this));
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
public class MainView extends GLSurfaceView {

	private GLRenderer renderer;
	
	public MainView(Context context) {
		super(context);
		setEGLContextClientVersion(2);
		renderer = new GLRenderer (context, this);
		setRenderer (renderer);
		setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
	}
}
public class GLRenderer implements Renderer {

	private MainView view;
	private MainGame game; //This is where the game logic begins.
	private GLRes gl20; //This is a class to initialise and store resources such as matrices and shaders
	
	public GLRenderer (Context context, MainView view)
	{
		this.view = view;
		gl20 = new GLRes (context);
	}
	
	@Override
	public void onDrawFrame(GL10 gl) {
		GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
		game.draw();
	}

	@Override
	public void onSurfaceChanged(GL10 gl, int width, int height) 
	{
		gl20.onSurfaceChanged(width, height);
	}

	@Override
	public void onSurfaceCreated(GL10 gl, EGLConfig config) 
	{
		gl20.onSurfaceCreated();

		game = new MainGame (view, gl20);
		game.setRunning(true);
		game.start();
	}
	
	public void onSurfaceDestroyed ()
	{
		game.setRunning(false);
	}
	
	public void onTouchEvent (MotionEvent event)
	{
		game.handleTouchEvent(event);
	}
}

The constructor of the Renderer is called as expected, but its onSurfaceCreated() is not, and therefore none of the other methods either, including onDrawFrame(). My GLSurfaceView's onSurfaceCreated is, however, called. This leads to me assume that I haven't set something up properly somewhere, regarding OpenGL and the Renderer, but I can't think what or where that could be. 


Gravity's affect on velocity implemented with speed and direction.

19 April 2013 - 12:37 PM

Sorry if the title's a bit confusing, had trouble trying to summarise the problem in a good way. 

Anywho, it seems I may have coded myself into a bit of pickle. I'm trying to create a game which includes gravity and some stuff which is affected by it... I decided, when I started the project, that I would describe each objects velocity with two scalars: speed and direction (in radians, right being 0). It's worked out well so far, until I tried to implement gravity.

 

The problem is, I can't figure out how to account for gravity by giving the object a downward force. If this just happens to be a bad way to implement velocity, I would be alright with having to change the code to use a different method; but if there is a viable solution for this, I'd love to hear it. 

 

Help of any kind would be appreciated. 


Add Object to Array from Constructor

08 April 2013 - 01:53 PM

Hey

 

I'm trying to implement collision detection for a project. So far, my idea has been to add all objects that are added into a scene into an array of objects. My question is, as in the title, can I add an object to said array in its constructor? 

 

I've tried like this 

Object::Object () 
{
	pos_x = 0; pos_y = 0; velocity = 0; direction = 0;
	objectArray [numObjects] = this.Object;
        numObjects++
}

 

and this 

Object::Object () 
{
	pos_x = 0; pos_y = 0; velocity = 0; direction = 0;
	objectArray [numObjects] = this;
        numObjects++
}

 

But neither worked, and I'm having trouble figuring out exactly how I would do it properly, if it's at all possible. 

Also, objectArray is just a pointer to an object, and I've had trouble with pointers before (and probably will for a while). 

int numObjects = 0; 

Object *objectArray;

 

Any help would be appreciated. I also realise that there are probably better ways to keep track of all the objects, or to go about handling collision detection in general. So any help with this topic, or just collision detection in general would be great.

Thanks.  


Access Violation on Pointer Delete

16 March 2013 - 08:38 AM

Well I'm working on a small project, a Blackjack game in C++. I'm getting an Access Violation error when I try to delete a pointer to an object. 

Sprite* message;


void showMessage ()
{
	message->draw();
	glutSwapBuffers();
	Sleep(2000);
	delete message;
}

 

showMessage() is only called from the function below. 

void drawAll()
{
	showHands();
	showButtons();
	if (message != NULL)
	{
		showMessage();
	}
	glutSwapBuffers();
}

 

I have a feeling it's really stupid problem that I'll probably kick myself over when I found out what it is, but I can't, for the life of me, think of what it is. 

I think that's all the necessary code

Any help would be appreciated. 

 

It might be worth mentioning that drawAll() is called in the glutDisplayFunc... But I'm not sure if this would make any difference. 

Thanks


PARTNERS