Book Image

Lua Game Development Cookbook

By : Mario Kasuba, Mário Kašuba
Book Image

Lua Game Development Cookbook

By: Mario Kasuba, Mário Kašuba

Overview of this book

Table of Contents (16 chapters)
Lua Game Development Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Moving the window


In some situations, it may be desirable for the user to be able to move the window to different places. There are many ways to achieve window movement. This recipe will show you how to use matrix operations to apply correct drag and drop movements in various situations.

Getting ready

First, you'll need to have the working event system from the LuaSDL library to catch the input from your mouse device. There are two kinds of events you'll want to detect: mouse movement and mouse button presses/releases. The most important part of this process is obtaining the mouse cursor position on the application window.

The last component of this recipe that you'll need is the window's model-view matrix. This will be used to determine the mouse cursor position on a window.

How to do it…

The first step of this recipe is to determine the current mouse cursor position. You can obtain its position by catching the SDL.SDL_MOUSEMOTION event, which returns the horizontal and vertical positions of...