Corona Builds

Can I just check that certain functionality is only available in the subscription version and I will have to pay to use it and won’t be available in the free version.

An example:

I am using the free version in an attempt to tie in my development to the Corona platform. I have been trying to remove a physics body but the version I have is 2011.591 (the free one) but reading the documentation at http://developer.anscamobile.com/node/13673 it states:

physics.removeBody() : This API was added starting with Daily Build 2011.598. It’s not available in the 2011.591 Release build.

Is this really the case that I have no means of a workaround to achieve my proof of concept without paying out for the subscription version?

Thanks for your advice in advance

James [import]uid: 103970 topic_id: 18288 reply_id: 318288[/import]

A work around is to remove the object with the physics body, then spawn a body-less instance of the same object in the same exact spot. [import]uid: 10903 topic_id: 18288 reply_id: 70063[/import]

@crssmn - many thanks for the quick response could you provide an example. If removing via display.remove does this also remove the physics body?

Do you also happen to know if my post on the build free vs subscription is correct? [import]uid: 103970 topic_id: 18288 reply_id: 70069[/import]

It does remove the physics body, the you may also want to set your object to nil to remove any other references to it.

I was unaware of the physics remove body api, but just ran a test and it works for me. I have the latest daily build so that may be the case of free vs subscription. [import]uid: 10903 topic_id: 18288 reply_id: 70071[/import]

Unless I’m having a brain freeze not sure this will work for me. My bodies make up a chain similar to that of the bridge sample. Wouldn’t your suggestion mean it would collapse and be noticeably rebuilt?

[import]uid: 103970 topic_id: 18288 reply_id: 70073[/import]

Potentially, but I assume it would collapse if you used physics remove body as well. [import]uid: 10903 topic_id: 18288 reply_id: 70086[/import]

Removing the object and removing the physical body will have the same effect in terms of physics.

The only difference is that using obj:removeSelf() will remove the body AND the image, whereas using physics.removeBody(obj) will remove only the physical body.

A function like this would do the same thing as removing the physical body, just less effectively, so there is a workaround;
[lua]local arrow = display.newImage (“arrow.png”)
arrow.x = 160
arrow.y =240

require ( “physics” )
physics.start()
physics.setGravity( 0, 1 )

physics.addBody(arrow)

local function test ()
prevX, prevY = arrow.x, arrow.y
arrow:removeSelf()
local arrow = display.newImage(“arrow.png”)
arrow.x = prevX
arrow.y = prevY
end
timer.performWithDelay(2000, test, 1)[/lua]

Replace arrow with your own image and test with .591.

Peach :slight_smile: [import]uid: 52491 topic_id: 18288 reply_id: 70106[/import]

Thanks @crssmn and @peachpellen

I think I might be going about this all wrong so let me tell you what I am trying to achieve

I am creating a rope / chain with a starting point of the bridge sample. What I am trying to do is if user vwants rope longer then they tilt device and extra bodies get added and removed if tilted up

I don’t necessarily want to add and remove but simply to get the rope/chain to move up and down but need to handle the links showing and hiding. Because the anchor point is at the top most link and thus is most likely where the movement needs to happen from I can’t see how can I do it rather than adding or removing from the top

YScale and height transitions don’t work as is documented as the body isn’t scaled and I also need to recalculate the joints

Am I being over ambitious and is this even possible using Corona? [import]uid: 103970 topic_id: 18288 reply_id: 70129[/import]

Hey again,

I think that perhaps you’re being a little over ambitious if you’re still new to developing - this kind of thing would take some clever thinking, something that comes with a little experience.

I would go about it by adding a link every X seconds when tilted down, removing the bottom one every X seconds when tilted up - although I’m sure others might have different ideas about how to achieve the desired effect.

Certainly, it is possible in Corona.

Peach :slight_smile: [import]uid: 52491 topic_id: 18288 reply_id: 70137[/import]

Thanks Peach. Believe it or not I’m actually an experienced developer but as you know from my blog I am only a few weeks into Box2D and Corona so the syntax and game development in general is a little alien.

Can I be cheeky and ask for a small example as to how you would tackle this please to ensure I am not implementing any gotchas. I have prototyped this countless times now over the past few weeks and while I have it adding bodies correctly (sort of) the removal is causing me issues.

Thanks in advance :slight_smile: [import]uid: 103970 topic_id: 18288 reply_id: 70155[/import]

Right I am making some progress but it isn’t looking very natural :slight_smile:

[lua]require ( “physics” )
physics.start()
physics.setGravity( 0, 9.6 )

local link = {}

physics.setDrawMode( “normal” )

–> Create Walls
local leftWall = display.newRect (-5, 0, 1, display.contentHeight)
local rightWall = display.newRect (display.contentWidth, 0, 1, display.contentHeight)
local ceiling = display.newRect (0, 0, display.contentWidth, 1)
local floor = display.newRect (0, display.contentHeight, display.contentWidth, 1)

physics.addBody (leftWall, “static”, {bounce = 0.0, friction = 10})
physics.addBody (rightWall, “static”, {bounce = 0.0, friction = 10})
physics.addBody (ceiling, “static”, {bounce = 0.0, friction = 10})
physics.addBody (floor, “static”, {bounce = 0.0, friction = 10})

