iPhone controllers?

New to Moai? Get started here with our best tips and tutorials.

iPhone controllers?

Postby SweBeat » Tue Jun 26, 2012 2:49 pm

Hello,

I've been trying to make an iPhone game now with Moai, now that I finally got it working. :)

But I can't seem to find how to use the touch controllers on the iPhone? Do I need to build functions for that myself or how does it work? This is my first game trying to make for iPhone. So I'm a big newbie to this. So maybe someone could point me in a direction how to like touch something and drag it around? And maybe more tutorials if there are any for Moai and iPhone developement. Or at least how I use the touch, swipe and so on.

I'm also using Rapanui, so if someone also knows more about that how to use it and such that would be awesome.

Sorry to bother with another question so soon but I'm stuck again. :?
SweBeat
 
Posts: 34
Joined: Tue Jun 26, 2012 11:22 am

Re: iPhone controllers?

Postby anddrewscott » Tue Jun 26, 2012 4:38 pm

Check out the Rapanui touch samples such as rn-touch.lua, here:
Code: Select all
  1. --[[

  2. --

  3. -- RapaNui

  4. --

  5. -- by Ymobe ltd  (<!-- m --><a class="postlink" href="http://ymobe.co.uk">http://ymobe.co.uk</a><!-- m -->)

  6. --

  7. -- LICENSE:

  8. --

  9. -- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) <!-- m --><a class="postlink" href="http://www.opensource.org/licenses/cpal_1.0">http://www.opensource.org/licenses/cpal_1.0</a><!-- m -->.

  10. -- CPAL is an Open Source Initiative approved

  11. -- license based on the Mozilla Public License, with the added requirement that you attribute

  12. -- Moai (<!-- m --><a class="postlink" href="http://getmoai.com/">http://getmoai.com/</a><!-- m -->) and RapaNui in the credits of your program.

  13. ]]

  14.  

  15. sprite1 = RNFactory.createImage("images/tile1.png")

  16.  

  17. back = RNFactory.createImage("images/background-purple.png")

  18. back:sendToBottom()

  19.  

  20. local w, h = RNFactory.stageWidth, RNFactory.stageHeight

  21.  

  22. function onTouchEvent(event)

  23.     if event.phase == "began" then

  24.         sprite1.x = event.x

  25.         sprite1.y = event.y

  26.     end

  27.  

  28.     if event.phase == "moved" then

  29.         sprite1.x = event.x

  30.         sprite1.y = event.y

  31.     end

  32. end

  33.  

  34. local listenerId = RNListeners:addEventListener("touch", onTouchEvent)

  35. print("Listener ID", listenerId)

  36.  



If you want to make your own call back functions. Have a look through RNInputManager - how it caters for touch events (devices) and and mouse pointers.
anddrewscott
 
Posts: 153
Joined: Fri Sep 02, 2011 7:39 am

Re: iPhone controllers?

Postby ibisum » Wed Jun 27, 2012 12:33 am

There are a couple of good samples for doing touch and drags and so on, in the MOAI sdk samples folder. The most enlightening sample is in "samples/input/input-picking", since this gives you the details on how to put things up on the screen, have them react to touch events, move when dragged, and so on. I highly recommend you check this sample out, its a very easy to understand mechanism and you will, probably, have a good time with it.

Then, when you've checked that out, have a look at the Hanappe framework. A lot of folks seem to go straight for the frameworks once they get rolling with MOAI - after all, MOAI is quite low-level in many ways, and the frameworks contributed by the MOAI hacker community are in many ways absolutely brilliant in their own light - but I would suggest you first learn how to do it the 'plain' MOAI way first (input-picking), and then look at Hanappe, because there is a lot to learn in the Hanappe framework, the docs are in Japanese, and you'll have to know how MOAI is doing things in order to properly 'grok' the code for Hanappe itself. Here is where Hanappe lives:

https://github.com/makotok/Hanappe

In particular, look at the rpgmap example (at the bottom of the main samples list when you run the main.lua demo included in the framework) as it provides a very nice on-screen touch-control surface interface that might be exactly what you are looking for. Plus, there's the whole "everything you need to build an RPG and more" is included, thing. ;)

Good luck, lets hear how you progress - and glad you got things happening!
;
--
ibisum@gmail.com
Got a MOAI snippet? Please consider adding it to http://moaisnippets.info
User avatar
ibisum
 
Posts: 1024
Joined: Mon Oct 17, 2011 1:11 am
Location: Vienna, Austria


Return to New Users

Who is online

Users browsing this forum: No registered users and 2 guests

x