Hi everyone. I need help with : "i have a shaped object on the scene, what i need is , when i touch or press object it gets bigger. "
Please help i have spend all day and cant figure it out. Thanks
[import]uid: 11559 topic_id: 19982 reply_id: 319982[/import]
Do something like this:
[lua]image = display.newImage(“image.png”, display.contentWidth/2, display.contentHeight/2)
local function whatever()
transition.to(image, {time=2000, xScale = 1.9, yScale = 1.9})
end
image:addEventListener(“touch”, whatever)[/lua]
Hope this helps.
Regards,
Jordan Schuetz
Ninja Pig Studios [import]uid: 29181 topic_id: 19982 reply_id: 77818[/import]
If you want to do it instantly you can use
myImage:scale(2.0, 2.0) [import]uid: 84637 topic_id: 19982 reply_id: 77828[/import]
Thanks to everyone.
According to example above it gives me a lot of errors.
@Danny would you please give me an example of code how would you do it.
I need when i press object it gets bigger, and so far up to 5-7 time.
Thanks [import]uid: 11559 topic_id: 19982 reply_id: 77829[/import]
Sure :
local function scaleUp(object, scale)
object:scale(object.xScale + scale, object.yScale + scale)
return object
end
--Usage (on a button press or similar)
scaleUp(myImg, 0.2)
That would for instance scale up your image by its current scale value plus the amount to scale by [import]uid: 84637 topic_id: 19982 reply_id: 77832[/import]
Thanks a lot. [import]uid: 11559 topic_id: 19982 reply_id: 77834[/import]
Here is how i did it and its just black screen. No idea why.
[code]
– Play scene
module(…,package.seeall)
local group
–Button press handlerr
local function menuPressed(b)
game.playEventSound(game.soundPressed)
game.changeScene(“mainscene”,“overFromTop”)
end
– add shape press handlers
local function scaleUp,(shape, scale)
shape:scale(shape.xScale + scale, shape.yScale + scale)
return shape
end
— Example
scaleUp(myImg, 0.2)
function new()
physics.start()
group = display.newGroup()
– Add Background
local background = display.newImageRect( “backgrounds/bkg.png”, 480, 320 )
background.x = 240
background.y = 160
group:insert(background)
– Add rope
local rope =display.newImageRect ( “levels/rope.png”, 480, 9)
rope.x = 240
rope.y = 110
group:insert(rope)
– add ground
local ground = display.newImageRect (“levels/ground.png”, 200, 64)
ground.x = 240
ground.y = 210
group:insert (ground)
– add shape
local shape = display.newImage(“levels/shape.png”, 35,35)
shape.x = 240
shape.y = 210
group:insert (shape)
– Add menu button
button:create(group,1,{x=45,y=300,w=71,h=21,handler=menuPressed},“buttons/menuicon.png”)
button:create(group,1,{x=130,y=300,w=71,h=21,handler=restartPressed}, “buttons/restarticon.png”)
button:create(group,1,{x=450,y=300,w=40,h=39,handler=SoundPressed}, “buttons/soundicon.png”)
button:create(group,1,{x=390,y=300,w=40,h=39,handler=MusikPressed}, “buttons/musikicon.png”)
return group
end
`` [import]uid: 11559 topic_id: 19982 reply_id: 77836[/import]
check the simulator output for errors. [import]uid: 71210 topic_id: 19982 reply_id: 77864[/import]
This is the output from debugger
Runtime error
error loading module ‘level1’ from file ‘/Users/shakirovruslan2008/Documents/Ayena LLC/Corona/Impossible Test Game/level1.lua’:
…rovruslan2008/Documents/Ayena LLC/Corona/Impossible Test Game/level1.lua:33: ‘(’ expected near ‘,’
stack traceback:
[C]: ?
[C]: ?
[C]: in function ‘require’
…s/Ayena LLC/Corona/Impossible Test Game/director.lua:116: in function ‘loadScene’
…s/Ayena LLC/Corona/Impossible Test Game/director.lua:394: in function ‘changeScene’
…ments/Ayena LLC/Corona/Impossible Test Game/main.lua:40: in function ‘_listener’
?: in function <?:514>
?: in function <?:215>
Runtime error
…s/Ayena LLC/Corona/Impossible Test Game/director.lua:135: ERROR: table expected. If this is a function call, you might have used ‘.’ instead of ‘:’
stack traceback:
[C]: ?
[C]: in function ‘insert’
…s/Ayena LLC/Corona/Impossible Test Game/director.lua:135: in function ‘_listener’
?: in function <?:514>
?: in function <?:215> [import]uid: 11559 topic_id: 19982 reply_id: 77871[/import]
I can see an extra comma here
[lua]local function scaleUp,(shape, scale)
shape:scale(shape.xScale + scale, shape.yScale + scale)
return shape
end[/lua] [import]uid: 71210 topic_id: 19982 reply_id: 77876[/import]
Thanks. I have removed the comma , but the error is still there.
Runtime error
…nts/Ayena LLC/Corona/Impossible Test Game/level1.lua:20: attempt to index local ‘shape’ (a nil value) [import]uid: 11559 topic_id: 19982 reply_id: 77878[/import]
you are calling the function
scaleUp(myImg, 0.2)
but i cannot see myImg declared anywhere. So the variable shape get a nil value and that causes the error.

[import]uid: 71210 topic_id: 19982 reply_id: 77881[/import]
i got it to work. Thank you everyone.
I have another question. How do i make it clickble 5 times and every time i click/touch objects gets bigger [import]uid: 11559 topic_id: 19982 reply_id: 77882[/import]
how is it working now ? the code looks like it works the way you want. [import]uid: 71210 topic_id: 19982 reply_id: 77884[/import]
I coded this way
[code]
local function shapePressed()
transition.to(shape, {time=10, xScale = 2, yScale = 2})
end
local shape = display.newImage(“levels/shape.png”, display.contentWidth/2, display.contentHeight/2)
– event listeners
shape:addEventListener(“touch”, shapePressed)
``
But it does only once and stops without any error in output.
Any ideas ? [import]uid: 11559 topic_id: 19982 reply_id: 77885[/import]
oh… you have to call the scaling function inside a touch or tap event…
it goes something like this
[lua]myImg:addEventListener(“tap”,function() scaleUp(myImg, 0.2) end)[/lua] [import]uid: 71210 topic_id: 19982 reply_id: 77887[/import]
Thank you trying to help a lot. But according to my code. Can you give me example using my code above. Im new to this. Thanks a lot [import]uid: 11559 topic_id: 19982 reply_id: 77889[/import]
in your code you are settign the xscale and yscale to 2 every time u press the button…
u should increment the current value instead.
[lua]local shape = display.newImage(“levels/shape.png”, display.contentWidth/2, display.contentHeight/2)
local function shapePressed()
transition.to(shape, {time=10, xScale = shape.xScale + 2, yScale = shape.yScale + 2})
end
– event listeners
shape:addEventListener(“tap”, shapePressed)[/lua]
[import]uid: 71210 topic_id: 19982 reply_id: 77891[/import]
Thanks. but not working.
Lets put it this way.
I have a shape, when i touch it 1 time it gets x pixels bigger, when i touch again it gets bigger even more and so on.
Hope this is clear explanation. And thanks a lot for your help [import]uid: 11559 topic_id: 19982 reply_id: 77915[/import]
the above code I posted should work the way you want.
make sure that you declare “shape” before the function shapePressed. [import]uid: 71210 topic_id: 19982 reply_id: 77932[/import]