Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Micboy

Pages: 1 ... 3 4 [5] 6
61
Hi,

I have read: http://dragonfiresdk.net/forum/index.php?topic=360.0
but it seems rather complicated! Is there an easier method? Without elasticity and friction?

For example, could I do something like:
Code: [Select]
int OnDrag(int id,int event,int x,int y)
{
// Record initial coordinates when pressed down
if (event == 1)
{
nOldX = x;

}

// Record new coordinates when moving
if (event == 2)
{
               nNewX = x;
}
}

return id;
}

then set new position of container?
Thank you in advance,

Micboy

62
Thanks for your help guys. Realised that Im not allowed OnButton(int id, int event), only id.

Case closed!!!

63
I seem to be unable to resolve this! Could someone help me please!
The error is:
error C2665: 'ButtonAdd' : none of the 2 overloads could convert all the argument types

The code is:
Code: [Select]
        //Already initialised cn1, SP_Button, and OnMenu(int id, int evt)
cn1 = ContainerAdd(0, 0, 0); //ContainerAdd(cn, x ,y)
MenuView[0] = ViewAdd(cn1,"Images/Menu1.png", 0,0);
SP_Button = ButtonAdd(cn1, "Images/Single_Player.png" ,60 ,260, OnMenu1, 1);

int ButtonAdd(int cn,char *filename, int x, int y, int (*callback)(int id), int id);

I'm trying to figure out whats wrong, but cant seem to identify the problem!
Thank you in advance,

Micboy


PS, the full error is:
error C2665: 'ButtonAdd' : none of the 2 overloads could convert all the argument types
1>          dfsdk\dragonfiresdk\lights\dragonfiresdk.h(244): could be 'int ButtonAdd(int,char *,int,int,int (__cdecl *)(int),int)'
1>          while trying to match the argument list '(int, const char [20], int, int, overloaded-function, int)'

64
Thanks! I will let you know if it works!

65
Hi guys,

For my game, I need to print the score, which is constantly updated.

I have a function called PrintSteps:

Code: [Select]
string Steps;
int Step = 0;
bool StepsInit = false;
int MyFont = FontAdd("Helvetica", "Regular", 12, 0xFFFFFF);

void PrintSteps(int n)//n=number of steps
{
//add text to screen to show how many buttons have been pressed
Steps=n+1;
Steps="new!";
int MyText2;
if(StepsInit==false){
//int MyText1//(char *)Steps.c_str()
MyText2 = TextAdd(100, 50, (char *)Steps.c_str(), MyFont);
}
else TextSetText(MyText2,(char *)Steps.c_str());
StepsInit = true;
}

(in a dif function):
PrintSteps(Step)
   

Basically, how do I output a number onto the screen?

I tried:
Code: [Select]
int Steps;
MyText2 = TextAdd(100, 50, Steps, MyFont);

But that dosent seem to work?

Thank you in advance,

Micboy

66
Game Programming / Access violation in the code below?
« on: December 19, 2012, 01:28:09 pm »
Could someone please have a look at this code:

error returned is:
Unhandled exception at 0x00a1ac42 in MyFirstApp.exe: 0xC0000005: Access violation reading location 0x00000010.


Code: [Select]
#include "DragonFireSDK.h"
#include <time.h>
#include <Box2D/Box2D.h>

// For iPhone:
const int SCREEN_W = 480;
const int SCREEN_H = 320;

// Scale is 32 pixels = 1 meter:
const float SCALE = 1.0f / 32.0f;

const float SCALED_SCREEN_W = 480*SCALE;
const float SCALED_SCREEN_H = 320*SCALE;
const float SCALED_HALF_SCREEN_W = 240*SCALE;
const float SCALED_HALF_SCREEN_H = 160*SCALE;

// Animation frequency is 30 times / second:
const float DELTA = 1.0f / 30.0f;

// Bodies are 50 pixels per side.
// Body size is halved, since body vertices are relative to the center of the shape:
const float BODY_SIZE_WIDTH = (40.f * SCALE) / 2.0f;
const float BODY_SIZE_HEIGHT = (60.f * SCALE) / 2.0f;

int imagehandleS;

