How do I calculate LinearVelocity or LinearImpulse to throw a pumpkin.
In my game I've set the stick to 25 degrees inclined... The pumpkin is placed on the top of the stick. I can drag the stick from top to down to between 25 to -25 degrees.
So when the mouse is up then I want to throw pumpkin based on the angle dragged. What should I apply?
Either
applyLinearImpulse()
or
applyForce()
or
setLinearVelocity()
How do I calculate the parameters for the above functions... The stick is not a Bitmap image, Its not a dynamic body...
Currently I've written code on onMouseMove event as follow:
local a =math.atan((event.y - self.pumpkinStick:getY())/(event.x - self.pumpkinStick:getX()))*180/math.piifmath.ceil(a)<= -25then
self.pumpkinStick:setRotation(-25)
self.pumpkinStick:setVisible(true)
self.stick:setVisible(false)elseifmath.ceil(a)>=25then
self.pumpkinStick:setRotation(25)
self.pumpkinStick:setVisible(true)
self.stick:setVisible(false)else
self.pumpkinStick:setRotation(a)end
The movement of the pumpkin is fine... Its forms correct arc, but only problem is the speed.... There is no speed in the movement....
Hence when it hits the spring anywhere the reaction of the spring will be same all the time... The working of the spring doesn't look like real world..
And there no bounce effect for pumpkin, restitution is set to 0.8 but still the pumpkin does not bounces when it hits any wall or spring...
when I comment the onBeginContact event, then there will be bouncing in pumpkin..
@Sush19 if you are using the example I provide, then it resets all velocities on collision, so it won't move further. As you had the same effect in your project only by using negative density, I've implemented it in my example by reseting the velocity on collision.
So 1) check if density is not equals or lower than 0 2) check if no velocities are changed on collision
The density of the pumpkin is 100 and the density of rest of the bodies is set to 1... None of the density is less than or equal to 0.
There is no change in velocities on collision... I just wanted to apply little bouncing for pumpkin. i.e when it touches other bodies such as the boundary walls or spring then the pumpkin should bounce...
local screenW = application:getContentWidth()local screenH = application:getContentHeight()local offsetX =0local offsetY =0if((self.worldW - self.pumpkin:getX())< screenW/2)then--self.worldW = screenW*10
offsetX =(-self.worldW + screenW)elseif(self.pumpkin:getX()>= screenW/2)then
offsetX = -(self.pumpkin:getX() - screenW/2)end
self:setX(offsetX)if((self.worldH - self.pumpkin:getY())< screenH/2)then--self.worldH = screenH*1.37
offsetY = -self.worldH + screenH
elseif(self.pumpkin:getY()>= screenH/2)then
offsetY = -(self.pumpkin:getY() - screenH/2)end
self:setY(offsetY)--and other backgrounds are based on below code, as you told me....--moving parallax backgrounds
self.bg1:setX(-offsetX)--will move with the screen
self.bg2:setX(-offsetX*0.8)--will move slower
self.bg3:setX(-offsetX*0.4)--will move faster--and not moving self.bg4 as it will move with the scene
This time I'm moving on Y-axis as well... I want to move the scene and backgrounds based on the speed of the pumpkin, Based on the velocity of the pumpkin I need to move the backgrounds.. How do I implement it...
Yes the x-axis and the y-axis moves as expected.... But when the pumpkin reaches the half of the screen then its speed gets slow down, I don't know exactly what is happening there,,, but I felt that the speed of the pumpkin before half of the screen is little more than when it reaches the half of the screen..
For your reference I've Included my project here... In my project base wall is the fastest moving background and the background on the top moves along with the screen and the grass is the slowest background..
Even the spring should move based on the base wall speed...
But when the pumpkin reaches half of the screen, then it seems to be like pumpkin changes its y-axis direction, It seems to be like pumpkin goes little upwards in y-axis.., This we can make out when we fully drag down the stick.. Which doesn't looks good and doesn't form a proper arc...
How do I add and manage more that one spring in my above project?
I tried adding more than one spring, but all the springs are not working fine... Only the last added spring works fine and all other springs doesn't work...
How do I do this? I wanted to add some 3 to 4 spring on random x position....
Hi... I need another help.. There is no bounce effect on pumpkin, I want pumpkin to bounce when it hits the walls, but because of the following event There is no bounce effect
if I comment this statement then there is bounce effect...
Right now the pumpkin stops wherever it falls on the bottom wall, I want the pumpkin to show little bounce and roll some distance based on its speed...
What I should do to get the bounce effect... I've set:
-- For pumpkin
local fixture = body:createFixture{shape = circle, density = 10, friction = 10, restitution = 0.1}
fixture:setFilterData({categoryBits = 2, maskBits = 9})
-- For walls
local fixture = body:createFixture{shape = poly, density = 1.0, friction = 0.1, restitution = 0.8}
fixture:setFilterData({categoryBits = 1, maskBits = 14})
Hi, In my game when the pumpkin hits the edge of the springTop, then the springTop starts shaking to and fro, and it continues until reload the game... How do I avoid shaking of the springTop when a body hits at the edge of it..
I want to add some points, say: coins or stars. I want to add N number of points in different positions When the pumpkin touches these stars then it should disappear from the stage without affecting the pumpkin movement and at the same time I want to play some sound and reward some extra points to the player.
I've set pumpkin: categoryBit = 1 and maskBits = 26 springTop: categoryBit = 2 and maskBits = 21 springBound: categoryBit = 4 and maskBits = 18 stars: categoryBit = 8 and maskBits = 17 walls: categoryBit = 16 and maskBits = 15
As I told you regarding my game, that each time I replay without exiting the game, the game gets slower and slower...
Now I'm using SceneManager as you suggested me.... But still there is the same problem..
It works fine and it doesn't get slower when I replay the game on my PC...
I created .apk and was trying on Android devices, on Android devices for the first time I play the game, that time it works fine, but when I replay without exiting the game, then each time I replay the game, the game gets slower and slower...
Comments
Thank you..
How do I calculate LinearVelocity or LinearImpulse to throw a pumpkin.
In my game I've set the stick to 25 degrees inclined... The pumpkin is placed on the top of the stick. I can drag the stick from top to down to between 25 to -25 degrees.
So when the mouse is up then I want to throw pumpkin based on the angle dragged.
What should I apply?
Either
The stick is not a Bitmap image, Its not a dynamic body...
Currently I've written code on onMouseMove event as follow:
Please help me...
Hence when it hits the spring anywhere the reaction of the spring will be same all the time... The working of the spring doesn't look like real world..
And there no bounce effect for pumpkin, restitution is set to 0.8 but still the pumpkin does not bounces when it hits any wall or spring...
when I comment the onBeginContact event, then there will be bouncing in pumpkin..
How do I fix it..?
As you had the same effect in your project only by using negative density, I've implemented it in my example by reseting the velocity on collision.
So
1) check if density is not equals or lower than 0
2) check if no velocities are changed on collision
None of the density is less than or equal to 0.
There is no change in velocities on collision...
I just wanted to apply little bouncing for pumpkin. i.e when it touches other bodies such as the boundary walls or spring then the pumpkin should bounce...
Thank you for your guide through..
Will be back with if problem arises...
I'm moving the scene as you told me
I want to move the scene and backgrounds based on the speed of the pumpkin,
Based on the velocity of the pumpkin I need to move the backgrounds..
How do I implement it...
And does x axis moving work as expected?
For your reference I've Included my project here...
In my project base wall is the fastest moving background and the background on the top moves along with the screen and the grass is the slowest background..
Even the spring should move based on the base wall speed...
Thank you...
http://www.screenr.com/XPGH
Which doesn't looks good and doesn't form a proper arc...
Hope you understood what I mean to say...
I tried adding more than one spring, but all the springs are not working fine...
Only the last added spring works fine and all other springs doesn't work...
How do I do this?
I wanted to add some 3 to 4 spring on random x position....
I've already added but doesn't work for me...
Please help me..
Please help me and reply me
Thank you
It
It works great...
thanks a lot
I need another help..
There is no bounce effect on pumpkin, I want pumpkin to bounce when it hits the walls, but because of the following event There is no bounce effect
Right now the pumpkin stops wherever it falls on the bottom wall, I want the pumpkin to show little bounce and roll some distance based on its speed...
What I should do to get the bounce effect...
I've set:
what you need to do is to check, if pumpkin collides with spring only then reset, other wise do not reset and let it bounce
I tried the same and it works...
In my game when the pumpkin hits the edge of the springTop, then the springTop starts shaking to and fro, and it continues until reload the game...
How do I avoid shaking of the springTop when a body hits at the edge of it..
Or experiment with restitution and friction of srpingTop
I'll try with restitution and friction now..
Thank you..
I tried with
How can I set it to display it in Landscape Mode..
If it is with exported project, then for Android you need to replace portrait with landscape in your AndroidManifest activity tag
If IOS then you can set allowed orientation in General settings tab by checking/unchecking device icons in different orientations
In my project there are 3 files
main.lua
game.lua
gameEnd.lua
I'm loading the initial sound, background Image and playButton image in main.lua
When playButton is clicked I'm calling game.lua as
Whether this lines frees the memory as well?
https://github.com/gideros/Scene-Manager
And here is more info on it:
http://appcodingeasy.com/Gideros-Mobile/Manage-Scenes-in-Gideros-Mobile
You can also check the usage example here:
https://github.com/ar2rsawseen/GameTemplate
I want to add some points, say: coins or stars.
I want to add N number of points in different positions
When the pumpkin touches these stars then it should disappear from the stage without affecting the pumpkin movement and at the same time I want to play some sound and reward some extra points to the player.
I've set
pumpkin: categoryBit = 1 and maskBits = 26
springTop: categoryBit = 2 and maskBits = 21
springBound: categoryBit = 4 and maskBits = 18
stars: categoryBit = 8 and maskBits = 17
walls: categoryBit = 16 and maskBits = 15
How do I achieve this?
About colliding with stars, you also need to make star a sensor, by setting isSensor to true when creating fixture
As I told you regarding my game, that each time I replay without exiting the game, the game gets slower and slower...
Now I'm using SceneManager as you suggested me.... But still there is the same problem..
It works fine and it doesn't get slower when I replay the game on my PC...
I created .apk and was trying on Android devices, on Android devices for the first time I play the game, that time it works fine, but when I replay without exiting the game, then each time I replay the game, the game gets slower and slower...
I'm using 3 Scenes
How do I improve it?
http://www.giderosmobile.com/forum/discussion/799/addingremoving-children-and-memory-usage/p1
http://giderosmobile.com/forum/discussion/2645/help-with-memory-leak