Author Topic: Making a sprite 'jump'  (Read 2238 times)

Micboy

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-2
    • View Profile
Making a sprite 'jump'
« on: August 02, 2012, 08:37:55 am »
Hi everyone, I'm new to dfsdk so i need some help.
As i am not too familiar with box2d, I will therefore make a sprite jump by changing the Y coordinates in OnTimer().
However, moving the sprite is easy, but how do I move it when the screen is touched?
Any help would be appreciated!

Micboy

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-2
    • View Profile
Re: Making a sprite 'jump'
« Reply #1 on: August 02, 2012, 08:40:04 am »
Should I set the Touchadd function, then have the callback as jump(), with jump() having a calc that changes the Y coordinates into the jump height?

tim

  • Administrator
  • Hero Member
  • *****
  • Posts: 1595
  • Karma: +11/-1
    • View Profile
    • DragonFireSDK
Re: Making a sprite 'jump'
« Reply #2 on: August 02, 2012, 11:19:57 am »
If you need to have the device respond to a touch event, then yes, you'll need to set up a touch area using TouchAdd() with the appropriate settings.

Have you read the Box2D tutorial about jumping?

http://www.dragonfiresdk.net/wiki/index.php?title=Tutorial%3AJumping_in_Box2d
Tim Sommers
DragonFireSDK Team

Micboy

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-2
    • View Profile
Re: Making a sprite 'jump'
« Reply #3 on: August 03, 2012, 03:30:52 am »
If you need to have the device respond to a touch event, then yes, you'll need to set up a touch area using TouchAdd() with the appropriate settings.

Have you read the Box2D tutorial about jumping?

http://www.dragonfiresdk.net/wiki/index.php?title=Tutorial%3AJumping_in_Box2d

Of course, that was the reason why I wanted to steer away from Box 2d. I am wondering if it is possible to make a sprite move up a few pixels then back down, within the OnTimer(), when the screen is touched.

Micboy

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-2
    • View Profile
Re: Making a sprite 'jump'
« Reply #4 on: August 03, 2012, 10:16:52 am »
Any help would be grateful

tim

  • Administrator
  • Hero Member
  • *****
  • Posts: 1595
  • Karma: +11/-1
    • View Profile
    • DragonFireSDK
Re: Making a sprite 'jump'
« Reply #5 on: August 03, 2012, 01:01:10 pm »
Of course, you can do something like this in OnTimer() without using Box2D, but you'll have to code everything yourself. This is what makes Box2D so attractive.  It handles all of the collision detection and physics for you.

If you only need something simple, you could do something like this (pseudocode example):

Code: [Select]
void OnTimer()
{
    ....
if (NeedToMoveUp==true)
{
PlayerY--;
ViewSetxy(PlayerView,0,PlayerY);
}
else
if (NeedToMoveDown==true)
{
PlayerY++;
ViewSetxy(PlayerView,0,PlayerY);
}
}
Tim Sommers
DragonFireSDK Team