//int jumpTouch;
//int OnJumpTouch(int id, int event, int x, int y);
//bool touching;

int spriteX;
int spriteY; //to control sprite location using variables manually
int jumpheightY;
int jumpY;

int groundX;
int groundY;
int frame = 0;

// Keeps track of the "world's" Y coordinate.
int GlobalY;

int viewS;
int viewG;
int viewB;

int spriteH_pixels = 60;
int spriteW_pixels = 40;
int spriteH_metres = 60*SCALE;
int spriteW_metres = 40*SCALE;

int jumpTouch;
int OnJumpTouch(int id, int event, int x, int y);
    b2Fixture* footSensorFixture;
    b2PolygonShape footSensorBox;
    b2FixtureDef FootSensorFixtureDef;

bool blTouching;

class MyContactListener : public b2ContactListener
{
    void BeginContact(b2Contact* contact)
    {
        //check if fixture A was a ball
        void* bodyUserData = contact->GetFixtureA()->GetUserData();
        if ( (int)bodyUserData ==3 )
        {
blTouching = true;
        }   
        //check if fixture B was a ball
        bodyUserData = contact->GetFixtureB()->GetUserData();
        if ( (int)bodyUserData ==3 )
        {
blTouching = true;
        } 
    }
 
    void EndContact(b2Contact* contact)
    {
        //check if fixture A was a ball
        void* bodyUserData = contact->GetFixtureA()->GetUserData();
        if ( (int)bodyUserData==3 )
        {
blTouching = false;
        } 
        //check if fixture B was a ball
        bodyUserData = contact->GetFixtureB()->GetUserData();
        if ( (int)bodyUserData==3 )
        { 
blTouching = false;
        }
    }
};

MyContactListener myContactListenerInstance;


// Earth gravity = 9.81 m/s:
const float EARTH_GRAVITY = 9.81f;
// Box2D objects:
b2World* world;
b2Vec2 Gravity;
b2Body* body;




void AppMain()
{
// Application initialization code goes here.  Create the items / objects / etc.
// that your app will need while it is running.
LandscapeMode();
spriteX=220;
spriteY=180;

groundX=0;
groundY=240; //remember that ground in DFSDK with ‘box’ ground in box2d

imagehandleS = ImageAdd("Images/sprite.png");//allocate handle to image

viewS = ViewAdd("Images/sprite.png", spriteX, spriteY); //add a view to image to make it visible

spriteH_pixels=ViewGetHeight(viewS); //sprite height in pixels
spriteW_pixels=ViewGetWidth(viewS); //sprite height in pixels
spriteH_metres=spriteH_pixels*SCALE; //sprite height in metres
spriteW_metres=spriteW_pixels*SCALE;//sprite width in metres

Gravity.Set(0.0f, EARTH_GRAVITY);               // Set default gravity vector:
const bool AllowSleep = true;
world = new b2World(Gravity, AllowSleep);
world->SetContactListener(&myContactListenerInstance);


b2BodyDef groundBodyDef; //initialise ground body
groundBodyDef.position.Set(0.0f, 240*SCALE);

//set ground position in container at (0,240) initially
b2Body* groundBody = world->CreateBody(&groundBodyDef); //create a ground polygon
b2PolygonShape groundBox;

groundBox.SetAsBox(240*SCALE, 60*SCALE);
//half width=240; half height=60

groundBody->CreateFixture(&groundBox, 0.0f); //creating a shape fixture for the ground body

//Creating dynamic bodies
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody; //by default == static, make them dynamic
bodyDef.position.Set(spriteX*SCALE, spriteY*SCALE);
b2Body* body = world->CreateBody(&bodyDef);

//creating and attaching a polygon shape using a fixture definition
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(1.0f, 1.50f);
//sprite pixel width = 40
//sprite pixel height = 60

b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 1.0f; //set density
fixtureDef.friction = 0.3f; //set friction
body->CreateFixture(&fixtureDef);


jumpTouch = TouchAdd(0,0, 320, 480, OnJumpTouch, 0);
footSensorBox.SetAsBox(10 * SCALE, 30 * SCALE);
    FootSensorFixtureDef.isSensor = true;
    FootSensorFixtureDef.shape =&footSensorBox;
    footSensorFixture = body->CreateFixture(&FootSensorFixtureDef);
    footSensorFixture->SetUserData( (void*)3 );

}

