Hi! We are creating a bejeweled inspired puzzlegame for a school assignment. Basically what you do is rotate a cluster of 4 bricks on a board to create a combination of 4 (or more) bricks with the same color.
To rotate the bricks we have put a listener between each cluster of 4, and by tapping or swiping (depends on the controller you have chosen) on the listener, the bricks rotate. Example:
https://www.dropbox.com/s/5gz5pin3h77pdph/example1.png
What we want to create now is a multitouch controller where you hold one finger on the listener, and by tapping on either side, you rotate the cluster accordingly.
Here is the code so far:
[lua]function multiDetect(e) if e.phase == “began” or e.phase == “stationary” then --When the first finger is touching the screen, I’m saving the coordinates so
–that we can detect if the second finger is to the left or right. print("First finger is touching screen with id: " … tostring(e.id))
print("coor = " … e.xStart) --Saving the id of the event so we can detect if the first finger has been lifted.
firstTouch = e.id;
startX = e.xStart;
–Setting the target to the listener(I dont know if this is the way to do it);
display.getCurrentStage():setFocus(e.target, firstTouch); function spinThatShit(event) if event.phase == “began” and event.id ~= firstTouch then print("Second finger is touching, id: " … tostring(event.id));
print("The xPos of the second finger is: " … event.xStart); if event.xStart > startX then
–Second finger is to the right, rotating clockwise
rotateCW(e)
elseif event.xStart < startX then
–Second finger is to the left, rotating counterclockwise
rotateCCW(e) end
end
end
–Listening for the second finger
Runtime:addEventListener(“touch”, spinThatShit) elseif e.phase == “ended” or e.phase == “cancelled” and e.id == firstTouch then
–The first finger has been lifted.
–Setting the id to zero.
firstTouch = 0;
display.getCurrentStage():setFocus(e.target, nil);
print(“Lifting first finger”)
–Removing the eventlistener for the second touch.
Runtime:removeEventListener(“touch”, spinThatShit) end[/lua]
The problem is that we need to press outside the board. If you hit other listeners it wont rotate.
Also, if you press other listeners it detects that the first finger has been lifted. So when you actually lift the first finger the endedphase has been run twice. What we need is a way to be able to press wherever we want on the board with the second finger, and maybe make the other listeners inactive while the first finger is pressing the board. In theory the only value we need is the x-pos of the second finger to know which way to rotate the bricks. Hope some of you are able to help!
Thanks!