Created
June 11, 2012 01:52
-
-
Save cubed2d/2908070 to your computer and use it in GitHub Desktop.
sprite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Sprite | |
{ | |
private Color tint; // this is a normal field. its private, so only we can see it. | |
// THIS IS BAD DONT DO IT :) public Color tint; // this is a public field. Any other class can see it, this is what you would do in java. in C# this is bad code! | |
// this is a property, and the way you should expose data to other classes. Use it to wrap a varible up. this means if later you decided you want to let tint be shades of red, you just change the set method to enforce that new rule. you dont have to go though allll the code that sets tint and change that to enfore a new data rule. | |
public Color Tint | |
{ | |
get { return tint;} | |
set { tint= value;} | |
} | |
// this is an autoproperty. its the same as the above example, except the c# compiler does the work of creating the backing field for your property for you. it makes your life easier | |
public Vector2 Postion {get;set;} // example of an auto property. | |
public Sprite(Vector2 pos, Vector2 scale, Color tint) | |
{ | |
// constructor | |
} | |
public void Update(GameTime time) | |
{ //updaet code here | |
} | |
} | |
// at point of use | |
Sprite s = new Sprite(new Vector2(x,y), scale, Color.Crimson); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment