Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Sprite animation question
Started by ammar71 Dec 05 2019 04:23 PM

2 replies to this topic
sprite newsprite timers

Best Answer AngelaMcCall , 06 December 2019 - 02:44 AM

Hi Anmar71,

I've a similar situation going on in my game using overlays.

Are you able to restrict the ability to click on objects whilst the animation is doing it's thing.
Not sure if this is the correct way to resolve it, but its the path I am taking in my game...

EG

 

In my overlay scene I have:

SCENE SHOW WILL:
 

    local parent = event.parent  -- Reference to the parent scene object    

    if ( phase == "will" ) then
        -- Code here runs when the scene is still off screen (but is about to come on screen)
        print("OL5 SHOW EVENT WILL"--testing

        -- ================================================================================================
        -- MANAGE PARENT SCENE
        -- hide the parent scenes groupMain ( so all hit navigation objects and the btnBackPackClosed are disabled and invisable )
        parent:disableGroupMain()
        parent:disableGroupUserInterface()
        parent = nil
       

Then in the parent scene, I have...
 

-- -----------------------------------------------------------------------------------
-- GLOBAL FUNCTIONS SPECIFIC TO THIS PARENT SCENE
-- -----------------------------------------------------------------------------------

-- create global functions that live in this scene,
-- so that the OL1-InventoryBag can call them to hide/show the groupMain
function scene:disableGroupMain() groupMain.isVisible = false end
function scene:enableGroupMain() groupMain.isVisible = true end
-- so that the OL2-Notifications can call them to hide/show the groupUserinterface (also OL2-Notifications)
function scene:disableGroupUserInterface() 
    print("disableGroupUserInterface")
    
    groupUserInterface.isVisible = true
    groupUserInterface.isHitTestable = false 
    groupMain.isVisible = true
    groupMain.isHitTestable = false
end
function scene:enableGroupUserInterface() groupUserInterface.isHitTestable = true end

I am currently testing the ability to turn off the objects own ability to receive hits, whilst the overlay is doing it's thing, this then prevents players from moving to another scene whilst my popup message is on screen.

I've not yet done anything with Sprites, so not sure if this approach, is even possible for you with the animations, but from what I gather, you need a way to control the underlaying objects, that is managed by the animation.

The other thing that comes to mind, is that an Overlay is destroyed when it is closed. Meaning the destroy and hide scene events are guaranteed to be run, so could you call to removeself() the objects then? If needs be put the function to call in the parent scene where the object lives and using the parent event to call it from the overlay??

 

I hope these ideas give you some food for thought.
Good luck :-)
Angela

 

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

ammar71

[GLOBAL: userInfoPane.html]
ammar71
  • Enthusiast

  • 86 posts
  • Corona SDK

Hello all,

 

I am working on an app where the user needs to move from one scene to the next by tapping on objects on the screen. To make it clear that the user needs to tap, I thought I could show a tapping finger animation. Since such animation would be used on a number of scenes, it makes sense to put it in a global module and call it from there.

 

I did write a function inside a module and I added a sprite animation to it and I added a timer to remove the sprite after 2 seconds. Then I call that function from the "show" event of a scene.

 

This works well, until the user clicks too quickly (while the animation is still playing) and moves to a new scene where the animation function is called again. I am getting the following error: 

attempt to call method 'removeSelf' (a nil value)

My code is as follows:

local M = {}

local tap_animation
local function remove_tap_finger()
  tap_animation:removeSelf()
end
-- Shows a finger, tapping on the screen for a short period.
function M.show_tap_finger()
  local sheetData = { width=100, height=143, numFrames=2, sheetContentWidth=200, sheetContentHeight=143 }
  local tap_sheet = graphics.newImageSheet( "graphics/tap_sheet.png", sheetData )
  local sequenceData = {{ name="seq1", sheet=sheet1, frames= { 1, 2, 1, 2, 1 }, time=1500, loopCount=1 },}
  tap_animation = display.newSprite( tap_sheet, sequenceData )
  tap_animation.x = display.contentCenterX ; tap_animation.y = display.contentCenterY
  tap_animation:play()
  timer.performWithDelay( 2000, remove_tap_finger )
end

Another problem with the function above is that when I move to the next scene before the animation is finished, the animation continues in the next scene. I want the animation to stop (and object removed) if the scene changes.

 

I know I can solve this by adding the animation function to each scene and adding the sprite to the sceneGroup of that scene, but is there a way to do it globally so that I don't have to rewrite the function in every scene?

 

Thanks.



[TOPIC: post.html]
#2

AngelaMcCall

[GLOBAL: userInfoPane.html]
AngelaMcCall
  • Enthusiast

  • 52 posts
  • Corona SDK

  Best Answer

Hi Anmar71,

I've a similar situation going on in my game using overlays.

Are you able to restrict the ability to click on objects whilst the animation is doing it's thing.
Not sure if this is the correct way to resolve it, but its the path I am taking in my game...

EG

 

In my overlay scene I have:

SCENE SHOW WILL:
 

    local parent = event.parent  -- Reference to the parent scene object    

    if ( phase == "will" ) then
        -- Code here runs when the scene is still off screen (but is about to come on screen)
        print("OL5 SHOW EVENT WILL"--testing

        -- ================================================================================================
        -- MANAGE PARENT SCENE
        -- hide the parent scenes groupMain ( so all hit navigation objects and the btnBackPackClosed are disabled and invisable )
        parent:disableGroupMain()
        parent:disableGroupUserInterface()
        parent = nil
       

Then in the parent scene, I have...
 

-- -----------------------------------------------------------------------------------
-- GLOBAL FUNCTIONS SPECIFIC TO THIS PARENT SCENE
-- -----------------------------------------------------------------------------------

-- create global functions that live in this scene,
-- so that the OL1-InventoryBag can call them to hide/show the groupMain
function scene:disableGroupMain() groupMain.isVisible = false end
function scene:enableGroupMain() groupMain.isVisible = true end
-- so that the OL2-Notifications can call them to hide/show the groupUserinterface (also OL2-Notifications)
function scene:disableGroupUserInterface() 
    print("disableGroupUserInterface")
    
    groupUserInterface.isVisible = true
    groupUserInterface.isHitTestable = false 
    groupMain.isVisible = true
    groupMain.isHitTestable = false
end
function scene:enableGroupUserInterface() groupUserInterface.isHitTestable = true end

I am currently testing the ability to turn off the objects own ability to receive hits, whilst the overlay is doing it's thing, this then prevents players from moving to another scene whilst my popup message is on screen.

I've not yet done anything with Sprites, so not sure if this approach, is even possible for you with the animations, but from what I gather, you need a way to control the underlaying objects, that is managed by the animation.

The other thing that comes to mind, is that an Overlay is destroyed when it is closed. Meaning the destroy and hide scene events are guaranteed to be run, so could you call to removeself() the objects then? If needs be put the function to call in the parent scene where the object lives and using the parent event to call it from the overlay??

 

I hope these ideas give you some food for thought.
Good luck :-)
Angela

 


  • ammar71 likes this

[TOPIC: post.html]
#3

ammar71

[GLOBAL: userInfoPane.html]
ammar71
  • Enthusiast

  • 86 posts
  • Corona SDK

@AngelaMcCall

 

I guess I could use a (global) flag that I set when the animation starts and clear when it finishes, then use that flag to disable/enable "tap" events in the scene. I will give it a try.

 

Thanks Angela.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: sprite, newsprite, timers