physics.addBody( ceiling, “static”, { density=0, friction=0.5,bounce=0.2 } )
local xCenter = 160
local wCeil = 120
local hCeil = -5
–local ceiling = display.newRect( xCenter - wCeil*0.5, 0, wCeil, hCeil )
physics.addBody( ceiling, “static”, { density=0, friction=0.5,bounce=0.2 } )

local prevBody = ceiling

local w,h = 10,22
local halfW,halfH = 0.5*w,0.5*h

– center of body
local x = xCenter
local y = hCeil - halfH
local yJoint = y - halfH
local linkCount = 15
local heightCount = 10

local group = display.newGroup()

– rope
for i = 1, linkCount do
y = y + h
yJoint = yJoint + h

link[i] = display.newImage(“link.png” ,x-halfW, y-halfH) --) display.newRect( x-halfW, y-halfH, w, h )

–body:setFillColor( 128, 0, 0 )
physics.addBody( link[i], { density=15, friction=0.5, bounce = .2 })
local joint = physics.newJoint( “pivot”, prevBody, link[i], xCenter, yJoint )

prevBody = link[i]

group:insert( link[i] )
end

local function test ()

– From the top ****************** DOESN"T WORK ******************

– Need this to have a slow transition of the slowly removing the top link or moving it up
– until out of view then and removing it and applying the second link in the chain to become
– the first and resetting the joints so that what was originally the second is now the one
– joined ot the ceiling

link[1].height = link[1].height - 2.2
link[2].y = link[2].y - 2.2
yJoint = yJoint + h
heightCount = heightCount - 1

if(heightCount == 0) then
link[1]:removeSelf()
heightCount = 10
end

– From the bottom ****************** DOES WORK ******************
– This works fine but doesn’t look natural
–[[

if(linkCount > 0) then
link[linkCount]:removeSelf()
linkCount = linkCount - 1
end

]]

end
timer.performWithDelay(500, test, 0)[/lua]

The bit in question is the test function. If I take from the bottom that is simple right but doesn’t look like the chain is being pulled from the top. If you think about pulling a tope or chain you pull from the top so therefore that should be the one that disappears right?

The challenge I have is that I need to either slowly transition the whole chain by the height of the link and then once totally removed from sight then remove it and reapply all the joints etc to its new positions etc and join it to the ceiling. This however seems a bit of a hack.

A little help in resetting the bodies and joints would be appreciated :slight_smile: [import]uid: 103970 topic_id: 18288 reply_id: 70209[/import]

A real hack would be moving the ceiling which kind of gives the effect I want …

[lua]transition.to(ceiling, {time=250, y = ceiling.y - 5, transition = easing.linear})[/lua]

… but this seems cheating and would also mean that I am limited to the aesthetics I could apply, for example I couldn’t have a crane with a pulley as the crane would effect have to move not the chain which is obviously not how a winch works

Any thoughts? [import]uid: 103970 topic_id: 18288 reply_id: 70210[/import]

Hey again - sorry, we have a bit of a time difference :wink:

I’m sorry, for some reason in this thread your name didn’t click - you’re right though, I recall from your blog you are not a new developer.

I like you last idea - I don’t see it as cheating, I see it as clever. It may not be how a winch really works, however if it works then it works :wink:

Peach :slight_smile: [import]uid: 52491 topic_id: 18288 reply_id: 70264[/import]

Indeed I think we are on the opposite sides of the world!

For some reason even though it works it doesn’t sit well with me and not sure I can implement the game as I intended

Do you have any comments based on your experiences of removing bodies and joints as I started coding below?

[lua]     link[1].height = link[1].height - 2.2
                        link[2].y = link[2].y - 2.2
                        yJoint = yJoint + h
                        heightCount = heightCount - 1
               
                        if(heightCount == 0) then
                                link[1]:removeSelf()
                                heightCount = 10
                        end[/lua]

But witht the same transitional effect I have in my hack?
[import]uid: 103970 topic_id: 18288 reply_id: 70320[/import]

I am sorry to say that no, I do not have any experience with this specific type of thing; and it is quite specific :wink:

Is there a specific reason it doesn’t sit well with you? Sometimes there’s a good reason, sometimes not so much - at least in my own experience.

Over time I’ve learned that it’s about making it work - provided you aren’t doing anything that will cause issues (memory leaks, bad performance, etc.) then making it work, however you do it, should be considered a victory - especially if it’s something fairly complex, which I would consider this to be.

Just my 2 cents.

Peach :slight_smile: [import]uid: 52491 topic_id: 18288 reply_id: 70336[/import]

Because I was looking to create a crane or winch that acted in a realistic fashion and not having to be masked because I don’t know how to remove joints and bodies correctly

I can probably mask with an overlayed image so that when the chain / rope moves up it remains behind the masking image but as I said this seems a hack.

Thanks for your input though much appreciated. I’ll endeavour to try and solve it but might need to move onto to another part and come back to this when I have more than 3 weeks experience of the framework [import]uid: 103970 topic_id: 18288 reply_id: 70343[/import]