int OnJumpTouch(int id, int event, int x, int y)
{
    if (event ==1)
    {
if (blTouching == true)
{
body->ApplyLinearImpulse(b2Vec2(0, -10), body->GetWorldCenter());
}
}
    return id;
}
void AppExit()
{
// Application exit code goes here.  Perform any clean up your app might
// need to do in the event of interruption by a phone call or the user
// pressing the Home button, or some other event that would cause your
// application to terminate.
}


void OnTimer()
{
    // Main loop code goes here.  OnTimer() is called 30 times per second.

// Update all of the bodies created:
    world->Step(DELTA, 10, 10);
        // To convert Box2D positions to DFSDK positions, subrtract BODY_SIZE
        // from each coordinate to get the top left of the shape:
        ViewSetxy(viewS, ((body->GetPosition().x - BODY_SIZE_WIDTH) / SCALE), ((body->GetPosition().y - BODY_SIZE_HEIGHT) / SCALE));
        // Box2D uses radians for angles, but DFSDK uses degrees.  Convert. Degrees = Radians * 180 / PI:

}


67
Game Programming / Re: Problem with BOX2d code for Ground Body
« on: November 14, 2012, 02:46:46 pm »
Maybe it might help you to answer the question if I post the whole block of code

Code: [Select]
//b2Vec2 Gravity(0, -9.8); //normal earth gravity, 9.8 m/s/s straight down!
Gravity.Set(0.0f, EARTH_GRAVITY);               // Set default gravity vector:
const bool AllowSleep = true;
world = new b2World(Gravity, AllowSleep);


b2BodyDef groundBodyDef; //initialise ground body
groundBodyDef.position.Set(0.0f, 240*SCALE);

//set ground position in container at (0,240) initially
b2Body* groundBody = world->CreateBody(&groundBodyDef); //create a ground polygon
b2PolygonShape groundBox;

groundBox.SetAsBox(240*SCALE, 60*SCALE);
//groundBox.SetAsBox(36.0f, 3.0f); //form ground polygon into a box shape. Centre box on origin of the parent body
//SetAsBox(1,2): 1 = half width
//2 = half height
//half width=240; half height=60

groundBody->CreateFixture(&groundBox); //creating a shape fixture for the ground body



//b2BodyDef rectangle;
//rectangle.type = b2_dynamicBody; //this will be a dynamic body
//rectangle.position.Set(spriteX*SCALE, spriteY*SCALE);
////rectangle.position.Set(0.0f, 20.0f); //set the starting position
////220, 180
//rectangle.angle = 0; //set the starting angle




//Creating dynamic bodies
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody; //by default == static, make them dynamic
bodyDef.position.Set(spriteX*SCALE, spriteY*SCALE);
//(220,180)
b2Body* body = world->CreateBody(&bodyDef);

//creating and attaching a polygon shape using a fixture definition
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(1.0f, 1.50f);
//sprite pixel width = 40
//sprite pixel height = 60

b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 1.0f; //set density
fixtureDef.friction = 0.3f; //set friction
body->CreateFixture(&fixtureDef);


Sorry, problem has just been solved.

68
Game Programming / Re: Problem with BOX2d code for Ground Body
« on: November 14, 2012, 02:39:36 pm »
Maybe it might help you to answer the question if I post the whole block of code

Code: [Select]
//b2Vec2 Gravity(0, -9.8); //normal earth gravity, 9.8 m/s/s straight down!
Gravity.Set(0.0f, EARTH_GRAVITY);               // Set default gravity vector:
const bool AllowSleep = true;
world = new b2World(Gravity, AllowSleep);


b2BodyDef groundBodyDef; //initialise ground body
groundBodyDef.position.Set(0.0f, 240*SCALE);

//set ground position in container at (0,240) initially
b2Body* groundBody = world->CreateBody(&groundBodyDef); //create a ground polygon
b2PolygonShape groundBox;

groundBox.SetAsBox(240*SCALE, 60*SCALE);
//groundBox.SetAsBox(36.0f, 3.0f); //form ground polygon into a box shape. Centre box on origin of the parent body
//SetAsBox(1,2): 1 = half width
//2 = half height
//half width=240; half height=60

groundBody->CreateFixture(&groundBox); //creating a shape fixture for the ground body



//b2BodyDef rectangle;
//rectangle.type = b2_dynamicBody; //this will be a dynamic body
//rectangle.position.Set(spriteX*SCALE, spriteY*SCALE);
////rectangle.position.Set(0.0f, 20.0f); //set the starting position
////220, 180
//rectangle.angle = 0; //set the starting angle




//Creating dynamic bodies
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody; //by default == static, make them dynamic
bodyDef.position.Set(spriteX*SCALE, spriteY*SCALE);
//(220,180)
b2Body* body = world->CreateBody(&bodyDef);

//creating and attaching a polygon shape using a fixture definition
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(1.0f, 1.50f);
//sprite pixel width = 40
//sprite pixel height = 60

b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 1.0f; //set density
fixtureDef.friction = 0.3f; //set friction
body->CreateFixture(&fixtureDef);

69
Game Programming / Problem with BOX2d code for Ground Body
« on: November 14, 2012, 02:38:46 pm »
Dear all,
For this line:groundBody->CreateFixture(&groundBox);
Apparently:
error C2664: 'b2Fixture *b2Body::CreateFixture(const b2FixtureDef *)' : cannot convert parameter 1 from 'b2PolygonShape *' to 'const b2FixtureDef *'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


Finally, i am getting quite a lot of warnings: conversion from 'const float' to 'int', possible loss of data. is this a major problem?

Thank you for your help

70
Game Programming / Making a world with unlimited size??!!
« on: November 14, 2012, 01:54:43 pm »
So, my sprite will always remain in the middle.
However, the world (background) will move down, similar to doodle jump.

If I do this, should I make a container with unlimited height?

71
Game Programming / How many downloads?!! Success stories??
« on: November 14, 2012, 01:43:57 pm »
Kinda interested...
Any one got any success stories they would like to share?
:D

72
Game Programming / Re: Box2d Code questions
« on: November 14, 2012, 01:41:29 pm »
Thanks for the reply.
So if i initialise the ground, how do I set the coordinates of my image to be the coordinates of the static object in box2d?

Thank you


73
Game Programming / Box2d Code questions
« on: November 13, 2012, 02:45:22 pm »
Dear All,

I have a few questions regarding Box2d code.

Could someone please give me a quick overview as to what the following different lines of code means:
groundBodyDef.position.Set(0.0f, -10.0f); --> would it make any difference if I didnt not have a float value i.e. would I lose accuracy or would it reduce memory
--> in DFSDK, my ground will be 480pixels by 120pixels at bottom of screen (located at (0,240)). Converting this to metres using my 1/32 scale, would I simply then add these coords to groundBodyDef.position.Set?
*******
rectangle.position.Set(0.0f, 20.0f); --> This will be my sprite. --> would it matter if i didnt have 'f'?
--> in dfsdk, it should be located at (200pixels,180pixels). Therefore, would this be (6.25m, 5.625m) in box2d???
*******
How would I set ground graphics as ground in Box2d?
***
My world height is unlimited, is this automatically done when initialising a world in Box2d?
********
Thank you for taking your time reading this!!!
I would be very grateful if you could provide some answers!
Thank you ever so uch
Michael

74
Game Programming / Box 2D vs DFSDK coordinates
« on: November 13, 2012, 02:26:20 pm »
Dear All,

I am having a bit of trouble programming my game. Currently, I am using Box2d for a more 'realistic' model of the world.

However, I am wondering whether when I initiate the world, is the origin automatically centred in the middle of the screen (http://www.box2d.org/forum/viewtopic.php?f=3&t=8198), or can I set it to be in the top left hand corner?

Thank you very much for taking your time to read this post.

Micboy

75
Game Programming / Re: Making a sprite 'jump'
« on: August 03, 2012, 10:16:52 am »
Any help would be grateful

Pages: 1 ... 3 4 [5] 6