At the time the team was using a countdown clock that was made in PowerPoint and that simply did not cut it. Gfx.Timer was originally developed for TEDxLjubljana. (x=0, y=0) refers to the top left of the image) Coordinates are based on the image being drawn into - (e.g. => Indentation not required, but helps organize things! Pushing our new image to the graphics context, so everything - drawn will be drawn directly to the image Local smileWidth, smileHeight = 36, 36 local smileImage = (smileWidth, smileHeight) Import " CoreLibs/graphics " - In this example, we'll be drawing a smiley face to an image, which saves our - drawing, makes it easier to draw, and helps improve performance since we don't - have to redraw each element separately each time local gfx = aphics If playdate.buttonJustPressed(playdate.kButtonA) then - Shake the screen for 500ms, with the screen - shaking around by about 5 pixels on each sideĮnd - A circle to be able to view what the shaking looks like ShakeTimer.timerEndedCallback = function() (shakeX, shakeY)Įnd - Resetting the display offset at the end of the screen shake Local shakeY = math.random(-magnitude, magnitude) Local shakeX = math.random(-magnitude, magnitude) Using the timer value, so the shaking magnitude - gradually decreases over time local magnitude = math.floor(timer.value) ShakeTimer.updateCallback = function(timer) Every frame when the timer is active, we shake the screen Creating a value timer that goes from shakeMagnitude to 0, over - the course of 'shakeTime' milliseconds local shakeTimer = (shakeTime, shakeMagnitude, 0) Import " CoreLibs/timer " - This function relies on the use of timers, so the timer core library - must be imported, and updateTimers() must be called in the update loop local function screenShake(shakeTime, shakeMagnitude) You can copy and paste this example directly as your a file to see it in action (We aren't using timers in this example, but in most - average-complexity games, you will.) if playdate.buttonIsPressed( playdate.kButtonUp ) thenĮnd if playdate.buttonIsPressed( playdate.kButtonRight ) thenĮnd if playdate.buttonIsPressed( playdate.kButtonDown ) thenĮnd if playdate.buttonIsPressed( playdate.kButtonLeft ) thenĮnd - Call the functions below in playdate.update() to draw sprites and keep - timers updated. (There are multiple ways to read the d-pad this is the simplest.) - Note that it is possible for more than one of these directions - to be pressed at once, if the user is pressing diagonally. Poll the d-pad and move our player accordingly. Use this function to poll input, run game logic, and move sprites. This function is called right before every frame is drawn onscreen. `playdate.update()` is the heart of every Playdate game. After this runs (it just runs once), nearly everything will be - controlled by the OS calling `playdate.update()` 30 times a second. x,y,width,height is the updated area in sprite-local coordinates - The clip rect is already set to this area, so we don't need to set it ourselvesĮnd - Now we'll call the function above to configure our game. local backgroundImage = ( " Images/background " ) (This is what we're doing below.) - 2) Use a tilemap, assign it to a sprite with sprite:setTilemap(tilemap), - and call :setZIndex() with some low number so the background stays behind - your other sprites. There are generally two ways to do this: - 1) Use setBackgroundDrawingCallback() to draw a background image. PlayerSprite:add() - This is critical! - We want an environment displayed behind our sprite. PlayerSprite:moveTo( 200, 120 ) - this is where the center of the sprite is placed (200,120) is the center of the Playdate screen local playerImage = ( " Images/playerImage ")Īssert( playerImage ) - make sure the image was where we thought The :moveTo() call moves our sprite to the center of the display. The :setCenter() call specifies that the sprite will be anchored at its center. local playerSprite = nil - A function to set up our game environment. We'll scope it to this file because - several functions need to access it. NOTE: Because it's local, you'll have to do it in every. Instead of having - to preface all graphics calls with "aphics", just use "gfx." - Performance will be slightly enhanced, too. Import " CoreLibs/timer " - Declaring this "gfx" shorthand will make your life easier. You'll want to import these in just about every project you'll work on. Your game can use multiple source files if you wish - (use the `import "myFilename"` command), but the simplest games can be written - with just `a`. Where do I report bugs or issues relating to the SDK? Where do I go if I have questions about the SDK? Profiling malloc calls in the Simulator.Assign frequently-used objects to local variables.Using your Playdate to control the Simulator.Set PLAYDATE_SDK_PATH Environment Variable.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |