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
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:
“ 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
Comments
< pre lang="lua">
--your codes
< /pre>
remove first whitespaces from the tags
Please keep us informed if you find a new formula!
@unlying, why do you need to move image without wave, if you can move it with waves?!? :-?
if you want to move it straight, it would be
y=1
x=x+1
is that what you are wondering?
But blimp file was missing, though
So.. you want square waves?
or you just want a flat sine wave?
perhaps the next wave i do will be a square one...
edit:
@ar2sawseen image added!
https://deluxepixel.com
@Harrison, flate wave would be very useful in my project. Please start with it!
Square waves are hard to do, but you can compromise and make almost square waves:
square, but a just a little wobbly at the top and bottom:
y=a*math.sin(2*math.sin(2*math.sin(2*math.sin(x))))
where a makes it taller.
i have not tested it but adding in (l*x) would probably allow you to adjust length.