Slick Forums

Discuss the Slick 2D Library
It is currently Thu Jun 20, 2013 7:47 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Thu Jul 26, 2012 12:15 pm 
Offline

Joined: Tue May 22, 2012 8:24 pm
Posts: 49
How to make shape translate to x and y of mouse, when you click once on a position.

I would like it to move, for example, from point 0, 10 to point 500, 230. But I would like it to slowly move from one point to another... I don't want teleportation... How to do this ?


Top
 Profile  
 
PostPosted: Fri Jul 27, 2012 10:47 am 
Offline

Joined: Sun Jul 08, 2012 10:33 am
Posts: 27
hey PixelDeBurner,
im about to do it soon too so i can only give you my idea.
you got the source and destination positions so u can both save and then for example just add sx += (sx-dx)/abs(sx-dx) and sy += (sy-dy)/abs(sy-dy) in each update.
i hope my calcualtions are correct, im in a bit of a hurry ;) but i think you know what i mean

edit: for measurement of how fast the shape moves just compare a speed attribute with the delta of the update method.


Top
 Profile  
 
PostPosted: Fri Jul 27, 2012 1:21 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1477
Simplest/best way to do it IMO is to use a simple tween engine. This has the added bonus of giving your animation a bit more flare than a boring linear easing.


Top
 Profile  
 
PostPosted: Wed Aug 15, 2012 11:46 am 
Offline

Joined: Sun Jul 08, 2012 10:33 am
Posts: 27
this looks interesting. i tried it and wrote a particle class. now this particle should follow my mouse so i did:

Code:
update(...){
Tween.to(particle1, ParticleAccessor.POSITION_XY, 100f)
       .target(mouseX, mouseY)
       .start(manager);

manager.update(delta);
}


its working fine but is it right? i read that i should put this actually in the ini() method?!

edit: also the closer the particle gets to my cursor the slower it moves. can i turn this off somehow?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group