Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

how do you loop through single images at a time by tapping on a button
Started by Bigland Feb 13 2010 01:15 AM

- - - - -
3 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Bigland

[GLOBAL: userInfoPane.html]
Bigland
  • Observer

  • 10 posts
  • Guests

Hi,
I have seen how random pictures can be displayed by shaking.

How do you loop through one image at a time by tapping a button?
I've picked up pieces but do not know how to use the loop statement

local button = display.newImage("image_selector_button.png", 250, 410, 0, 0)
local plate = {"image1.png", "image2.png", "image3.png"};

function button:tap( event )
*** how do you loop through those images with each tap? *****
--local dial = display.newImage("compass_dial2.png", 5, 125, 0, 0)
end
button:addEventListener( "tap", button )
Please advice
uid: 3482 topic_id: 495 reply_id: 300495


[TOPIC: post.html]
#2

afyzendo

[GLOBAL: userInfoPane.html]
afyzendo
  • Observer

  • 25 posts
  • Guests

Hello Bigland,

Here is my solution to your question. The imageIndex variable remembers where we are in the list of images (1, 2, 3...). At each click the current image is removed, the next index is computed and the next image is shown. I hope this helps.

Cheers, Arjan van IJzendoorn

local button = display.newImage("image_selector_button.png", 250, 410, 0, 0)
local plate = {"image1.png", "image2.png", "image3.png"}

-- Remember the index of the image that is currently being shown.
local imageIndex = 1
-- Show the first image.
local image = display.newImage(plate[imageIndex])
function button:tap( event )
	-- Remove current image.
	display.getCurrentStage().remove(image)
	-- Compute index of next image.
	imageIndex = imageIndex + 1
	-- If we have reached the end, go back to the first.
	if imageIndex > #plate then
		imageIndex = 1
	end
	-- Add new image
	image = display.newImage(plate[imageIndex])
end
button:addEventListener( "tap", button )
uid: 4824 topic_id: 495 reply_id: 969


[TOPIC: post.html]
#3

Bigland

[GLOBAL: userInfoPane.html]
Bigland
  • Observer

  • 10 posts
  • Guests

Thank you very much. It works like a charm!!!!!

I didi not read about imageindex anywhere in the documentation that came with the package or did I miss it?

Where can I find more documentation regarding the language syntax?
uid: 3482 topic_id: 495 reply_id: 977


[TOPIC: post.html]
#4

afyzendo

[GLOBAL: userInfoPane.html]
afyzendo
  • Observer

  • 25 posts
  • Guests

imageindex is not something special. It is just a name I chose for the variable. I could have used i or x or imageNr or anything else.

The language Corona uses is Lua and you can find more information about Lua here:

http://www.lua.org/docs.html

Programming in Lua (first edition) can be browsed for free at http://www.lua.org/pil/
uid: 4824 topic_id: 495 reply_id: 978



[topic_controls]
[/topic_controls]