It looks like you're new here. If you want to get involved, click one of these buttons!
It seems that I cant understand multitouch. Here is my touch function with all the mess that is included:
function Player:touched(touch)
--Move
if touch.state==BEGAN then
self.touches[touch.id]=touch
end
for k,touchs in pairs(self.touches) do
if touchs.state==MOVING and touchs.x>0 and touchs.x<150 and
touchs.y>0 and touchs.y<150 then
self.speed=touchs.y/9
end
--Look x and y
if touchs.state==BEGAN then
self.dax=touchs.x
self.lyx=touchs.y
end
if touchs.state==MOVING and touchs.x>150 then
self.da=self.dalx-(touchs.x-self.dax)
self.angle=self.da/80
self.tly=self.lylx-(self.lyx-touchs.y)
self.tly=self.tly/100
if self.tly>1.5 then self.tly=1.5 end
if self.tly<-1.5 then self.tly=-1.5 end
end
if touchs.state==ENDED then
self.touch[touchs.id]=nil
self.speed=0
self.dax=0
self.dalx=self.da
self.lylx=self.tly
self.lyx=0
end
end
end
Help would be appreciated!
EDIT: Fixed BEGAN and MOVING
Comments
it is not clear what you are trying to do. Difficult then to help you?
Oh, didnt mean to be unclear. What I want to acheive is to get the multitouch in the code to work, as it didnt when I tried it before posting this question. There is a problem somewhere, but I cant find it...
oh really? You want it to work? Silly me, i thought you wanted it not to work!
From the indication you've given me up to now, my most appropiate proposal would be: 'make it work then, by correcting the bugs'. No, dont thank me, it is natural to help when i can.
Now, if you can be a bit more specific on describing what result you want exactly, maybe i will be able to be more specific too.
;-)
Haha, well I might not always be so clear.
However, what I want is the user to have one finger touching/adjusting the speed and another finger to look around. After figuring out the basics of multitouch I executed my code but the game didn't respond. So thats the problem that I am incapable of solving.
@MMGames One thing I noticed was these "if" statements. touchs.state can't be BEGAN and MOVING at the same time, so MOVING will never be true.
Fixed. Thanks @dave1707
But the problem is still there...
Do you have codea community? Have a look at Spritea or Spacewar in there, or if not look here:
http://twolivesleft.com/Codea/Talk/discussion/4487/spritea-a-rapid-scene-generation-tool-from-sprites-located-in-the-dropbox-folder/p1
and here:
http://twolivesleft.com/Codea/Talk/discussion/4585/spacewar-soon-to-be-on-the-app-store/p1
Both use multitouch and support up to 11 touches.
If you wanted to post your whole code for us to look at, we might be able to help out more.
I suspect that your code is getting called too often. Split it into
Then call processTouches at most once each cycle.
@MMGames From what I got out of your questions, you want 2 squares that will control 2 different things. Here is a small example with 2 squares. Since I don't know exactly what you want them to do, I just displayed the left and right x,y values as you move your fingers around the squares. You can take the touched function and add whatever code you want each square to do.
That's why I proposed gesture API since the beginning of Codea (was Codify). There are times when you just don't want to get messy with touch detection.
Simple. You just need to update the variable in the tabe. It's assigning a clone, not a pointer. Remove the first if statement to check if the touch's state is BEGAN. This should work.
@SkyTheCoder @dave1707 @Andrew_Stacey Thank you! Now it works as it schould!