Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Sine Waves - Gideros Forum

Sine Waves

HarrisonHarrison Member
edited June 2014 in Step by step tutorials
Just a bit ago i learned about how cool waves are and i figured that i should share it with you guys! So here it is:
y=h*math.sin(u*x)
where h is height and u is oscillation speed (up and down)
x is the x and y is the y :D
oh! and dont forget to update the x or it wont move!
x=x+1
the sample code:
-- load 
blimpx=10
blimpy=blimpx
local blimp = Bitmap.new(Texture.new("images/blimp.png"))
blimp:setPosition(20, 20)
blimp:setScale(0.5,0.5)
stage:addChild(blimp)
function onEnterFrame(event)
blimpx=blimpx+1
blimpy=10*math.sin(0.1*blimpx)
blimp:setPosition(blimpx, blimpy)
end
 
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
There you go, when you put it all together you get a cool sine wave effect that is fun to mess around with.
cosine is almost the same, but the wobbles are in a different spot- try it out.
Now, you may ask, what does this have to do with app dev?
Sine waves are (or can be) used in many games, whenever you see something wobble while moving forward!
I will post here when i find out more useful line formulas!
Feel free to post what you did with sine waves.
Note:you will have to add the image manually in gideros. make a folder called images (in gideros) and put blimp.png (findable in the .zip) in it.
The sample game:

Likes: SinisterSoft

“ The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. ” - Tom Cargill
zip
zip
blimpwimage(2).zip
21K
+1 -1 (+1 / -0 ) Share on Facebook

Comments

Sign In or Register to comment.