Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / [SOLVED] Bit of a hard time getting my head around some basic screen/sprite functions

Author
Message
n00bstar
20
Years of Service
User Offline
Joined: 9th Feb 2004
Location: Montreal, Canada.
Posted: 20th Feb 2020 20:36
Hello world!

First post, just bought AppGameKit classic to mess around with and I get stuck on the first simple thing

Quick background: Been coding in basic since the 90s, but haven't kept up with all them new and flashy development kits. I'm a bit of an oldschool programmer with habits firmly planted in the Nirvana era

But hey... now I got two problems

1) Extracting sprites from a spritesheet
In just about every programming language I've tried there was an easy way to load a sprite sheet that is composed of tiles that are all the same size. The command used would usually look a bit like;

LoadImage(imagefile, X Size, Y Size, NumberOfFrames)

So if you had a file with 50 tiles of 16x16 pixels all bunched up against one another you'd use:

Sprites = LoadImage("tileset.png", 16, 16, 50)

And then use it with something like DrawImage(ImageIndex, X Coord, YCoord, FrameNumber)

I've gotten my head around atlas textures and managed to do pretty much the same kind of thing but...isn't it just a PITA to work with an accompanying text file all the time? I mean it's fine when your project is done with, but in the middle of development when you're constantly changing your graphics? Seems weird. Am I missing some super obvious thing or am I going to have to learn to live with having one more notepad window open all the time?



2) Pasting the image to create a tilemap

So my tiles are 16x16 as previously mentionned. I'm working with 20 tiles by 16 tiles (320x256 virtual resolution) for a fullscreen. Here's how I've always proceeded (in pseudocode)



Now since I have seen any way to draw an image to the backbuffer directly. It seems I have to work strictly with sprites. I think you can see my problem. If I replace the DrawImage command with a CreateSprite command, my program bogs down to a crawl in no time because each sprite I create is an actual object and not just pixels thrown onto the backbuffer. So my questions are:
A) Is there a way to paste pixels directly on the backbuffer like an oldschool chump?
and if not:
B) I've figured out a way to manage this by dimming an array of 320 slots (20x16) and assining each sprite to a slot and then go through that array each frame, and then deleting all the sprites and redo the whole thing again every frame. Doesn't have much of a hit on performance but it's a weird bass ackward way of going about it. I'm sure there's a smarter way to do it. Please impart your wisdom on this old fool!

The author of this post has marked a post as an answer.

Go to answer

fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 20th Feb 2020 21:22
This post has been marked by the post author as the answer.
here is an example that creates an atlas map of 4
to create a single frame image you can change the image by pressing space
move the mouse around and you can see its drawing to the screen

I hope that helps


fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
n00bstar
20
Years of Service
User Offline
Joined: 9th Feb 2004
Location: Montreal, Canada.
Posted: 20th Feb 2020 23:31
Sweet baby jeebus! I've looked for that DrawSprite command and somehow never found it. Knowing I can paste stuff directly to the backbuffer, I can code myself a few functions to oldschool-i-fy my AppGameKit

You sir, are the man. May beer forever flow your way!
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 21st Feb 2020 02:20
Your welcome glad I could help

The commands are usually there but how to use them is what makes it hard

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk

Login to post a reply

Server time is: 2024-11-23 08:25:53
Your offset time is: 2024-11-23 08:25:53