Can a user interact directly with a sprite? In other words, can a sprite respond to an event? Can a user touch a sprite on screen and me know about it so I can manipulate the sprite?
Thanks…
[import]uid: 5540 topic_id: 605 reply_id: 300605[/import]
Can a user interact directly with a sprite? In other words, can a sprite respond to an event? Can a user touch a sprite on screen and me know about it so I can manipulate the sprite?
Thanks…
[import]uid: 5540 topic_id: 605 reply_id: 300605[/import]
I ask alot of questions around here, so I will try to help you out. There may be another way to do this, but this worked for me.
You need to set the sprites location to equal a place holder object. If you open the Follow Me sample code and set the alpha of one of the boxes to 0 or do like I did and use and blank .png then you will have a place holder to work with. From this point on, you will need to move the place holder instead of the sprite and will need to disable the player from being able to move the placeholder while you are moving it or it will go crazy.
– This part needs to constantly happen so use an EnterFrame
local function onEnter(event)
Sprite.y = Holder.y
Sprite.x = Holder.x
end
Runtime:addEventListener(“enterFrame”,onEnter) [import]uid: 4871 topic_id: 605 reply_id: 1185[/import]
Thanks very much for the reply… I’ve just discovered the “Follow Me” example and I’ll have to experiment with that.
So let’s theorize for a second with something we probably all know. For a game like Bejeweled 2 on the iPhone… would they have created each of those jewels as a sprite (for the sparkle and explode animations) and have an invisible place holder object behind each one of them?
I have much experimentation to do. Thanks for the info!
[import]uid: 5540 topic_id: 605 reply_id: 1187[/import]
The plot thickens!
I have verified that sprites *WILL* respond to touch events. A pseudo code example:
=====
myAnim = sprite.newAnim{“image1.png”, “image2.png”, “image3.png”, “image4.png”, “image5.png”}
myAnim:stopAtFrame(1)
function onTouch( event )
local t = event.target
local phase = event.phase
if “began” == phase then
t.stopAtFrame(2)
return true
end
end
myAnim:addEventListener( “touch”, onTouch )
=====
I’ve verified (with print statements that I have removed here) that when I touch the sprite the onTouch event does get triggered and it runs all the way to the “t.stopAtFrame(2)” line… but the sprite doesn’t change to frame 2. But it does GET there… which means I don’t need an invisible place holder object. I just need to figure out why the sprite frame doesn’t change…
[import]uid: 5540 topic_id: 605 reply_id: 1188[/import]
Ugh… I think Corona needs some better run-time/compile-time error checking!
myAnim.stopAtFrame(1)
is wrong and doesn’t work. However, Corona doesn’t catch it or flag it during the build or in the simulator in any way. It simply doesn’t work and I get no indication why.
myAnim:stopAtFrame(1)
is the correct form. A colon instead of a period.
That little error took me an hour to catch!
[import]uid: 5540 topic_id: 605 reply_id: 1192[/import]
Trust me, we here have been bitten by the : . notation, specially some of us C++ heads
C [import]uid: 24 topic_id: 605 reply_id: 1196[/import]
Just looking at the above, and trying to figure out how to create an on-touch event for a button to move a sprite animation left/right/jump, any idea?
Please check out Corona University and browse some of the sample projects. You may get a good starting foundation there.
http://www.coronalabs.com/resources/tutorials/sample-code/
You may also want to check out TangG apps, a great resource for Corona game templates, samples, etc.
http://www.tandgapps.co.uk/resources/coronalabs-resources/
Best regards,
Brent Sorrentino
Just looking at the above, and trying to figure out how to create an on-touch event for a button to move a sprite animation left/right/jump, any idea?
Please check out Corona University and browse some of the sample projects. You may get a good starting foundation there.
http://www.coronalabs.com/resources/tutorials/sample-code/
You may also want to check out TangG apps, a great resource for Corona game templates, samples, etc.
http://www.tandgapps.co.uk/resources/coronalabs-resources/
Best regards,
Brent Sorrentino