วันเสาร์ที่ 15 มิถุนายน พ.ศ. 2556

NSMutableDictionary


mutable dictionary can be changed, i.e. you can add and remove objects. An immutable is fixed once it is created.
create and add:
NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithCapacity:10];
[dict setObject:[NSNumber numberWithInt:42] forKey:@"A cool number"];
and retrieve:
int myNumber = [[dict objectForKey:@"A cool number"] intValue];
alternative:
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:[NSNumber numberWithInt:5] forKey:@"age"];
int myAge = [[dict objectForKey:@"age"] intValue];

วันพุธที่ 17 พฤศจิกายน พ.ศ. 2553

XNA: set the mouse cursor visible / invisible

mouse visible, in Game1 constructor add
isMouseVisible = true;

mouse invisible, in Game1 constructor add
isMouseVisible = false;

วันอังคารที่ 9 พฤศจิกายน พ.ศ. 2553

XNA: Backface Culling

in XNA, by default, backface culling is on, so that we won't see the object drawn in counter clock wise order (or we won't see what is inside a ball, and we don't want to see it anyway). only primitive that is facing the camera (clock wise order) is drawn.
We can turn off culling by placing the following code in the Draw( ) method just below the
GraphicsDevices.Clear( ) method.

GraphicsDevices.RenderState.CullMode = CullMode.None;

วันเสาร์ที่ 26 ธันวาคม พ.ศ. 2552

Set the size of the XNA game window

in window mode, set the properties PreferredBackBufferWidth and PreferredBackBufferHeight to set the width and height of the XNA game window.

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.PreferredBackBufferWidth = 1024;
graphics.PreferredBackBufferHeight = 768;
}

Exit XNA game in fullscreen mode

if there is no exit button or no other way to exit, just press Alt+F4

Run XNA in fullscreen mode

in Game1() constructor set the property IsFullScreen = true;

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.IsFullScreen = true;
}

Drawing 3D Wireframe model in XNA

in LoadContent(), set property RenderState.FillMode = FillMode.WireFrame;

protected override void LoadContent()
{
device = graphics.GraphicsDevice;
device.RenderState.FillMode = FillMode.WireFrame;
myModel = Content.Load("tank");
}