Hello,
I want to scale an image and then replace it with another in the same place, but when I try it the image moves several pixels from the origin.
This is the code:
local ui = require("ui")
local widthS,heightS=display.contentWidth,display.contentHeight
local background=display.newRect(0,0,widthS,heightS)
background:setFillColor(255,255,255)
local my\_group=display.newGroup()
local img
local function increase(event)
if event.phase == "release" then
img:scale(1.5,1.5)
end
end
local function setImage(num) --Here is where all happens
local lW=img.parent.width
local lH=img.parent.height
my\_group:remove(img)
img=display.newImage("foo\_"..num..".png")
my\_group:insert(img)
img.x=widthS/2
img.y=heightS/2-20
img.parent.width=lW
img.parent.height=lH
end
local function pressed1(event)
if event.phase=="ended" then
setImage(1)
end
end
local function pressed2(event)
if event.phase=="ended" then
setImage(2)
end
end
--
--BUTTONS
--
local item1\_button = ui.newButton{
default = "item1.png",
over = "item1.png",
onRelease = pressed1
}
local item2\_button = ui.newButton{
default = "item2.png",
over = "item2.png",
onRelease = pressed2
}
local increase\_button = ui.newButton{
default = "buttonGray.png",
over = "buttonGray.png",
onEvent = increase,
text="Increase!",
font=native.systemFont,
size=18,
emboss = true
}
item1\_button.x=widthS/2-50
item1\_button.y=heightS-90
item2\_button.x=widthS/2+50
item2\_button.y=heightS-90
increase\_button.x=widthS/2
increase\_button.y=heightS-30
img=display.newImage("foo\_1.png")
my\_group:insert(img)
img.x=widthS/2
img.y=heightS/2-20
What am I doing wrong?
I try several options but i am stuck.
I appreciate any help. [import]uid: 44013 topic_id: 13558 reply_id: 313558[/import]