It looks like you're new here. If you want to get involved, click one of these buttons!
--Input (sprite2): another sprite to check for collision detection --Return: return true if the rectangles overlap otherwise return false function Sprite:collision(sprite2) -- self bottom < other sprite top if self:getY() + self:getHeight() < sprite2:getY() then return false end -- self top > other sprite bottom if self:getY() > sprite2:getY() + sprite2:getHeight() then return false end -- self left > other sprite right if self:getX() > sprite2:getX() + sprite2:getWidth() then return false end -- self right < other sprite left if self:getX() + self:getWidth() < sprite2:getX() then return false end return true end |
Comments
Right now this way is the best way. We'll consider embedding collision detection or geometry engine into Gideros API.
Thank!
https://sites.google.com/site/xraystudiogame
Talking about the anchor point, do people usually work with it set at top left for Sprites and center for Bitmaps (mix)? Or do you prefer to work with all anchors set at the same point and would it be top left or center?
(Even though it's not possible for Sprites right now but I believe @atilim said that support is coming soon.)
Likes: evs
evs
I asked on another thread about certain methods for TileMap which I couldn't find in the reference manual and was told because TileMap descends from Sprite it inherits the methods. Thats fine but I dont see a class diagram anywhere so not sure how I discover all these goodies!
Cheers
Gary
http://www.giderosmobile.com/documentation/reference_manual.html
You can notice things like:
Sprite > EventDispatcher meaning Sprite inherits all EventDispatcher methods
TileMap > Sprite meaning TileMap inherits all Sprite methods and EventDispatcher methods
BUT since i'm using it on a lots of objects, it's slowing my game down.
Is there any better way? Or API implementation is anywhere close on the roadmap?
Will something like this work better?
but i don't know how to implement any "OR"s ?
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
Sprite:getBounds maybe?\
I wonder what is the slowest statement in this function
This function should be added back to the class reference documentation.
http://www.giderosmobile.com/forum/discussion/1279/how-do-i-get-the-bounds-of-a-sprite
http://wujitouch.com
why there is no such thing in api?
everyone should use this code over the old one
and ofc this should be added to documentation.
Likes: sunnyguy, bali001
www.tntengine.com
Likes: sunnyguy
One question though - if I wanted to shrink the hitbox so that there was a padding of say 5 pixels around the outside, how would I do that?
Thanks
try this...
taken from my upcoming collision lib (this is original prototype lua code... it's quite fast)
my next lib will be C++ native and for this example/collision check is about 30% faster...
anyway...
you can set width and height and also set collision handle so...
let me know...
www.tntengine.com
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
form c code a "Gideros lua" function (getBounds) and get back result to c code
....but is it's very slow...
but yes in this lua version you can use getBounds...
www.tntengine.com
Thanks
Tom
---------------------------------------