Circular Wraparound Layers ..

1 vote · 0 comments

From the MOAI forums:

.. an interesting technique for doing a wrap-around game, a la Pacman or Snake, where the edges propel the player back into the game field ..

Here is the MOAI pro way:

Render whole layer 8 more times with offsets. We can create layers and viewports and use partition from the main layer. You don't need 4 props for each object and checks when to enable/disable them. Since MOAI performs clipping for us, the overall performance hit will be minimal. Positions of all objects can be wrapped with modulo operation but they will still move smoothly. -- Vavius

raw ·
copy
· download
offsets = { { 2, 0}, {-2, 0}, { 0, 2}, { 0, -2}, { 2, 2}, {-2, 2}, {-2, -2}, { 2, -2}, } -- layer here is your main game layer which you want to wrap around partition = layer:getPartition () for i = 1, 8 do local viewport = MOAIViewport.new() -- viewport settings should be the same as in your main viewport viewport:setSize ( 320, 480 ) viewport:setScale ( 320, -480 ) viewport:setOffset ( unpack ( offsets [ i ] )) local layer = MOAILayer2D.new () layer:setViewport ( viewport ) MOAISim.pushRenderPass ( layer ) layer:setPartition ( partition ) end -- Vavius

Be the first to comment

Sign in with OpenID