Jump to content

  • Log In with Google      Sign In   
  • Create Account

Kain5056

Member Since 22 Dec 2012
Offline Last Active Sep 24 2014 03:12 AM

Posts I've Made

In Topic: Hello World App won't run in emulator

30 July 2014 - 05:30 PM

OK, I googled it (didn't know exactly what to google at the time) and found the solution.

I downgraded the API Level to 17 just to be sure (Android version 4.2.2) and it works like a charm, both in the emulator and on my physical phone. :-)

Thanks for the help. :-)

 

A question though: Do I even need the API Level 20 stuff? Or is it safe to just uninstall them and just work with Level 17? Because the whole thing takes a billion trillion (rough estimate) Gigabytes on my HDD and it's a bit annoying since it's almost full... :-/


In Topic: Hello World App won't run in emulator

30 July 2014 - 03:00 PM

Okay, here is what the LogCat gives me:

07-30 20:56:19.420: E/AndroidRuntime(871): FATAL EXCEPTION: main
07-30 20:56:19.420: E/AndroidRuntime(871): Process: com.example.testgame, PID: 871
07-30 20:56:19.420: E/AndroidRuntime(871): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testgame/com.example.testgame.MainActivity}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-30 20:56:19.420: E/AndroidRuntime(871): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at android.app.ActivityThread.access$800(ActivityThread.java:138)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at android.os.Handler.dispatchMessage(Handler.java:102)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at android.os.Looper.loop(Looper.java:136)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at android.app.ActivityThread.main(ActivityThread.java:5026)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at java.lang.reflect.Method.invokeNative(Native Method)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at java.lang.reflect.Method.invoke(Method.java:515)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at dalvik.system.NativeStart.main(Native Method)
07-30 20:56:19.420: E/AndroidRuntime(871): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-30 20:56:19.420: E/AndroidRuntime(871): 	at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:275)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2872)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3129)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:303)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at android.app.Activity.setContentView(Activity.java:1930)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at com.example.testgame.MainActivity.onCreate(MainActivity.java:15)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at android.app.Activity.performCreate(Activity.java:5242)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-30 20:56:19.420: E/AndroidRuntime(871): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
07-30 20:56:19.420: E/AndroidRuntime(871): 	... 11 more

In Topic: Homing missile problem

06 June 2014 - 06:50 PM

Welp, no wonder my code does not work. You are right, it seems that SFML and ActionScript handle rotation a bit differently. I think that in ActionScript the missile points up at 90 degrees, but in SFML it points down.

All I need now to adjust the code it to find out how exactly does ActionScript handle rotation. Direction, degrees, and all that. Then, I'll be able to adjust the code accordingly. I'll try searching online tomorrow.

 

Thank you for explaining all this to me. :-)


In Topic: Homing missile problem

06 June 2014 - 08:52 AM

After a bit of thought and some calculations, I discovered that the conversion of range from [0,360] to [180,-180] seems to be as simple as this:

float current = 180 - rocket_sprite.getRotation();

With this, the code should work just as in the ActionScript example, since now it's all in the same range and at the same units.

It does not. The missile goes shakey, and there's no easing.

I can't understand why.

 

I'll keep looking into it, but right now I'm baffled. Why does it work there, but not here?

 

For reference, HERE's the ActionScript tutorial. The example of how it should work is under "Step 10: Less Precision for Better Looks".

 

...And here is my current code:

#include <math.h>
#define PI 3.14159265

class rocket
{
private:
    sf::Texture rocket_texture;
    sf::Sprite rocket_sprite;
    sf::Vector2f position;
    float rotation;

public:
    rocket();
    bool rocket_load();
    void rocket_show( sf::RenderWindow * window );
    void set_position( sf::Vector2f new_position );
    void rocket_rotate( sf::RenderWindow * window );
    void rocket_move();
};

rocket::rocket() { rotation = 0.f; }

bool rocket::rocket_load()
{
    rocket_texture.loadFromFile( "rocket.png" );
    rocket_sprite.setTexture( rocket_texture );

    return true;
}

void rocket::rocket_show( sf::RenderWindow * window )
{
    rocket_sprite.setOrigin( rocket_texture.getSize().x / 2 , rocket_texture.getSize().y / 2 );
    rocket_sprite.setPosition( position );
    window->draw( rocket_sprite );
}

void rocket::set_position( sf::Vector2f new_position ) { position = new_position; }

void rocket::rocket_rotate( sf::RenderWindow * window )
{
    sf::Vector2i mouse_position = sf::Mouse::getPosition( *window );
    float targetx = mouse_position.x - position.x;
    float targety = mouse_position.y - position.y;
    rotation = atan2( targety , targetx ) * ( 180 / PI );

    int ease = 5;
    float current = 180 - rocket_sprite.getRotation();

    if( abs( rotation - current ) > 180 )
    {
        if( rotation > 0 && current < 0 ) rotation -= ( 360 - rotation + current ) / ease;
        else if( current > 0 && rotation < 0 ) rotation += ( 360 - rotation + current ) / ease;
    }
    else if( rotation < current ) rotation -= abs( current - rotation ) / ease;
    else rotation += abs( rotation - current ) / ease;

    rocket_sprite.setRotation( rotation );
}

void rocket::rocket_move()
{
    int speed = 5;
    float speedx = 0;
    float speedy = 0;
    speedx = speed * ( 90 - abs( rotation ) ) / 90;
    if( rotation < 0 ) speedy = -speed + abs( speedx );
    else speedy = speed - abs( speedx );
    position.x += speedx;
    position.y += speedy;
}

In Topic: Homing missile problem

06 June 2014 - 05:15 AM

Not to sound ungrateful here, in fact I'm going to study intensely all the code you all provided, and I am extremely grateful for all the information, but for the moment I'd like to stick to the tutorial code as much as possible so I can keep following it. I can't help but think that there must be a simpler way to do it.

 

In fact, I have noticed that in the line

rotation = atan2( targety , targetx ) * ( 180 / PI );

the " * ( 180 / PI ) " part  converts radians to degrees, meaning that all the calculations are done in degrees.

float current = rocket_sprite.getRotation();

also returns degrees, as I understand, so the only problem is the range.

 

 

I have tried calculating the current angle manually, using this code:

float current = atan2( rocket_sprite.getPosition().y , rocket_sprite.getPosition().x ) * ( 180 / PI );

As you might have guessed, it didn't make any difference. But I still think that there must be a solution along those lines with minimal changes to the tutorial code. I'm just not good enough at math to find it.

 

Still, I *do* appreciate immensely all the examples and information you provided, and I *will* study them. Just after I manage to finish the tutorial. :-)

 

So, if you are still willing to help me convert just the range of "getRotation()", I'm still open to suggestions. :-)


PARTNERS