Hi, I am try to make a rope that is attached to a two ends, one end is at the top of the screen and the other is attached to a yoyo.
The effect i want to achieve is that when the yoyo is moved (using the directional keys) the ‘rope’ moves along with it for example if the down arrow is pressed, then the rope extends to the new position of the yoyo yet still being fixed at both ends.
The way i am currently doing this is that i have a runtime listener on enterframe which creates a new rope depending on the x and y position of the yoyo, however by doing this i have a blinking rope effect (due the the removing and re-creating of the display.newLine).
I am wondering if there is any other way of implementing such effect without the blinking effect i.e. a solid white rope?
Heres my code if anyone doesn’t understand my problem:
[lua]display.setStatusBar (display.HiddenStatusBar)
– Hides the status bar
_W = display.contentWidth
_H = display.contentHeight
local background = display.newImage (“jungle_bkg.png”)
– Sets the background
local yoyo= display.newRect( 0, 0, 50, 50 )
yoyo.x = 240
yoyo.y = 160
yoyo:setFillColor(100, 230, 255)
local top = display.newRect( 0, 0, 10, 10 )
top.x = _W/2
top.y = 0
top:setFillColor(135, 255, 100)
local up = display.newImageRect( “up.png”, 40, 50 )
up.x = 100
up.y = 190
local down = display.newImageRect( “down.png”, 40, 50 )
down.x = 100
down.y = 270
local left = display.newImageRect( “left.png”, 50, 40 )
left.x = 60
left.y = 230
local right = display.newImageRect( “right.png”, 50, 40 )
right.x = 140
right.y = 230
– Puts in all four movement arrow images and positions them
local motionx = 0
local motiony = 0
local speed = 10
local function stop (event)
if event.phase ==“ended” then
motionx = 0
motiony = 0
end
end
Runtime:addEventListener(“touch”, stop )
– When no arrow is pushed, this will stop me from moving.
local function moveYoyo (event)
yoyo.x = yoyo.x + motionx
yoyo.y = yoyo.y + motiony
end
Runtime:addEventListener(“enterFrame”, moveYoyo)
– When an arrow is pushed, this will make me move.
function up:touch()
motionx = 0
motiony = -speed
end
up:addEventListener(“touch”, up)
function down:touch()
motionx = 0
motiony = speed
end
down:addEventListener(“touch”, down)
function left:touch()
motionx = -speed
motiony = 0
end
left:addEventListener(“touch”,left)
function right:touch()
motionx = speed
motiony = 0
end
right:addEventListener(“touch”,right)
– The above four functions are stating the arrows should all listen for touches and defining
– the way I should move based on each touch.
function DrawLine()
if line then
line:removeSelf()
line = nil
else
line = display.newLine(top.x, top.y, yoyo.x, yoyo.y )
–line:setColor(math.random(255), math.random(255), math.random(255))
line.width = 10
end
end
Runtime:addEventListener(“enterFrame”, DrawLine)
–drawline creates a line[/lua]
Thanks
[import]uid: 34863 topic_id: 29838 reply_id: 329838[/import]