Analogue Joystick - Sample Code WIP

Latest Build of the joystick now online

Get it here http://www.alienhorde.com/files/joystick_1_0.zip

Most of the new features listed above are now working including the new fade effect. Check main.lua on how to generate a new joystick [import]uid: 5354 topic_id: 1632 reply_id: 4922[/import]

I don’t know if I’ll use it but many thanks Matthew! :smiley: [import]uid: 7022 topic_id: 1632 reply_id: 4923[/import]

Matthew it is phenomenal! Will the tile engine be free to use as well? :slight_smile: [import]uid: 7664 topic_id: 1632 reply_id: 4935[/import]

Anything I post is free to use, I dont want crediting or anything like that.

Corona is missing a few things in my opinion, not the fault of Ansca, but as its so new there are very few references and examples out there to follow and thats how I usually learn a new platform / language.

Anscas examples were enough for me to program Alien Horde but I think I can now add a bit back to the community. The joystick being the first example, it would be right at home in the “Interface” folder of the sample code and its designed to save people time in setting up their games and it also works for anyone needed in method of getting user input into their code for testing purposes. Thats why I did a zero config option

joystick = joystickClass.newJoystick{}  

will setup a new joystick and position it bottom left, you dont even need graphics.

As for the tile engine, I will setup a new topic once ive looked into it. Im not too sure how to proceed.

I could either have it draw the whole world at once, from a table of values / co-ordinates, or have it look at a table every “load point” and have it draw the new textures while clearing the old ones. Both would work from a sprite sheet and the textures would be 160px x 160px in size as that gets 6 squares on screen at once, enough definition in my opinion to work well of a sprite sheet.

The other issues is collision detection. I would see this concept being suitable for a top down racer so I would need to be able to define collision areas for each tile and have it set them up as well.

I need to look into the best way to accomplish this… [import]uid: 5354 topic_id: 1632 reply_id: 4948[/import]

Joystick Version 1 Released

Get it here http://www.alienhorde.com/files/joystick_1_0.zip

Ive included some examples and instructions on how to use it, it has all the features requested / listed above and is stable.

Also included is a 2 joystick example where you get to drive a tank!

Enjoy and let me know if you are using it in any projects

PS

Carlos / evank can we get this included in the /SampleCode folder of the Corona releases. I think it would be right at home in the /Interface section.

Its been update to work with the game edition replacing sprite.lua with movieclip.lua for the examples. [import]uid: 5354 topic_id: 1632 reply_id: 4958[/import]

Awesome and a big thank you! [import]uid: 5712 topic_id: 1632 reply_id: 4984[/import]

Matthew

I saw your interview on the main Ansca site, congrats and great work! [import]uid: 7664 topic_id: 1632 reply_id: 4993[/import]

Matthew,

Just in case I somehow forget or miss this thread again, I wanted to say thanks for the example. I’m working my way through Corona and Lua and I am your code will help a lot of people!

[import]uid: 8045 topic_id: 1632 reply_id: 4994[/import]

Hi Matthew,

Awesome piece of code, i think everbody will enjoy that :slight_smile:

Is there an easy way of setting up two joysticks, for example:

LEFTBOTTOM -> Joystick (Left, right, up, down)
RIGHTBOTTOM -> Button (just one action)

Cheers,
Jespar
[import]uid: 2734 topic_id: 1632 reply_id: 4999[/import]

Hi freshworks

What do you need the rightbottom button to do, do you just want a button or another joystick that only has one action?

Matt [import]uid: 5354 topic_id: 1632 reply_id: 5000[/import]

Hi Matt,

i just need it to be a button witch executes one action.

Cheers,
Jespar
[import]uid: 2734 topic_id: 1632 reply_id: 5001[/import]

Hi Jespar

I would just generate a new button using the ui.lua that Ansca provide.

Look in the /SampleCode/iPhone/Interface/ButtonEvents/

That will show you how to setup a new button and assign an action to it. If you hace the Game Edition I think you will need to download the normal Corona beta for the examples.

I you need help email me your setup to matt@mattpringle.co.uk and I will have a look for you

Matt [import]uid: 5354 topic_id: 1632 reply_id: 5003[/import]

Using Matthew Pringle’s Joystick on a Droid X. Works great except the joystick intermittently gets stuck in an ON position, and will not snap back to neutral position. This happens even with the ‘Simple Setup’. [import]uid: 12850 topic_id: 1632 reply_id: 28100[/import]

Hey david

have you tested on an iPhone, is this an android problem / droid problem ?

it sounds to me like something is crashing in the code, separate modules can crash without bringing an entire app down. if you want to email me it I can have a look see

Matt [import]uid: 5354 topic_id: 1632 reply_id: 28153[/import]

Matt,
I haven’t loaded on an iPhone. Focusing on Android development at the moment. I’m a NOOB, and Android is a bit more noob friendly in terms of getting the game on the phone.

I think I have found what is causing my particular problem. If you drag your finger outside the OUTER ring, the joystick stops tracking - left, right, up, down, touch, release. This doesn’t happen in the simulator.
This at least give me a direction to investigate.

Thanks for the code - It rocks on the simulator. Allowed me to move forward with some actual ‘story’ design rather than spending my time trying to figure out how to move. [import]uid: 12850 topic_id: 1632 reply_id: 28261[/import]

I think I read somewhere in the forums about android builds not handling the touch events properly.

Fingers crossed its fixed in the next release but have a search to see if there is a work around. [import]uid: 5354 topic_id: 1632 reply_id: 28281[/import]

How can i increase the value that the joystick is putting out. my player object does move in the intended direction, but much too slow
this is what i have right now
[lua]local movePlayer = function()

xMotion = joystick.joyX * 25
yMotion = joystick.joyY * 25

playerObject:setLinearVelocity( xMotion , yMotion)

end
Runtime:addEventListener(“enterFrame”, movePlayer )[/lua]

this does seem to make the playerobject move faster but i get a continual runtime error.

any help would be great thanks [import]uid: 19620 topic_id: 1632 reply_id: 56288[/import]

use this

xMotion = joystick.joyX yMotion = joystick.joyY if xMotion ~= false and yMotion ~= false then xMotion = xMotion \* 25 yMotion = yMotion \* 25 playerObject:setLinearVelocity( xMotion , yMotion) end [import]uid: 5354 topic_id: 1632 reply_id: 56290[/import]

works like a charm, thank you for the quick reply [import]uid: 19620 topic_id: 1632 reply_id: 56292[/import]

can you think of anyway that i would be able to change the multiply value while the joystick is being moved? for example while im moving, i would like to have a button that when held down, simulated the player running, thus increasing the speed. [import]uid: 19620 topic_id: 1632 reply_id: 56295[/import]