anyone know how to change a sprite or change a animate in accelerometer?
thanks [import]uid: 23063 topic_id: 10046 reply_id: 310046[/import]
anyone know how to change a sprite or change a animate in accelerometer?
thanks [import]uid: 23063 topic_id: 10046 reply_id: 310046[/import]
anyone? [import]uid: 23063 topic_id: 10046 reply_id: 37325[/import]
Hey there,
I am not sure what “in accelerometer” means. Do you mean if the device is tilted at all you want the sprite to play a different sequence?
Peach
[import]uid: 52491 topic_id: 10046 reply_id: 37595[/import]
yea i want when you move the device, change the sprite of my object
EDIT: my object is a ghost that i want to anime to looks like his is floating but when I have tryed with animation function… was too fast and i dont know how to slow down this animation… any idea? [import]uid: 23063 topic_id: 10046 reply_id: 37620[/import]
You need to check out the Sprite API - you can define the frame rate to make it any speed you like 
http://developer.anscamobile.com/reference/index/spritenewsprite
For changing the animation based on tilt, check out the tutorials available both on Corona and on Techority regarding moving an object using the accelerometer - you’d just add a line of code to play a different sprite when the device was tilted.
Peach
[import]uid: 52491 topic_id: 10046 reply_id: 37742[/import]
Hello there, @peach pellen, I have something similar going on with my sprites. Essentially I got my sprite to animate and work properly, however, when I implement a onTilt function (accelerometer), my sprite doesn’t respond very well: It tilt responds to the tilts but it seems like it’s always tending to go to the the -x by default: Here’s a sniped of my code (remember I am new using Corona SDK and Lua):
local acc = {}
local centerX = display.contentWidth * 0.5
function acc:accelerometer(e)
spriteGreenInstance.x = centerX + (12 * e.xGravity)
if (spriteGreenInstance.x > _W) then
direction_green_man = direction_green_man * -1;
spriteGreenInstance:scale(-1 , 1);
elseif(spriteGreenInstance.x < 0) then
direction_green_man = direction_green_man * -1;
spriteGreenInstance:scale(-1, 1);
end
–[[ if (e.xGravity > 0) then
direction_green_man = direction_green_man * 1;
spriteGreenInstance:scale(-1, 1) --go opposite direction
elseif(e.xGravity < 0) then
direction_green_man = direction_green_man * -1;
spriteGreenInstance:scale(-1, 1);
end
–physics.setGravity( (10 * event.xGravity), (-10 * event.yGravity));]]–
end
Runtime:addEventListener(“accelerometer”, acc)
… and here’s my sprite animation code:
–GREENMAN –
local green_man_sprite = sprite.newSpriteSheet(“greenman.png”, 128, 128);
local greenman_sprite_set = sprite.newSpriteSet(green_man_sprite, 1, 15);
sprite.add( greenman_sprite_set, “greenman”, 1, 15, 200, 0 ) – play 15 frames every 200 ms
local spriteGreenInstance = sprite.newSprite( greenman_sprite_set );
spriteGreenInstance.x = _W * 0.5;
spriteGreenInstance.y = display.contentHeight * 0.5 + 70;
spriteGreenInstance:scale(1, 1);
spriteGreenInstance:prepare(“greenman”)
spriteGreenInstance:play()
I can’t really figure out what am I doing wrong in this code. Can you help me, please? I would really appreciate it! Thanks [import]uid: 75258 topic_id: 10046 reply_id: 48541[/import]
Hey there,
In future please post your code in < lua > tags or < code > tags as I can’t read the above without getting a bit of a headache 
Have you previously managed to implement tilt without a sprite, just a normal image?
When using the accelerometer it’s often easier to get tilt working how you want with a normal object and then go through and add in events for the sprite.
Let me know and I’ll try to steer you in the right direction 
Peach [import]uid: 52491 topic_id: 10046 reply_id: 48552[/import]
Hello Peach,
I am sorry for the plain text code I posted… oops! My bad, I should have read the guidelines prior to start posting.
Thank you very much for your promptness on the reply. I highly appreciate your time. I haven’t tried using just a plain image yet. I thought about it (movieClip() function). I will try it out and will report!
Again, Thank you for you response.
Dichone [import]uid: 75258 topic_id: 10046 reply_id: 48650[/import]
Hey Dichone, no worries 
Try out a normal image first - I actually have a tutorial on http://techority.com for moving a normal image/physics body with the accelerometer that could start you out.
Look at that and then once you fully understand it, then move on to implement your animations - it will make it a much easier process 
Here’s a link to my sample for the accelerometer; http://techority.com/2010/11/19/control-an-actor-with-the-accelerometer/
Look forward to hearing how you go!
Peach
[import]uid: 52491 topic_id: 10046 reply_id: 48750[/import]