Thanks @talis and @ glennbjr - that will be useful.
In case it's any use to anyone else, I've also made a function based on that to pulse the size of a button as that's what I needed for something I'm working on:
function pulse(object,scl) if scl ~= nil then object:setScale(scl) else object:setScale(1.2) end GTween.new(object, 0.2, {scaleX=1,scaleY=1}, {}) end
Has optional scl parameter to set the scale to pulse to (can be less than 1 to make the object smaller). If no scl set, then it defaults to making it 1.2x original size.
@Gracille Addition to @ar2rsawseen post working functions are below. Also iparameter of the function and gtween obje is not same. So here is the working and correct one for sure:) P.S : Tested:)
--change the value 5 to change the shake distancefunction shake(obje)
obje:setPosition(obje:getX()-5, obje:getY()-5)
GTween.new(obje, 0.25, {x = obje:getX()+5,y = obje:getY()+5}, {delay =0, ease = easing.outBounce })end
@Gracille as i said before this is the code i am using in my own applications and it is %100 working. In your implementation ther must be something wrong. So please post your whole code here and we can correct.
--change the value 5 to change the shake distance function shake(object) object:setPosition(object:getX()-5, object:getY()-5) GTween.new(object, 0.25, {x = object:getX()+5,y = object:getY()+5}, {delay = 0, ease = easing.outBounce }) end ------- local bup = Bitmap.new(Texture.new("images/Backbtn.png")) local bdown = Bitmap.new(Texture.new("images/Backbtn1.png")) local backbtn = Button.new(bup, bdown) backbtn:setPosition(3, 170) self:addChild(backbtn)
@Gracille you only define the shake function but you didn't call it anywhere. You should call the function somewhere like: shake(bup) shake(backbtn) etc....
@Gracille no problem there is nothing wrong with asking and learning. Please feel free to ask anything. If i know i will help, if not someone else will:D Time will come and you will answer my questions too. This is what this forum is for \m/
Comments
Likes: phongtt, talis, chipster123, atilim, thanhquan1512
iTunes: http://itunes.com/apps/glennbacon
Amazon: http://www.amazon.com/s/ref=bl_sr_mobile-apps?_encoding=UTF8&node=2350149011&field-brandtextbin=Glenn Bacon
Should look cool together with vibrations
Thanks
Thanks for the idea @glennbjr.
Likes: Teranth, chipster123
Likes: chipster123
iTunes: http://itunes.com/apps/glennbacon
Amazon: http://www.amazon.com/s/ref=bl_sr_mobile-apps?_encoding=UTF8&node=2350149011&field-brandtextbin=Glenn Bacon
In case it's any use to anyone else, I've also made a function based on that to pulse the size of a button as that's what I needed for something I'm working on: Has optional scl parameter to set the scale to pulse to (can be less than 1 to make the object smaller). If no scl set, then it defaults to making it 1.2x original size.
I tried using your code but i cant shake the Flask image,
can anyone tell whats wrong with my code? thanks...
heres my code
shakey = gideros.class(Sprite)
function shakey:init()
local bg = Bitmap.new(Texture.new("images/Main Menu/BG2.png"))
self:addChild(bg)
local object = Bitmap.new(Texture.new("images/Main Menu/Flask.png"))
self:addChild(object)
object:setPosition(150, 40)
object:addEventListener ("click",
function shake(object)
object:setPosition(object:getX()-3, object:getY()-3)
GTween.new(obje, 0.25, {x = object:getX()+3,y = object:getY()+3}, {delay = 0, ease=easing.outBounce })
end)
local bup = Bitmap.new(Texture.new("images/Backbtn.png"))
local bdown = Bitmap.new(Texture.new("images/Backbtn1.png"))
local backbtn = Button.new(bup, bdown)
backbtn:setPosition(3, 170)
self:addChild(backbtn)
backbtn:addEventListener ("click",
function()
sceneManager:changeScene("mmenu", 0.3, SceneManager.crossfade)
end)
shakey.lua:13: '(' expected near 'shake'
P.S : Tested:)
@talis I tried your code but the error is still the same.
In your implementation ther must be something wrong. So please post your whole code here and we can correct.
shakey = gideros.class(Sprite)
function shakey:init()
local bg = Bitmap.new(Texture.new("images/Main Menu/BG2.png"))
self:addChild(bg)
local object = Bitmap.new(Texture.new("images/Main Menu/Flask.png"))
self:addChild(object)
object:addEventListener ("click",
--change the value 5 to change the shake distance
function shake(object)
object:setPosition(object:getX()-5, object:getY()-5)
GTween.new(object, 0.25, {x = object:getX()+5,y = object:getY()+5}, {delay = 0, ease = easing.outBounce })
end
-------
local bup = Bitmap.new(Texture.new("images/Backbtn.png"))
local bdown = Bitmap.new(Texture.new("images/Backbtn1.png"))
local backbtn = Button.new(bup, bdown)
backbtn:setPosition(3, 170)
self:addChild(backbtn)
backbtn:addEventListener ("click",
function()
sceneManager:changeScene("mmenu", 0.3, SceneManager.crossfade)
end)
end
You should call the function somewhere like:
shake(bup)
shake(backbtn)
etc....
Time will come and you will answer my questions too. This is what this forum is for \m/
like so
it is just calling and setting a new position for the object periodically randomly.
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps