Time for action – displaying raw graphics
Let's make
DroidBlaster
more interactive with some graphics and game components.
- Edit
jni/Types.hpp
and create a new structureLocation
to hold entity positions. Also, define a macro to generate a random value in the requested range as follows:#ifndef _PACKT_TYPES_HPP_ #define _PACKT_TYPES_HPP_ ... struct Location { Location(): x(0.0f), y(0.0f) {}; float x; float y; }; #define RAND(pMax) (float(pMax) * float(rand()) / float(RAND_MAX)) #endif
- Create a new file,
jni/GraphicsManager.hpp
. Define a structureGraphicsElement
, which contains the location and dimensions of the graphical element to display:#ifndef _PACKT_GRAPHICSMANAGER_HPP_ #define _PACKT_GRAPHICSMANAGER_HPP_ #include "Types.hpp" #include <android_native_app_glue.h> ...
Get Android NDK Beginner's Guide - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.