Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li><p>@XtrmJosh is right, XNA would be more appropriate for such task</p></li> <li><p>You are better off asking such questions in <a href="https://gamedev.stackexchange.com/">https://gamedev.stackexchange.com/</a> than in SO, it is <strong>the</strong> place about game development questions</p></li> <li><p>Make your cat move in <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.processcmdkey.aspx" rel="nofollow noreferrer">ProcessCmdKey</a> instead, events will be always caught as opposed to using <code>Control.KeyDown</code> which catches them <strong>only</strong> if that control has the focus.</p></li> </ul> <p>Code :</p> <pre><code>public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { // Move your cat here return base.ProcessCmdKey(ref msg, keyData); } } </code></pre> <ul> <li><p>When are you hooking to your timer tick event in GameManager ?</p> <pre><code>private void Form1_Load(object sender, EventArgs e) { Timer timer = new Timer(); timer.Tick += timer_Tick; } void timer_Tick(object sender, EventArgs e) { // Do your thing } </code></pre></li> <li><p>In that same tick event you are moving things but <strong>you don't draw them</strong>.</p></li> <li><p>Use <code>Cat.Move(int n)</code> to move your cat, the <code>Cat.KeyDown</code> is <strong>irrelevant</strong> unless Cat is a <code>Control</code> (it will never get called). But put that logic in the ProcessCmdKey instead. Consider using <code>Keys</code> rather than an integer. And the others 'if' should be 'else if'. (see switch instead as it's less error-prone)</p></li> </ul> <p>Code :</p> <pre><code>protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { // Move your Cat here switch (keyData) { case Keys.Left: cat.Move(keyData); break; case Keys.Right: break; } return base.ProcessCmdKey(ref msg, keyData); } public class Cat { public void Move(Keys keyData) { switch (keyData) { case Keys.Left: // act accordingly ... break; case Keys.Right: break; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload