Java tutorial
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package com.gamemaker.screens; import com.badlogic.gdx.Screen; import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.gamemaker.ERhelpers.AssetLoader; import com.gamemaker.ERhelpers.Button; import com.badlogic.gdx.graphics.g2d.Animation; /** * Created by robertcao on 8/09/2016. */ public class HowtoplayScreen implements Screen { private Game game; private ShapeRenderer shapeRenderer; private OrthographicCamera cam; private SpriteBatch batcher;//this is for drawing pictures for u private TextureRegion mapBg; public Button startBtn; private TextureRegion startButton_on, startButton_off; private TextureRegion backBtn_on, backBtn_off, forwardBtn_on, forwardBtn_off; public Button backBtn, forwardBtn; private float gameWidth = Gdx.graphics.getWidth(); private float gameHeight = Gdx.graphics.getHeight(); protected Animation tutor_animation1, tutor_animation2, tutor_animation3; public int step = 1; public float runTime = 0; public HowtoplayScreen(Game game) { this.game = game; cam = new OrthographicCamera(); cam.setToOrtho(true, 1280, 720); batcher = new SpriteBatch(); batcher.setProjectionMatrix(cam.combined); shapeRenderer = new ShapeRenderer(); shapeRenderer.setProjectionMatrix(cam.combined); mapBg = AssetLoader.mapBg; backBtn_on = AssetLoader.backBtn_on; backBtn_off = AssetLoader.backBtn_off; forwardBtn_on = AssetLoader.forwardBtn_on; forwardBtn_off = AssetLoader.forwardBtn_off; backBtn = new Button(50, 50, 150, 150, backBtn_on, backBtn_off); forwardBtn = new Button(50, 210, 150, 150, forwardBtn_on, forwardBtn_off); startButton_on = AssetLoader.startBtn_on; startButton_off = AssetLoader.startBtn_off; startBtn = new Button(50, 210, 150, 150, startButton_on, startButton_off); tutor_animation1 = AssetLoader.tutor_animation1; tutor_animation2 = AssetLoader.tutor_animation2; tutor_animation3 = AssetLoader.tutor_animation3; } @Override public void show() { } public void update(float deltaTime) { int[] data = { 0, 0, 0, 0, 0 }; if (step == 4) { game.setScreen(new GameScreen1(game, data)); } runTime += 0.6 * deltaTime; } public void draw(float delta) { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); batcher.begin(); //batcher.disableBlending(); batcher.draw(mapBg, 0, 0, 1280, 720); // batcher.draw(introText, 0, 0, 1280, 720); drawButton(delta); batcher.end(); } @Override public void render(float delta) { update(delta); draw(delta); } @Override public void resize(int width, int height) { } @Override public void pause() { } @Override public void resume() { } @Override public void hide() { } @Override public void dispose() { } public void drawButton(float delta) { if (step == 1) { batcher.draw(tutor_animation1.getKeyFrame(runTime), 380, 120, 500, 539); forwardBtn.isTouchDown(Gdx.input.getX(), Gdx.input.getY()); if (forwardBtn.getIsPressed()) { batcher.draw(forwardBtn.buttonDown, forwardBtn.x, forwardBtn.y, forwardBtn.width, forwardBtn.height); if (Gdx.input.justTouched()) { AssetLoader.clickButton.play(); step++; } } else { batcher.draw(forwardBtn.buttonUp, forwardBtn.x, forwardBtn.y, forwardBtn.width, forwardBtn.height); } forwardBtn.isTouchUp(Gdx.input.getX(), Gdx.input.getY()); } else if (step == 2) { batcher.draw(tutor_animation2.getKeyFrame(runTime), 390, 180, 500, 539); backBtn.isTouchDown(Gdx.input.getX(), Gdx.input.getY()); forwardBtn.isTouchDown(Gdx.input.getX(), Gdx.input.getY()); if (forwardBtn.getIsPressed()) { batcher.draw(forwardBtn.buttonDown, forwardBtn.x, forwardBtn.y, forwardBtn.width, forwardBtn.height); if (Gdx.input.justTouched()) { AssetLoader.clickButton.play(); step++; } } else { batcher.draw(forwardBtn.buttonUp, forwardBtn.x, forwardBtn.y, forwardBtn.width, forwardBtn.height); } if (backBtn.getIsPressed()) { batcher.draw(backBtn.buttonDown, backBtn.x, backBtn.y, backBtn.width, backBtn.height); if (Gdx.input.justTouched()) { AssetLoader.clickButton.play(); step--; } } else { batcher.draw(backBtn.buttonUp, backBtn.x, backBtn.y, backBtn.width, backBtn.height); } forwardBtn.isTouchUp(Gdx.input.getX(), Gdx.input.getY()); backBtn.isTouchUp(Gdx.input.getX(), Gdx.input.getY()); } else if (step == 3) { batcher.draw(tutor_animation3.getKeyFrame(runTime), 400, 200, 500, 539); backBtn.isTouchDown(Gdx.input.getX(), Gdx.input.getY()); startBtn.isTouchDown(Gdx.input.getX(), Gdx.input.getY()); if (startBtn.getIsPressed()) { batcher.draw(startBtn.buttonDown, startBtn.x, startBtn.y, startBtn.width, startBtn.height); if (Gdx.input.justTouched()) { AssetLoader.clickButton.play(); step++; } } else { batcher.draw(startBtn.buttonUp, startBtn.x, startBtn.y, startBtn.width, startBtn.height); } if (backBtn.getIsPressed()) { batcher.draw(backBtn.buttonDown, backBtn.x, backBtn.y, backBtn.width, backBtn.height); if (Gdx.input.justTouched()) { AssetLoader.clickButton.play(); step--; } } else { batcher.draw(backBtn.buttonUp, backBtn.x, backBtn.y, backBtn.width, backBtn.height); } startBtn.isTouchUp(Gdx.input.getX(), Gdx.input.getY()); backBtn.isTouchUp(Gdx.input.getX(), Gdx.input.getY()); } } }