How to place an image in place of this button

Na classe pushButtonClass.lua usada para criar botões de mudança de cena, eu gostaria de saber como fazer na localização do botão display.newRect insira qualquer imagem para executar a mesma função de mudança de cena usando no caso o código display.newImage.

This is the file I was referring to.

It is found in all the programs made available by roaminggamer on the link posted in this youtube video.

https://www.youtube.com/watch?v=hsDiGvAFsZY

This file is located in the scripts folders of all programs

Sincerely, Leonam Reis Calatrone

First, welcome to the forums. We are glad you’re here.  Please keep in mind that for the best help, make your posts in English please unless you’re asking in a language specific forum. Now to your question!

You would simply replace display.newRect() with display.newImageRect() which takes a path to the image, width, and height as parameters.  You already have width and height with the display.newRect() call.

The one addition is you would need to position the image. display.newRect()'s first two parameters are the X and Y to draw the rectangle. You can use those values to move the image to where you want it by setting the .x and .y values after you create the image.  Assuming you have this as your display.newRect() call:

local myButton = display.newRect( display.contentCenterX, 100, 80, 50 )

You would use an image by doing:

local myButton = display.newImageRect( "button.png", 80, 50 ) -- note I'm making up values myButton.x = display.contentCenterX myButton.y = 100

or something like that.

Rob

Na classe pushButtonClass.lua usada para criar botões de mudança de cena, eu gostaria de saber como fazer na localização do botão display.newRect insira qualquer imagem para executar a mesma função de mudança de cena usando no caso o código display.newImage.
 
Portuguese Direct Translation:

In the pushButtonClass.lua class used to create scene change buttons, I would like to know how to do at the location of the display.newRect button to insert any image to perform the same scene change function using in the display.newImage code case.

 
Question:

Are you are asking, “How do I use any images I wish for the buttons” in that example?

Você está perguntando: “Como eu uso as imagens que desejo dos botões” nesse exemplo?

Original code: https://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/composer_scene_manager.zip

For now, I will assume you want to use arbitrary images for the buttons.  Let me look and answer back soon.

Por enquanto, assumirei que você deseja usar imagens arbitrárias para os botões. Deixe-me olhar e responder em breve.

@leonam

Let me direct you to a more up-to-date version of those button classes:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2016/03/oop_img_button.zip

This version of the buttons classes allows you to specify the images when you make the buttons:

require "scripts.pushButtonClass" require "scripts.toggleButtonClass" require "scripts.imgPushButtonClass" local group = display.newGroup() -- Image Push Button Samples local buttonA = ImagePushButton( group, centerX - 125, centerY + 3 \* tweenButtons, "", onPlay, { width = 100, height = 100, unselImg = "images/gel/buttonA.png", selImg = "images/gel/buttonAOver.png" } ) local buttonB = ImagePushButton( group, centerX, centerY + 3 \* tweenButtons, "", onPlay, { width = 100, height = 100, unselImg = "images/gel/buttonB.png", selImg = "images/gel/buttonBOver.png" } ) local buttonC = ImagePushButton( group, centerX + 125, centerY + 3 \* tweenButtons, "", onPlay, { width = 100, height = 100, unselImg = "images/gel/buttonC.png", selImg = "images/gel/buttonCOver.png" } )

Thank you all …

Thanks roaminggamer, this is exactly what I was needing

First, welcome to the forums. We are glad you’re here.  Please keep in mind that for the best help, make your posts in English please unless you’re asking in a language specific forum. Now to your question!

You would simply replace display.newRect() with display.newImageRect() which takes a path to the image, width, and height as parameters.  You already have width and height with the display.newRect() call.

The one addition is you would need to position the image. display.newRect()'s first two parameters are the X and Y to draw the rectangle. You can use those values to move the image to where you want it by setting the .x and .y values after you create the image.  Assuming you have this as your display.newRect() call:

local myButton = display.newRect( display.contentCenterX, 100, 80, 50 )

You would use an image by doing:

local myButton = display.newImageRect( "button.png", 80, 50 ) -- note I'm making up values myButton.x = display.contentCenterX myButton.y = 100

or something like that.

Rob

Na classe pushButtonClass.lua usada para criar botões de mudança de cena, eu gostaria de saber como fazer na localização do botão display.newRect insira qualquer imagem para executar a mesma função de mudança de cena usando no caso o código display.newImage.
 
Portuguese Direct Translation:

In the pushButtonClass.lua class used to create scene change buttons, I would like to know how to do at the location of the display.newRect button to insert any image to perform the same scene change function using in the display.newImage code case.

 
Question:

Are you are asking, “How do I use any images I wish for the buttons” in that example?

Você está perguntando: “Como eu uso as imagens que desejo dos botões” nesse exemplo?

Original code: https://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/composer_scene_manager.zip

For now, I will assume you want to use arbitrary images for the buttons.  Let me look and answer back soon.

Por enquanto, assumirei que você deseja usar imagens arbitrárias para os botões. Deixe-me olhar e responder em breve.

@leonam

Let me direct you to a more up-to-date version of those button classes:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2016/03/oop_img_button.zip

This version of the buttons classes allows you to specify the images when you make the buttons:

require "scripts.pushButtonClass" require "scripts.toggleButtonClass" require "scripts.imgPushButtonClass" local group = display.newGroup() -- Image Push Button Samples local buttonA = ImagePushButton( group, centerX - 125, centerY + 3 \* tweenButtons, "", onPlay, { width = 100, height = 100, unselImg = "images/gel/buttonA.png", selImg = "images/gel/buttonAOver.png" } ) local buttonB = ImagePushButton( group, centerX, centerY + 3 \* tweenButtons, "", onPlay, { width = 100, height = 100, unselImg = "images/gel/buttonB.png", selImg = "images/gel/buttonBOver.png" } ) local buttonC = ImagePushButton( group, centerX + 125, centerY + 3 \* tweenButtons, "", onPlay, { width = 100, height = 100, unselImg = "images/gel/buttonC.png", selImg = "images/gel/buttonCOver.png" } )

Thank you all …

Thanks roaminggamer, this is exactly what I was needing