It looks like you're new here. If you want to get involved, click one of these buttons!
Hi, so as an alternative control system for people who can't operate their iPhones and iPads using tilt ive been looking into an onscreen joystick that just moves left and right with buttons for shoot and loop the loop for Starsceptre.
I've got a good example for the joystick but when I click on a button it overrides the joystick turning it off.
I'm using touch and not current touch. I'm wondering how I retain two touches. Is it by using touch.id one set for joystick and one each for the two buttons? I'm also trying to fix the joystick in one place and I've almost got that working.
This is the joystick code that creates the stick and locks it to horizontal controls
if controltype=="c" and game== go and touch.y < scY*50 and touch.y > scY*0 and touch.x < scX*35 and touch.x > scX*10 and touch.state == BEGAN then
control.centre = vec2(touch.x,scY*25)
control.touch = vec2(scX*25,scY*25)
control.active = true
elseif controltype=="c" and game== go and touch.y < scY*50 and touch.y > scY*0 and touch.x < scX*50 and touch.x > scX*0 and touch.state == MOVING then
control.touch = vec2(touch.x,scY*25)
if control.touch:dist(control.centre) > control.radius - control.innerRadius then
control.touch = control.centre + (control.touch - control.centre):normalize()*(control.radius - control.innerRadius)
end
else
control.active = false
end
And here is the button for shooting. Do both sets need different Touch ID for you each?
if game==go and sh.state ~= sh.deady and sh.state~=sh.jumpin and sh.state~=sh.pullup and sh.state~=sh.dive and paralysis <1 and levelend==false
--and CurrentTouch.y < scY*35+yy
and (((controltype=="b" or controltype=="c") and touch.y < scY*29 and touch.y > scY*15
and touch.x < scX*78 and touch.x > scX*65) or (controltype=="a"
and touch.y < scY*75+yy))
and pauser==false
then
if touch.state==BEGAN and auto==true then
autofire=true
if safetybullet==0 then
fire=true
end
end
if touch.state==ENDED then
if auto==true then
autofire=false
if (level==3 and timer<5100) then
else
safetybullet=0
end
else
if level==3 then
if leveltimer<5100 then
if safetybullet==0 then
fire=true
end
else
if safetybullet==0 then
fire = true
end
end
else
if safetybullet==0 then
fire = true
end
end
end
end
else autofire=false
end
Thanks
Rich
Comments
@Majormorgan If you want to keep buttons or any type of screen touch seperate from other ones, then you're correct by saying you need to use Touch ID.
Thanks @dave1707 !! I'll get on that. Brilliant!!!
@Majormorgan Actually, you don't need to use Touch ID. Here's another way. I'm using a name that I give to each button. It might be easier to keep track of each button that way. To use the joyStick, slide your finger back and forth. The shoot button shoots a bullet each time it's hit. The loop button just spins the ship and doesn't let you shoot while spinning.
Thanks @dave1707
I'm down the Touch ID route at present. Do I need to create an array to store Touch IDs or am I missed by something simple, I was hoping to assign a touch.id to the joystick and one to fire button and loop button
@Majormorgan I think Touch ID is best used when you have multiple objects that don't remain in a fixed position. You might touch multiple objects and move them somewhere on the screen. I can't think of a good example at the moment. As for using an array, that depends. When you touch an object, then the table would need the ID along with other info for that object. If you use a class, then you would save the ID in the instance of the button. I think the easiest way for fixed buttons would be what I show above. You give each button a unique name and you use the name to identify which button is used. The name in this case is replacing the ID number. One thing about a Touch ID, it's a number that's different each time the screen is touched. I don't know how the ID is calculated.
Ah that makes sense @dave1707 - I'm gonna implement your code! Thank you
I didn't fully understand what you were saying, but were you after something like this.
Hi @dave1707 that works great in its own project and is quite close to my vision, but trying to incorporate that code into my game is proving a bitch as there are a number of things that are affected by the code from different parts of the game engine.
That's why I'm trying to implement the id aspect to the code I have. Here's a quick video demo:
https://instagram.com/p/BXXT9wkH79T/
As I can only detect one touch the joystick control is turning off the autofire but holding down on the joystick still lets me move the ship.
My two priorities to solve are multi touch or multi hold really, plus when You take your hand off the joystick I'll code it to move back to the centre.
if I could understand how to code in multi touch using Touch ID that would be ace!
Thank you so much for all your help
Best
Rich
@Majormorgan See the Codea example Multi Touch. See if that gives you the info you need. If not let me know and I'll help more.
I'll keep on with the multitouch examples and if I hit any specifics I'll ask.
One quick question, I still have another touch function running at the same time as this new touch t - and the other touch example is above the touch t code in main. Can two touch codes exist at the same time?
Thanks
@Majormorgan -here is an example of multi-touch which does some of what you want.
A purely personal point of view but I'm always a little bit disappointed when I see someone on the forum trying to implement an onscreen joystick. The iPad is a touch driven device, and there are so many possibilities to implement interesting control mechanisms for games, but the default seems to be for an onscreen approximation of a physical joystick.
IMHO having to hit a specific location on the screen to control your ship seems a bit 'meh' compared to the USP of your game of unique(ish) tilt controls for a shooter. How about detecting gestures to initiate events, e.g. Upward swipe to loop the loop. Tap or second finger hold to toggle auto-fire/fire and primary touch for ship movement.
The onscreen or touch to move controls are only an alternative to the tilt mechanism for the ones that don't like tilting. The titling will always be the main control system for the game, just I've had a lot of resistance to the tilt mechanic only so by making the stick variant, even an invisible one, will go some way to gaining more players.
I do get about the swipe action and tap to shoot as a good way to ensure a more expressive and mobile way of playing. I've just got to get the balance right as I hate shooters where the ship is stuck to your finger as you obscure the ship and can't see what you are hitting.
Also the game isn't an auto-shooter like others as you have to conciously make decisions to shoot or not.
I'll know once I get this code working properly
Thanks to you and to @dave1707 !!!
So it's meant to be:
~~~
If touch.state==ENDED then
touches[touch.id] = nil
else
touches[touch.id] = touch
[code goes here...]
end
~~~
All I have to do now is write code to detect the distance of the joystick as it moves from its centre point so it can adjust the amount the background moves by (slight movement on the stick = slight movement on the background, full movement on the stick = full movement on the background). I'll be able to crack that.
Thank you both so much for your examples and feedback.
I can see going forwards with new games that @dave1707 approach to making buttons will be worth investigating.
And here's the latest code demo that has stick on the left (massive hit area) for left movement plus pull back for tilt. The right side area is a massive hit state for autofire:
Looking at that video it seems like the game runs 1.5 - 2 times faster on my iPad Air 2. No wonder it was so hard
There is something running the code slower at the same time as screen record that I'm trying to locate. Not sure what it is yet as a version of starsceptre about 6 months ago plays and records fine at the same time.
How far did you get in the game?
@Majormorgan I'm not sure what is causing the slowdown exactly but generally you want to use DeltaTime to make sure the game can account for lower than optimal FPS.
I got up to the minefield level.
Thanks @John I'll see what I can do with DeltaTime as much of the game is frame based counting.
I'm still trying to isolate the piece of code that is slowing things down. I'm sure I'll find it soon
Thanks