0

I am following the tutorial at https://jimmaru.wordpress.com/2012/05/19/jimvaders-my-own-invaders-clone-thingie-tutorial/

The code I have below should display the text scrolling from side to side. Right now what I get is just a black rectangle that fills up most of the screen, and no text appears, no errors. FPSManager displays 60fps. I have title_1 and title_2 in my res/values/strings.xml setup.

MainActivity.java

package com.example.hh;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.util.FPSLogger;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.ui.activity.SimpleBaseGameActivity;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Typeface;
import android.view.Menu;

public class MainActivity extends SimpleBaseGameActivity {

    static final int cWidth = 800;
    static final int cHeight = 480;

    public Font mFont;
    public Camera mCamera;

    public Scene mCurrentScene;
    public static MainActivity instance;

    @Override
    public EngineOptions onCreateEngineOptions() {
        // TODO Auto-generated method stub

        instance = this;
        mCamera = new Camera(0,0, cWidth, cHeight);

        return new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, 
                new RatioResolutionPolicy(cWidth,cHeight),mCamera);

    }

    @Override
    protected void onCreateResources() {
        // TODO Auto-generated method stub
        mFont = FontFactory.create(this.getFontManager(), this.getTextureManager(), 256, 256, Typeface.create(Typeface.DEFAULT,Typeface.BOLD), 32);
        mFont.load();
    }

    @Override
    protected Scene onCreateScene() {
        // TODO Auto-generated method stub
        mEngine.registerUpdateHandler(new FPSLogger());
        mCurrentScene = new SplashScene();
        return mCurrentScene;
//      mEngine.registerUpdateHandler(new FPSLogger());
//      mCurrentScene = new Scene();
//      mCurrentScene.setBackground(new Background(0.09804f,0.7274f,0.8f));
//      return mCurrentScene;
    }

    public static MainActivity getSharedInstance(){
        return instance;
    }

    public void setCurrentScene(Scene scene){
        mCurrentScene = scene;
        getEngine().setScene(mCurrentScene);
    }
}

SplashScene.java

package com.example.hh;

import org.andengine.entity.modifier.MoveXModifier;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.text.Text;

public class SplashScene extends Scene {

    MainActivity activity;

    public void SplashScene(){
        setBackground(new Background(0.09804f, 0.6274f, 0));

        activity =  MainActivity.getSharedInstance();

        Text title1 = new Text(0,0, activity.mFont,activity.getString(R.string.title_1),activity.getVertexBufferObjectManager());
        Text title2 = new Text(0,0, activity.mFont, activity.getString(R.string.title_2), activity.getVertexBufferObjectManager());

        title1.setPosition(-title1.getWidth(), activity.mCamera.getHeight() / 2);
        title2.setPosition(activity.mCamera.getWidth(), activity.mCamera.getHeight() /2);

        attachChild(title1);
        attachChild(title2);

        title1.registerEntityModifier(new MoveXModifier(1,title1.getX(),activity.mCamera.getWidth()/2 - title1.getWidth()));
        title2.registerEntityModifier(new MoveXModifier(1,title2.getX(), activity.mCamera.getWidth() /2));

    }

}
KJW
  • 15,035
  • 47
  • 137
  • 243

1 Answers1

1

Where's the line that sets the foreground to white (or not-black)?

Zagrev
  • 2,000
  • 11
  • 8
  • is it possible to change font color? – KJW Oct 12 '12 at 22:55
  • Yes. The most common way is to use styles, but there's code here for a TextView: http://stackoverflow.com/questions/4602902/how-to-set-text-color-of-textview-by-coding – Zagrev Oct 13 '12 at 02:56