Why this doesn’t exist?
[lua]myImg= display.newImageRect(“pippo.png”,20,20)
myImg.image = “pluto.png”[/lua]
[import]uid: 70929 topic_id: 27403 reply_id: 327403[/import]
Why this doesn’t exist?
[lua]myImg= display.newImageRect(“pippo.png”,20,20)
myImg.image = “pluto.png”[/lua]
[import]uid: 70929 topic_id: 27403 reply_id: 327403[/import]
You cannot change an image that way - you’d need to use a sprite sheet or recreate the image - sprites would be easiest in the long run most likely [import]uid: 52491 topic_id: 27403 reply_id: 111324[/import]
To elaborate on peach’s post your looking to do something like this:
[code]
local myImg = display.newImageRect(“pippo.png”,20,20)
–When you want to change it
display.remove(myImg)
myImg = display.newImageRect(“pluto.png”,20,20)
[/code] [import]uid: 84637 topic_id: 27403 reply_id: 111349[/import]
Thanks Peach!
Hi Danny, if i do that, the body stay as it was? and the position will be reset?
I think that if you have a lot of on\off led in a table with many attributes, it would be great to change image on the fly…
Sorry for my english [import]uid: 70929 topic_id: 27403 reply_id: 111352[/import]
If you also have a physics body attached to the image you would also need to recreate that.
So for instance:
[code]
local myImg = display.newImageRect(“pippo.png”,20,20)
–When you want to change it
display.remove(myImg)
myImg = display.newImageRect(“pluto.png”,20,20)
physics.addBody(myImg, “dynamic”, {isSensor = false})
[code]
For instance [import]uid: 84637 topic_id: 27403 reply_id: 111355[/import]
yes, this is a solution, i only would suggest something useful… i have a little project of a drum machine with 16 img x 8 instruments so 128 images.
local kick={0,0,0,0,0,etc..}
.
.
.
.
local snare={0,0,0,0,0,etc..}
local function turnOn(objectSelected)
objectSelected.image="on.png"
objectSelected.satus=1
objectSelected.volume=getVolume(objectSelected)
.
.
.
.
end
local kick={0,0,0,0,0,etc..}
.
.
.
.
local snare={0,0,0,0,0,etc..}
local function turnOn(objectSelected)
newX=objectSelected.x
newY=objectSelected.y
display.remove(objectSelected)
objectSelected=display.newImageRect("on.png"...)
objectSelected.x=newX
objectSelected.x=newY
objectSelected.satus=1
objectSelected.volume=getVolume(objectSelected)
.
.
.
.
end
I know that’s the only way, so i just suggested you this feature [import]uid: 70929 topic_id: 27403 reply_id: 111358[/import]
If you have that many images I would strongly recommend using spritesheets [import]uid: 84637 topic_id: 27403 reply_id: 111360[/import]