简体   繁体   中英

How to Allow Partial Passability (Corona SDK)

I am making an app where a square bounces back and forth across the screen and the user controls a column with a hole in the middle and has to drag the column to allow the square to pass through. I am having trouble with the column however. The column is using this art ( https://gyazo.com/abfd0e166988178fa5e7f2bba7916a36 ) and I am having issues with the "gap" in the center. When the square moves around, it bounces off of the gap as if it were a solid object. Is there anyway to allow the square to pass through the gap without loading the columns as two separate items?

You can specify multiple shapes to create a multi-element body .

physics.addBody( object, "static",
    { bodyElement1 },
    { bodyElement2 },
    --etc.
)

In your case, it would look like this (of course, you'll have to tweak the values to fit the image):

local column = display.newImage( "column.png" )
local leftShape = { -40,-10, -20,-10, -20,10, -40,10 }
local rightShape = { 40,-10, 20,-10, 20,10, 40,10 }

physics.addBody( column, "dynamic",
    { shape=leftShape },
    { shape=rightShape }
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM