Game Development Reference
In-Depth Information
quad = MOAIGfxQuad2D.new()
quad:setTexture(imageName)
quad:setRect(-(wd/2),(ht/2),(wd/2),-(ht/2))
prop = MOAIProp2D.new()
prop:setDeck(quad)
prop:setLoc(xPos, yPos)
layer:insertProp(prop)
return prop
end
magnet = newImage("myImage2.png",40,260)
robo = newImage("myImage3.png",40,-140)
robo:setParent(magnet)
magnet:moveLoc(170,170,3)
Notice that the robot has a magnet that pulls the robot along with it when we move the magnet.
Any operation performed will affect both the props.
Let's add some scaling at the end of the code:
magnet:moveScl(-0.5,-0.5,3)
Notice that both the magnet and the robot start to scale as they move. All of the attributes/traits are
inherited from the parent object when you set it as the parent of another. The resulting action can be
seen in Figure 10-9 .
Figure 10-9. Scaling affects both the images (using traits)
Search WWH ::




Custom Search