How to: Resize Enemy Graphics

Mods, guides how to use and install mods go right in here.
Post Reply
User avatar
sgwyspeedrcr
Posts: 49
Joined: 09 Feb 2018, 04:24

Post » 20 May 2018, 17:07

I want to resize some of the enemy graphics for Mari0. I'm using Alesan99, but I imagine 90% of the code is roughly the same for SE. I've been struggling with this for awhile and still haven't succeeded in updating the size.

The default koopa troopa graphic is 96 x 96 pixels (4 koopas tall, 6 koopas long... making each koopa sprite 24h x 16w pixels. I want to expand the koopa troopa sprite to 32h x 16w pixels, making the entire graphic 128 x 96 pixels.

What, in the code below, do I need to update to properly resize the graphic? I would SUPER appreciate any tutorial on exactly what each of these variables and numbers represent... (so what is 12/16, and how is it different from 3/4 or 10/16 or 12/18??).

self.x = x-6/16

self.y = y-11/16

self.width = 12/16

self.height = 12/16

self.offsetX = 6

self.offsetY = 0

self.quadcenterX = 8

self.quadcenterY = 19

Image

User avatar
alesan99
Posts: 2335
Joined: 30 May 2013, 21:42
Contact:

Post » 20 May 2018, 19:44

The code for the image sizes is in spriteloader.lua line 105.

Code: Select all

	koopaquad = {}
	for y = 1, 4 do
		koopaquad[y] = {}
		for x = 1, 6 do
			koopaquad[y][x] = love.graphics.newQuad((x-1)*16, (y-1)*24, 16, 24, koopaimage:getWidth(), koopaimage:getHeight())
		end
	end
16 is the width and 24 is the height.
The offsets and quadcenters work the same as the custom enemies in SE.
sgwyspeedrcr wrote:(so what is 12/16, and how is it different from 3/4 or 10/16 or 12/18??)
Those are just fractions. They're divided by 16 because there are 16 pixels per tile.

User avatar
sgwyspeedrcr
Posts: 49
Joined: 09 Feb 2018, 04:24

Post » 20 May 2018, 23:04

What you pointed out did the trick! Thanks! I had to also mess with line 54 - 56 to tell it the total sprite sheet size is 96 x 112.

Code: Select all

		koopaquad = {}
		for y = 1, 4 do
			koopaquad[y] = {}
			for x = 1, 6 do
				koopaquad[y][x] = love.graphics.newQuad((x-1)*16, (y-1)*28, 16, 28, 96, 112)
			end
		end
Image

How do I get his feet out of the ground? I assume I'd set collision by altering the self.height = 12/16 in the line 12, koopa.lua file, but it doesn't appear to affect the sprite.

User avatar
Qcode
Posts: 1479
Joined: 05 Feb 2012, 18:00
Contact:

Post » 21 May 2018, 00:09

Adjust offsetY

User avatar
sgwyspeedrcr
Posts: 49
Joined: 09 Feb 2018, 04:24

Post » 21 May 2018, 02:38

Looks fantastic. Thanks!

For other enemies like Splunkin, where do I find their graphic sizes? I want to convert him into Rex.

Image

(koopa looks great)

Image

User avatar
alesan99
Posts: 2335
Joined: 30 May 2013, 21:42
Contact:

Post » 21 May 2018, 18:11

sgwyspeedrcr wrote:Looks fantastic. Thanks!

For other enemies like Splunkin, where do I find their graphic sizes? I want to convert him into Rex.
The other enemies should be in main.lua. Keep in mind that some quads are shared by multiple enemies, but I'm not sure that includes splunkins.

User avatar
sgwyspeedrcr
Posts: 49
Joined: 09 Feb 2018, 04:24

Post » 22 May 2018, 03:30

Lookin spot on. Really appreciate you takin the time to help out... hope there's not a limit on questions.

Exactly what is a "quad?" or for the non-mirrored sprites, a "quadi" ?

Image

User avatar
alesan99
Posts: 2335
Joined: 30 May 2013, 21:42
Contact:

Post » 22 May 2018, 03:47

sgwyspeedrcr wrote:Exactly what is a "quad?" or for the non-mirrored sprites, a "quadi" ?
Frames basically. "quadi" is just the number of the frame, some enemies have it because they have more complicated animations

User avatar
Qwerbey
Posts: 1282
Joined: 05 Oct 2012, 07:58
Contact:

Post » 22 May 2018, 06:15

A quad is basically a quadrilateral section of an image that can be rendered by itself.

User avatar
sgwyspeedrcr
Posts: 49
Joined: 09 Feb 2018, 04:24

Post » 23 May 2018, 02:58

OK, so basically a frame is a quad, and quadi represents complex frame movement (eg hammer bros). Using that, I was able to understand the basic mirroring and animation commands for most sprites.

https://gyazo.com/dcb28de2c8f65fdef54913dafe28ea81

How do I get the image to flip horizontally after a collision? So far it only knows to keep the source image regardless of direction. (Sprites WIP.. definitely am seeing a static horn for the squished sprite or a magical double chin on the large rex that keeps dis/appearing)

Sorry I keep pegging the forum for onsie and twosies questions. I'm actually making a large number of breakthroughs on my end that I don' t share because it's really simple-script or probably common knowledge info. For example, I figured out how to transform splunkin into the rex sprite (2 hp, with the 1hp version being stout and runs faster).

User avatar
Qwerbey
Posts: 1282
Joined: 05 Oct 2012, 07:58
Contact:

Post » 23 May 2018, 08:24

I don't know mate I'd honestly just use Custom Enemies at this point.

User avatar
sgwyspeedrcr
Posts: 49
Joined: 09 Feb 2018, 04:24

Post » 23 May 2018, 13:10

Any tutorials? Is customenemies really as simple as making a png file and putting a few defined variables in the json file?

Is there anywhere in the Main.lua, variables.lua or spriteloader.lua we have to define the customenemies?


And I may stick with the Rex over Splunkin since he is 90% complete, but I'll definitely look at using the rest of them for custom.

User avatar
Villager103
Posts: 506
Joined: 31 Jan 2013, 14:50
Contact:

Post » 23 May 2018, 13:40

To an extent, yeah. The only really finnicky part(in my experience, anyway) is the hitbox and quad offsets, the rest is actually really simple. You can find all the different variables and other things to create enemies on the stabyourself wiki.

User avatar
sgwyspeedrcr
Posts: 49
Joined: 09 Feb 2018, 04:24

Post » 23 May 2018, 15:36

Wow Ill give that a shot. I imagine something like Dino Rhino would be a heck of an undertaking because it essentially transforms into a new entity once struck, and it projects another entity (smb3 fire torch).

Im liking the learning experience thus far. Thanks

User avatar
Qwerbey
Posts: 1282
Joined: 05 Oct 2012, 07:58
Contact:

Post » 23 May 2018, 17:31

Yeah that's basically the easiest stuff to do with the Custom Enemy system.

User avatar
sgwyspeedrcr
Posts: 49
Joined: 09 Feb 2018, 04:24

Post » 24 May 2018, 04:14

if anyone is curious, I was able to get the Rex sprite to work with this portion of code, both to pull from the correct sprites depending on his hp and to correctly know which direction to flip the graphics depending on which way the sprite was moving.


The logic was really simple:

If Rex has 1 hp (squatty), then he should alterate between frame 3 and frame 4

If the Rex has any other hp, then he should alternate between frame 1 and frame 2

If the rex is moving to the left (-x direction) then his sprite should be graphically mirrored.

Otherwise, his sprite should not be flipped.

This makes a bit of lag when changing directions when his momentum is zero, but I can live with it

Code: Select all

	else
		self.animationtimer = self.animationtimer + dt
		while self.animationtimer > splunkinanimationspeed do
			self.animationtimer = self.animationtimer - splunkinanimationspeed
		
			if 	self.hp == 1 then
						if self.quad == splunkinquad[spriteset][3] then
							self.quad = splunkinquad[spriteset][4]
						else
							self.quad = splunkinquad[spriteset][3]
						end
					else
						if self.quad == splunkinquad[spriteset][1] then
							self.quad = splunkinquad[spriteset][2]
						else
							self.quad = splunkinquad[spriteset][1]
						end
					end
						
			if self.speedx > 0 then
					self.animationdirection = "left"
				else
					self.animationdirection = "right"
			end

		end
https://gyazo.com/0e869ff1804aabdad9c787884397fc52

What do you think of the custom fire mario?

Post Reply