Changing Image When Dragged

Can someone get me headed in the right direction with regard to animation of a character.

I’ve been learning and working on the beginnings of a game. I wrote a bunch of code for an image object using a touch event listener (to play sound when it begins moving, rotate left and right for single and double tap, etc.).

First (broader) Question:
Now I want to start adding some animation, such as the image changing to a different one as soon as the object “launches” (is dragged), and later when it gets near another type of image object. Apparently the movieclip library is what I should use. However, it seems to have it’s own drag method. So now … do I rewrite everything, calling functions from within object:setDrag( ) ?!

Second Question:
So I started experimenting with the movieclip functions, and got the image to change when the user drags. However it changes back to the first image as soon as it’s clicked on again. I’m sure that’s easily solvable, but before I start adding a bunch of code…
(First question again): Do I now just start adding functions within the movie drag event for the gameplay, replacing all my touch event code, such as for sound and image changes, responses?

Tet code:

local movieclip = require "movieclip"  
   
myAnim = movieclip.newAnim{ "sitting.png", "flying.png" }  
myAnim.x=100  
myAnim.y=100  
function changeTo()  
 onPress=myAnim:nextFrame()  
end  
  
-- Make sprite draggable  
 myAnim:setDrag{   
 drag=true,  
 onPress=changeTo  
 --- add more actions here  
 }  

Third Question: I notice the movieclip library has it’s own event listener - I notice I don’t have to use
Runtime:addEventListener(“touch”, whatever)? However, I don’t want to have to mess with customizing the movieclip library to add single/double tap rotation, etc.

Sorry if my first question is too general. I just don’t want to waste a lot of time reinventing the wheel …

Thanks!

Eric [import]uid: 128346 topic_id: 24174 reply_id: 324174[/import]

This is purely my opinion but I’d actually think that using a normal sprite may be easier for this.

You could then add listeners in the way you are used to and easily change the image when needed while NOT setting it back to the first frame on drag if you didn’t want to. (Just by keeping track of currentFrame.)

Is this a possibility here?

Peach :slight_smile: [import]uid: 52491 topic_id: 24174 reply_id: 97656[/import]

Peach,
Funny you should mention sprites. I was studying them, then went and did a search and found a forum posting about how to change an image when dragged, and they suggested using movieclips:
http://developer.anscamobile.com/forum/2011/01/18/change-image-touch

So I went off in that direction. But I’ll go back and do some experimental sprite stuff. Thanks.

I’ve run across some pages that suggest sprites are associated with something called Corona “Game Addition”? Is that no longer the case?

I looked at the sample code “JungleScene” and it uses 'require “sprite” ', but I see no sprite.lua in the folder, like there was a moviclip.lua for programs that use that. So where is it pulling the sprite library from? If it’s part of the main API why use “require”?

By the way Ansca Mobile, unless I’m mistaken, the Advanced Animation Using Sprites page has some unclear documentation: Under Sprite API it gives statements such as “si = sprite.newSprite( spriteSet )” or “si:prepare([sequence])” without explaining that “si” (which I assume stands for “sprite instance”) is just an example (object) and not part of the syntax per se. It would be better to assume the (muddle-headed newbie) reader doesn’t already know what you are talking about, and spell it out like in the docs where it says, for example, “spriteInstance:prepare()”.
http://developer.anscamobile.com/reference/index/spriteinstanceprepare
Having to untangle this kind of thing takes up time.

Oh! Was about to make a sprite sheet to test: how does this work with different resolutions of screens – right now I’m using the context scaling in the config.lua file and making graphics at different sizes?

Thanks!
[import]uid: 128346 topic_id: 24174 reply_id: 97725[/import]

Hey,

Yeah, I suppose is a matter of opinion - mine being sprites are better :wink: That doesn’t make it fact, though, I just find them easier to work with efficiently.

Corona “Game Edition” is retired, now whether you are Indie or Pro you have access to all the features that were previously just in Game Edition :slight_smile:

When you use require “sprite” you don’t need to add a file, it will work automatically. (When you build it will be included but you wont see it.) It’s a behind the scenes kind of thing :wink:

RE the docs, I’m sorry you found them confusing, we are in the process of updating the docs so hopefully some of these things can be remedied as we move forward.

Lastly I don’t have much experience with this but I believe making the sprite quite sizable and then scaling it down in your code should do the trick.

Peach :slight_smile: [import]uid: 52491 topic_id: 24174 reply_id: 97869[/import]