Moving object around using keyboard

Come down to the basement if you have questions about scripting or would like to talk about coding in general.

Moving object around using keyboard

Postby 8oni » Sun Dec 25, 2016 12:56 pm

Hi!
This time I show you how to move object in Novelty using keyboard



And here is the code
Code :
Code: Select all
event s.OnUpdate
{
   Object@ s = Scene.GetObject("Square") as Object;
   $checkX = s.position.x;
   $checkY = s.position.y;
   
   if($checkX < 0)
   {
      s.position.x = 0;
   }
   else if($checkX > 750)
   {
      s.position.x = 750;
   }
   else
   {
      //do nothing;
   }
   
   if($checkY < 0)
   {
      s.position.y = 0;
   }
   else if($checkY > 550)
   {
      s.position.y = 550;
   }
   else
   {
      //do nothing;
   }
   
   
}


event Sample.OnKeyDown
{
   Object@ s = Scene.GetObject("Square") as Object;

   switch (keyCode)
   {
   case KEY_UP:
      s.position.y = s.position.y - 10;
      break;
   case KEY_DOWN:
      s.position.y = s.position.y + 10;
      break;
   case KEY_LEFT:
      s.position.x = s.position.x - 10;
      break;
   case KEY_RIGHT:
      s.position.x = s.position.x + 10;
      break;
   }   
}


Feels free to download the project example and asking any question!
Attachments
MovingObjectUsingKeyboard.nov
(12.7 KiB) Downloaded 68 times
So many idea, so little time
User avatar
8oni
 
Posts: 258
Joined: Tue Oct 30, 2012 12:23 pm

Re: Moving object around using keyboard

Postby fleet » Sun Dec 25, 2016 9:59 pm

Thanks for posting this!
Why? I like big ones, that's why.
User avatar
fleet
 
Posts: 869
Joined: Tue Aug 31, 2010 12:03 am
Location: USA


Return to The Basement

Who is online

Users browsing this forum: No registered users and 1 guest

cron