say I have a floor in my world, so that my balls can bounce off it and off my stage (out of the side)
what happens to my sprite/body?
at the moment i have a BallActor class and this contains my sprite. the sprite also has a reference back to the actor so that i can access it during collisions
eg
[lua]obj = new BallActor()
print(obj.sprite) – will return a table reference to the sprite created in the BallActor class
obj.sprite.actor = obj – set reference back to actor
physics.addBody(obj.sprite)
local function onCollision( event )
local obj1 = event.object – ie my sprite
local actor = obj1.actor
…
end[/lua]
depending what Corona does with my sprite/body when it leaves the stage will affect what I can do with my actor (eg does my sprite reference still exist or has Corona removed it when it left the stage bounds etc)
presumably corona isn’t going to just remove the body outside the screen, since otherwise i could never have a game world bigger than my screen!.. but what I was wondering also is if my floor is a rectangular sprite the width of the screen, presumably my ball (for instance) can bounce off the floor, out of the screen and then drop below. Do I need to manage it’s existence based on the y position in that case? Does it just keep falling otherwise? Does the Corona engine enforce any limits itself? [import]uid: 6645 topic_id: 3453 reply_id: 10363[/import]
my guess is that it keeps falling. Just do a test with an object and print out its coordinates. [import]uid: 5712 topic_id: 3453 reply_id: 10373[/import]
i’ll check if its x is outside the screen in this instance and remove/recycle it
my other question is how to best remove it from it’s actor efficiently
if i remove the sprite, i cant reference the actor directly so is what i did above the best way to do it?
[lua]local obj1 = event.object – ie my sprite
local actor = obj1.actor – the class that created the sprite
obj1:removeSelf()
actor=nil – wont this just delete my local reference to my actor, rather than removing the actor itself[/lua]
would i be better keeping a allActors array (local to my main application) and removing it from there?
[lua]local function onCollision( event )
local obj1 = event.object – ie my sprite
local actor = obj1.actor
…
local actorToRemove = splice(onScreenActors[instanceOf(onScreenActors, obj1.actor)],1)
push(actorsToRemove, actorToRemove)
end
local function removeDeadItems()
for i = #actorsToRemove,1,-1 do
local actor = actorsToRemove[i]
actor.sprite:removeSelf()
– not needed?
– actorsToRemove[i]=nil
– actor=nil
end
actorsToRemove={}
end[/lua]
(note splice, push etc are my own functions, not native)
Your actor is stored inside the display object. Any displayobject that will be removed and has custom properties (your actor for an example) turn into a simple table that has to be removed then by assigning nil to it.
[lua]local obj1 = event.object – ie my sprite
local actor = obj1.actor – the class that created the sprite
obj1:removeSelf()
obj1=nil[/lua]
my other question is how to best remove it from it's actor efficiently
Actually you have the actor attached to the object, not opposite. [import]uid: 5712 topic_id: 3453 reply_id: 10417[/import]
Actually it’s a circular reference I think. My main app creates an instance of my Actor class which creates sprite. Then in my main app I am setting actor.sprite.actor = actor . I don’t know if this is a bad idea but it allows me to reference my actor from the event object. I just don’t know how to remove everything properly. Maybe I would be better not doing this and having an allActors(sprite) lookup instead? [import]uid: 6645 topic_id: 3453 reply_id: 10425[/import]