I couldn’t find any physics sample code that uses the game API sprite library, so maybe this isn’t working yet. I’d assume the sprite would appear as a DisplayObject. [import]uid: 3953 topic_id: 1595 reply_id: 301595[/import]
Thanks for your answer but you’ve got the wrong question.
I’m familiar with incorporating physics engines into realtime graphics apps.
I want to use Sprites (in the context of the native sprite library: require(“sprite”) and created with: sprite.newSprite(spriteSet)) as rigid bodies, but all the Corona samples, including the one you point to, use DisplayObjects (as in: addBody(DisplayObject)).
When I try to do the same with a Sprite instance, the simulator crashes.
I assumed that the Sprite object would behave similarly to a DisplayObject in terms of attaching rigid bodies etc. [import]uid: 3953 topic_id: 1595 reply_id: 4611[/import]
You can apply physics to it and be able to control what what frame in the moiveclip will play. [import]uid: 8045 topic_id: 1595 reply_id: 4620[/import]
Yes, MovieClips work fine because they’re just DisplayObjects wrapped in Lua code.
The question was about using Game SDK Sprites with physics.
I already have my own C++ framework that handles indexed sprite sequences using texture atlases with attachable 2D rigid bodies (using the Chipmunk lib). I was hoping in switching to Corona I could focus on game logic rather than low level coding. DisplayObjects - and by extension MovieClips - are not a suitable alternative to sprite sheets for games. [import]uid: 3953 topic_id: 1595 reply_id: 4659[/import]
I’ve tested this, and it seems to work fine for all three physics body types. Here’s working code (using some of the assets from “JungleScene”):
local physics = require( "physics" )
physics.start()
require "sprite"
display.setStatusBar( display.HiddenStatusBar )
local baseline = 280
-- A sprite sheet with a green dude
local sheet2 = sprite.newSpriteSheet( "greenman.png", 128, 128 )
local spriteSet2 = sprite.newSpriteSet(sheet2, 1, 15)
sprite.add( spriteSet2, "man", 1, 15, 200, 0 ) -- play 15 frames every 200 ms
local instance2 = sprite.newSprite( spriteSet2 )
instance2.x = 3 \* display.contentWidth / 4 + 30
instance2.y = baseline - 55
instance2:prepare("man")
instance2:play()
physics.addBody( instance2, "kinematic", { density = 1.0, friction = 0.5, bounce = 0.2 } )
Not sure what’s different here from your example (?) And you are correct that a sprite instance is a display object and should behave similarly in this context. [import]uid: 3007 topic_id: 1595 reply_id: 4966[/import]
Thanks for the response. You’re right of course. I omitted physics.start() before addBody(), causing the simulator to blow up. [import]uid: 3953 topic_id: 1595 reply_id: 4985[/import]