Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
sprite follow a drawn path — Gideros Forum

sprite follow a drawn path

arcadiaarcadia Member
edited December 2012 in General questions
Hi,
I want to draw a shape/path and then move a sprite along that path.
I draw a shape with mouse and i store the x/y coords in mouse move event. Then with a timer i set the sprite position with that stored coords.
The problem is that i need a constant and normalized moviment and not the slower or faster mouse moviment.
I want to do something like this:
https://play.google.com/store/apps/details?id=com.playcreek.MagicWingdom

Dislikes: aditya

+1 -1 (+0 / -1 )Share on Facebook

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    You can use GTween library and tween between points and calculating tweening time dynamically based on the distance you need to travel between these two points. I think this should provide smooth movement.
  • arcadiaarcadia Member
    edited December 2012
    Ok thanks it is ok now. But now i have an other problem. I need to detect a collision between all the sprite that moves randomly with the sprite i move too but when my sprite is "under" gtween' interpolation it don t seems to detect the collision. Is ok when they just move random...
    And also: i have to do all with box2d? The moviment random, the moviment along the path and the collision? I do not use box2d
    Thanks i m new with gidetos and lua
  • @arcadia, no you don't need to mandatory use box2d.
    There are two ways to handle this:
    1) if you want simply check a bounding box collision between sprites, without rotation or any other modification, you can use this simple method:
    function Sprite:collidesWith(sprite2)
    	local x,y,w,h = self:getBounds(stage)
    	local x2,y2,w2,h2 = sprite2:getBounds(stage)
     
    	return not ((y+h < y2) or (y > y2+h2) or (x > x2+w2) or (x+w < x2))
    end
    2) if you have more complex shapes then boxes or you may also rotate/scale or otherly modify the the sprite, you'll need something more sophisticated than bounding box. For that you can use super fast TNT Collision Engine
    http://www.tntparticlesengine.com/?cat=15

    Likes: atilim

    +1 -1 (+1 / -0 )Share on Facebook
  • Thx solved with gtween for interpolation and tnt particleengine for collision
Sign In or Register to comment.