- –
- – Abstract: Move Vectors in realtime. Lets users drag update vector positions
- – and updates the new positions on all clients.
- –
- – create global warp client and initialize it
- appWarpClient = require “AppWarp.WarpClient”
- – Replace these with the values from AppHQ dashboard of your AppWarp app
- API_KEY = “secret”
- SECRET_KEY = “secret”
- STATIC_ROOM_ID = “secret”
- appWarpClient.initialize(API_KEY, SECRET_KEY)
- – uncomment if you want to enable trace printing of appwarp
- –appWarpClient.enableTrace(true)
- – IMPORTANT! loop WarpClient. This is required for receiving responses and notifications
- local function gameLoop(event)
- appWarpClient.Loop()
- end
- Runtime:addEventListener(“enterFrame”, gameLoop)
- – do the appwarp client related handling in a separate file
- require “warplisteners”
- statusText = display.newText( “Connecting…”, 10, display.contentHeight, native.systemFontBold, 24 )
- statusText.width = 128
- appWarpClient.connectWithUserName(tostring(os.clock()))
- button = {}
- – Iterate through arguments array and create rounded rects (vector objects) for each item
- for i = 1, 2 do
- local button1 = display.newRoundedRect( 50*i*2, 60, 100, 100, 10 )
- button1.strokeWidth = 6
- button1:setStrokeColor( 200,200,200,255 )
- button[i] = button1
- end
- local function onTouch( event )
- local t = button[1]
- local phase = event.phase
- if “began” == phase then
- – Make target the top-most object
- local parent = t.parent
- parent:insert( t )
- display.getCurrentStage():setFocus( t )
- t.isFocus = true
- – Store initial position
- t.x0 = event.x - t.x
- t.y0 = event.y - t.y
- elseif t.isFocus then
- if “moved” == phase then
- – Make object move (we subtract t.x0,t.y0 so that moves are
- – relative to initial grab point, rather than object “snapping”).
- t.x = event.x - t.x0
- t.y = event.y - t.y0
- appWarpClient.sendUpdatePeers(tostring(t.y))
- elseif “ended” == phase or “cancelled” == phase then
- display.getCurrentStage():setFocus( nil )
- t.isFocus = false
- – send the update to others in the game room. space delimit the values and parse accordingly
- – in onUpdatePeersReceived notification
- appWarpClient.sendUpdatePeers(tostring(t.y))
- end
- end
- return true
- end
- button[1]:addEventListener( “touch”, onTouch )
- function onConnectDone(resultCode)
- if(resultCode == WarpResponseResultCode.SUCCESS) then
- statusText.text = “Joining Room…”
- appWarpClient.joinRoom(STATIC_ROOM_ID)
- elseif(resultCode == WarpResponseResultCode.AUTH_ERROR) then
- statusText.text = “Incorrect app keys”
- else
- statusText.text = “Connect Failed. Restart”
- end
- end
- function onJoinRoomDone(resultCode)
- if(resultCode == WarpResponseResultCode.SUCCESS) then
- appWarpClient.subscribeRoom(STATIC_ROOM_ID)
- statusText.text = “Subscribing to room…”
- else
- statusText.text = “Room Join Failed”
- end
- end
- function onSubscribeRoomDone(resultCode)
- if(resultCode == WarpResponseResultCode.SUCCESS) then
- statusText.text = “Started!”
- else
- statusText.text = “Room Subscribe Failed”
- end
- end
- function onUpdatePeersReceived(update)
- local func = string.gmatch(update, “%S+”)
- local y = func()
- local x = func()
- local buttonasd = button[2]
- buttonasd.y = tonumber(y)
- end
- appWarpClient.addRequestListener(“onConnectDone”, onConnectDone)
- appWarpClient.addRequestListener(“onJoinRoomDone”, onJoinRoomDone)
- appWarpClient.addRequestListener(“onSubscribeRoomDone”, onSubscribeRoomDone)
- appWarpClient.addNotificationListener(“onUpdatePeersReceived”, onUpdatePeersReceived)
here is a link to video that shows the bug
https://www.youtube.com/watch?v=UJ41buMjXJs&feature=youtu.be
Soo, if we come from left to right we can call them boxes 1, 2, 3 and 4. So see in the video, when I move box 3 it moves box 2 AND also box 4. What I want it to do is when I move box 3 it only moves box 2 and not box4.
Same thing happens other way; when I move box 1 it moves box 2 and box 4.
So if anyone of you could please help me with this problem as soon as possible.