Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
create rope as in cut the rope — Gideros Forum

create rope as in cut the rope

hgvyas123hgvyas123 Guru
edited September 2013 in General questions
i would like to create the rope as it was in cut the rope smooth,stretchable problem over here is i can not stretch the rope as my image shows the gap in between them also sometimes when rope is moving free at any degree rotation somewhat unusual happening to over come this i have below code but still if there is a way to apply texture to shape with my below code it would be great currently i am not able to apply texture to shape by maintaining rope's smoothness any idea or help is appriciated
 
 
 
 
require "box2d"
 
b2.setScale(30)
 
-- this table holds the dynamic bodies and their sprites
local actors = {}
 
-- create world
local world = b2.World.new(0, 9.8)
 
-- create ground body
local ground = world:createBody({})
 
-- create an edge shape, and attach it to the ground body as a fixture
local shape = b2.EdgeShape.new(0, 350, 320, 350)
--ground:createFixture({shape = shape, density = 0})
 
-- this box shape will be used while creating the chain elements
local shape = b2.PolygonShape.new()
shape:setAsBox(5, 1)
 
-- and our fixture definition
local fixtureDef = {shape = shape, density = 20, friction = 0.2}
 
-- start to create the bridge
local prevBody = ground
 
local bodiesArr = {}
 
for i=1,30 do
	local bodyDef = {type = b2.DYNAMIC_BODY, position = {x = 164 + i * 8, y = 150}}
	local body = world:createBody(bodyDef)
	body:createFixture(fixtureDef)
	table.insert(bodiesArr,body)
 
 
 
	local jointDef = b2.createRevoluteJointDef(prevBody, body, 160 + i * 8, 150)
	jointDef.collideConnected = false
	world:createJoint(jointDef)
 
	prevBody = body
end
--]]
--step the world and then update the position and rotation of sprites
 
local myRopeShape = Shape.new()
myRopeShape:beginPath()
myRopeShape:setFillStyle(Shape.SOLID, 0xff0000)   
myRopeShape:setLineStyle(2,0xff0000,1)
stage:addChild(myRopeShape)
 
local function onEnterFrame()
	world:step(1/60, 8, 3)
	myRopeShape:clear()
	myRopeShape:setFillStyle(Shape.SOLID, 0xff0000)  
	myRopeShape:setLineStyle(2,0xff0000,1)
	myRopeShape:moveTo(bodiesArr[1]:getPosition())
 
	for i=2,#bodiesArr do
		myRopeShape:lineTo(bodiesArr[i]:getPosition())
		--print(bodiesArr[i]:getPosition())
	end
 
	for i=#bodiesArr,2,-1 do
		myRopeShape:lineTo(bodiesArr[i]:getPosition())
		--print(bodiesArr[i]:getPosition())
	end
	myRopeShape:endPath()
	myRopeShape:closePath()
	--[[
	for body,sprite in pairs(actors) do
		sprite:setPosition(body:getPosition())
		sprite:setRotation(body:getAngle() * 180 / math.pi)
	end
	]]
end
 
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
 
 
local debugDraw = b2.DebugDraw.new()
world:setDebugDraw(debugDraw)
--stage:addChild(debugDraw)
Sign In or Register to comment.