How I can create an function image visible and invisible

Hi, I don’t see the problem - it does randomly create a new image?

Joakim [import]uid: 81188 topic_id: 21574 reply_id: 85627[/import]

Hello,

Hey my bad for the mis-spelling of isVisible…

copy and paste this in a new main.lua file
and run it…

see if I understand what your after…:slight_smile:

local ourBox = display.newCircle( 150, 150, 15 )  
-- just to keep it simple we will use a table you also could  
-- use a display.newGroup()  
local IDmg = {};  
ourBox.isVisible = false;  
local switchSeeMe = false;  
local rand = math.random;  
  
IDmg[1] = display.newImage("1.png");  
IDmg[1].isVisible = false;  
IDmg[2] = display.newImage("2.png");  
IDmg[2].isVisible = false;  
IDmg[3] = display.newImage("3.png");  
IDmg[3].isVisible = false;  
  
-- set up our first image  
local whichImage = IDmg[rand(3)];  
local function showCalciatore(show)  
  
 --local IDmg = rand..".png"  
 --local calciatore = display.newImage("1.png")  
  
 if show == true then  
 whichImage = IDmg[rand(3)];  
 whichImage.x = 200;  
 whichImage.y = 300;  
 end  
  
  
 if show == false then  
 -- print(" show :" .. show)  
 whichImage.isVisible = false;  
   
 elseif show == true then  
 -- print(" show :" .. show)  
 whichImage.isVisible = true;  
 end  
  
  
 print("\nshow: .. ",show);  
  
  
end  
-- print timer is running  
local function printTimer()  
  
  
  
 print("Timer Running!");  
 --using your function here  
 showCalciatore(switchSeeMe)  
  
  
 if switchSeeMe == false then  
  
 ourBox.isVisible = true;  
 switchSeeMe = true;  
  
 elseif switchSeeMe == true then  
  
 ourBox.isVisible = false  
 switchSeeMe = false;  
 end  
  
  
end  
  
-- cancel timer  
local function cancelTimer(e)  
  
 if e.phase == "ended" then -- up click from finger/mouse  
  
 -- stop our timer  
 timer.cancel(ourTimer);  
 print("Timer Cancelled!");  
  
 end  
  
end  
  
-- run our printtimer function every 2 seconds and loop forever  
ourTimer = timer.performWithDelay(2000, printTimer, -1); -- ie: -1 = loop forever 10 = run 10 times  
  
-- listen for a touch event on our screen  
-- ourBox:addEventListener("touch", cancelTimer); -- use our object as a button to stop  
Runtime:addEventListener("touch", cancelTimer);  

Hope this time it may help you… :wink:

EDIT: I think I posted this after you…got it to work…
man…I’m slow today… :wink:
Happy Programming…
Larry
[import]uid: 107633 topic_id: 21574 reply_id: 85624[/import]

Hi,
You mean using physics…?

--top of your .lua file  
local physics = require( "physics" );  
physics.start();  
  
local calciatore = display.newImage("1.png")  
physics.addBody( calciatore, "dynamic", { friction=0.5, bounce=0.3 } );  

something like that…

Good luck…:wink:
Larry
[import]uid: 107633 topic_id: 21574 reply_id: 85628[/import]

G R E A T ! ! !

Thank you a lot for your time

I reached my goal , thank at your help.

[import]uid: 100428 topic_id: 21574 reply_id: 85795[/import]